Run profile conditional on network in use

Run profile conditional on network in use

Postby ralphweir » Sat May 19, 2007 2:23 pm

Hi,

I want to use Syncback to backup some notebooks when they're at home. Unfortunately when they're in the office, they connect over the VPN and start a backup - typically no more than 10GBytes... over a VPN...

You know what happens next - Syncback gets turned off, and then the notebook is never backed up. And then the disk fails.

Is there any way of making a profile conditional on the network it is connected to? eg if my IP address is in this range, do the backup, if it's not, don't start the profile?

Thanks.
R
ralphweir
Newbie
Newbie
 
Posts: 1
Joined: Sat May 19, 2007 1:53 pm

Postby Dave Wilkins » Sat May 19, 2007 7:22 pm

Hi

As far as I know this exact facility is not available (others, pls feel free to correct me!), but whether iit is or not, and before going into possible workarounds, you have me a little puzzled, as follows

I'm not clear what is triggering this unwanted behaviour (tries to backup over VPN on arrival at office) - what starts the profile(s) there but not at home?

Why, after disconnection from home LAN at (say) 0745, is there 10GB (still left) to back up over VPN at 0905? How come it didn't get backed up the night before (or similar)?

Rgds
DW
Dave Wilkins
2BrightSparks Staff
2BrightSparks Staff
 
Posts: 6965
Joined: Thu Jan 04, 2007 10:02 am

Re: Run profile conditional on network in use

Postby MattM » Sun Jun 26, 2011 10:27 am

I'd also like to know if conditional profile runs are somehow possible.

My reason: I want to be able to back up my laptop from work/anywhere else via FTP. But when I'm at home, I'd like to back up via the local network which contains my backup server. I can't use the same profile that I use for remote FTP backup because loop-back connections (connect to local server via external IP) don't work.
MattM
Newbie
Newbie
 
Posts: 4
Joined: Sun May 01, 2011 11:13 am

Re: Run profile conditional on network in use

Postby Dave Wilkins » Sun Jun 26, 2011 5:36 pm

Not natively, no, but check out the VB script in your SE program folder

IsHomeNetwork.vbs

You can probably leverage this script in the Programs-Before section of a profile so that the script forces the profile to Abort if the current network is not the appropriate one.

(Note: this script / these lines

FoundHome = 1 ' SBSE returnvalue to stop profile
...
FoundHome = 0 ' SBSE return value to let profile run go ahead

were written when SE only accepted 1 & 0 as return values - specifically 1=ABORT & 0=RUN - but you can now set SE to Abort if the return value is not [anything numeric]. You can thus adjust either the script, SE or both, as you prefer. If you want to use the script 'as is', set the profile to Abort if return value is not [0])
Dave Wilkins
2BrightSparks Staff
2BrightSparks Staff
 
Posts: 6965
Joined: Thu Jan 04, 2007 10:02 am

Re: Run profile conditional on network in use

Postby MattM » Sat Jul 09, 2011 2:08 pm

Thanks that's a great tip, didn't think of using a script. I'll try it out.
MattM
Newbie
Newbie
 
Posts: 4
Joined: Sun May 01, 2011 11:13 am

Re: Run profile conditional on network in use

Postby lollies » Sun Sep 09, 2012 5:30 am

It shouldn't actually be too hard to do this programmatically. What you need to do is call GetAdaptersAddresses() (supported since WinXP), specify a family of AF_INET, flags of GAA_FLAG_SKIP_UNICAST | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_SKIP_FRIENDLY_NAME | GAA_FLAG_INCLUDE_GATEWAYS, then walk the returned list of IP_ADAPTER_ADDRESSES, and for each entry walk the list of IP_ADAPTER_GATEWAY_ADDRESS checking for the given gateway, a compare with the Address field in the structure.
The following should about do it:
Code: Select all
PIP_ADAPTER_ADDRESSES adapterAddresses;

gaaFlags = GAA_FLAG_SKIP_UNICAST | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_SKIP_FRIENDLY_NAME | GAA_FLAG_INCLUDE_GATEWAYS;
GetAdaptersAddresses( AF_INET, gaaFlags, NULL, &adapterAddresses, ... );
while( adapterAddresses != NULL )
  {
  PIP_ADAPTER_GATEWAY_ADDRESS gatewayPtr;

  for( gatewayPtr = adapterAddresses->FirstGatewayAddress;
       gatewayPtr != NULL; gatewayPtr = gatewayPtr->next )
    {
    if( compare( requiredGatewayAddress, gatewayPtr->Address ) )
      // Found!
    }
  adapterAddresses = adapterAddresses->next;
  }
lollies
Newbie
Newbie
 
Posts: 3
Joined: Sun Sep 09, 2012 5:04 am

Re: Run profile conditional on network in use

Postby lollies » Mon Feb 25, 2013 7:46 am

For those people who want a script to do this, IsHomeNetwork.vbs does some odd things, the following (based on IsHomeNetwork) may be a bit more useful:

Code: Select all
' For Syncback, "Programs - Before" script to check if we're in the
' home network.  This needs to be set for each profile (not for
' overall group profiles).
'
' Checks the DHCP server/default gateway address.

InHomeNetwork = 1   ' Return value to stop profile running

' Required DHCP server/gateway address to run

strRequiredDHCP = ""
strRequiredGateway = "192.168.10.1"

' Check for matching DHCP server and/or default gateway

Set objWMI = GetObject( "winmgmts:\\.\root\cimv2" )
Set colItems = objWMI.ExecQuery( "SELECT * FROM Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE" )

For Each objItem In colItems
'   WScript.Echo "DHCP: " & objItem.DHCPServer
   If Not IsNull( strRequiredDHCP ) And strRequiredDHCP = objItem.DHCPServer Then
      InHomeNetwork = 0   ' Return value to let profile run
      Exit For
   End If
   If Not IsNull( strRequiredGateway ) Then
      For i = LBound( objItem.DefaultIPGateway ) To UBound( objItem.DefaultIPGateway )
'         WScript.Echo "Gateway: " & objItem.DefaultIPGateway( i )
         If strRequiredGateway = objItem.DefaultIPGateway( i ) Then    
            InHomeNetwork = 0   ' Return value to let profile run
            Exit For
         End If
      Next
   End If
Next

Set objWMI = Nothing
Set colItems = Nothing

' Tell the caller what to do

Wscript.Quit( InHomeNetwork )


It'd still be nice to have this facility built into SyncBack though (see my sample code above), since having a command-line window flash up for every profile (I have several, that get run hourly) gets quite annoying.
lollies
Newbie
Newbie
 
Posts: 3
Joined: Sun Sep 09, 2012 5:04 am

Re: Run profile conditional on network in use

Postby Dave Wilkins » Mon Feb 25, 2013 10:07 am

Edit the default 'cscript' call (in Programs-Before box) to 'wscript'. No CLI window...
Dave Wilkins
2BrightSparks Staff
2BrightSparks Staff
 
Posts: 6965
Joined: Thu Jan 04, 2007 10:02 am

Re: Run profile conditional on network in use

Postby lollies » Mon Feb 25, 2013 10:54 pm

Thanks! Is there any reason why it defaults to the console host? Defaulting to the Windows host would make it a lot less intrusive.
lollies
Newbie
Newbie
 
Posts: 3
Joined: Sun Sep 09, 2012 5:04 am

Re: Run profile conditional on network in use

Postby Dave Wilkins » Tue Feb 26, 2013 7:52 am

I think it's to ensure that by default, you see it's working (the call) - in case the script quits due to errors (etc), but users believe it's not being called at all
Dave Wilkins
2BrightSparks Staff
2BrightSparks Staff
 
Posts: 6965
Joined: Thu Jan 04, 2007 10:02 am


Return to SyncBackSE V6/V5 (commercial)

Who is online

Users browsing this forum: gdeane and 0 guests

cron

User Control Panel

Login

Who is online

In total there is 1 user online :: 1 registered, 0 hidden and 0 guests (based on users active over the past 5 minutes)
Most users ever online was 619 on Tue Jun 26, 2007 10:08 am

Users browsing this forum: gdeane and 0 guests