How to run a backup job only if storage server is available

I want to run a regular backup on a windows laptop, but only if the laptop can connect to to the storage server (Synology via SFTP). I.e. when the laptop is not in my LAN, the backup should not start and also not give any error message (red tray icon).

I did not find any option on how to accomplish this.

Only thing I can think of is a bit convoluted. It would require abandoning the built-in Web UI scheduler. (You would still define the job in the Web UI, but you’d turn off scheduling.)

Instead you’d use Windows Task Scheduler to run a powershell (or other) script at your desired backup intervals. This script would test connection to your backup target and, if successful, would trigger the backup job.

To trigger the backup job I’d recommend the excellent duplicati-client utility. It provides a command line way to trigger actions in the Web UI, which is distinctly different from the native Duplicati.CommandLine.exe utility. (The native tool operates completely independent of the Web UI engine.)

PowerShell offers a native command for testing TCP ports. Something like this should work:

$TcpTest = Test-NetConnection -ComputerName 192.168.0.10 -Port 22
If ($TcpTest.TcpTestSucceeded)
{
  .\duplicati_client.exe login
  .\duplicati_client.exe run 3    # number is ID of backup job to run
  .\duplicati_client.exe logout
}

I wonder if –run-script-before with a big –run-script-timeout could hold off actual backup while testing?
One scheduling quirk might see the job run twice. I think next run gets scheduled when any run starts. Depending on where that is relative to the run script, backup may miss its next schedule while waiting.

I first thought of using --run-script-before but if it causes the backup to not run, that will still throw an Error or at least a Warning for the backup run attempt, I believe.

Errorlevel 1 should abandon the backup job silently:

Some time ago, I made a sample script to return an errorlevel depending on one or more discovered network settings (current associated SSID, reachability of an IP address, existence of a shared folder, check if wired ethernet adapter is connected):

The feature request was implemented over a year ago, so a script like this should work using a current Duplicati version (not tested by me!)

Excellent, that will lead to a simpler solution than what I proposed.

run-script-example.bat shows some of the things one can do, not that I’ve actually tried much of it…

This sound interesting, but I’m afraid it is far beyond my meager capabilities to implement relative to the small size of the problem I’d want to solve. In my case it is that I’m using Minio for the back end on a dedicated backup computer (old retired HTPC), with the intent of cross linking to another one out of state at my son’s house (yes, we are CrashPlan Home refugees). I can attach to his Minio S3 using a VPN (free softether.net) and he can likewise attach to mine, but for some strange reason I can’t attach to my own. I’m blaming CenturyLink for doing something to block it, I don’t know what… At any rate when I’m home I’m hard coding my local Backup Destination Server address to my un-routable 192.168… IP address, and then changing to the softether.net VPN/DDNS name when traveling. This is a nuisance and generates errors when I forget, but easy enough to fix manually in the GUI if I’m away for awhile. Just that, while it is a pain to edit eight jobs, it is not enough of one to spend (in my dunce case) days trying to figure out a one-off script set.

Having said that, it would be really cool if the GUI had a spot on the Destination page for an Alternate Server address path that would be attempted should the primary fail/timeout. Or an Advanced Option (forgive me if there is one and I missed it, but I did look…). I suppose that would imply that the CommandLine backup would get a new argument like <storage-Alt-URL> or something like that, with an option for setting a timeout value, etc., maybe… Not sure this is worth a formal RFE relative to far more important and wondrous things on tap (NO sarcasm, this really is stellar), but it would make my life a tiny bit easier.

@likesource have you considered using a DDNS/VPN to attach to a gateway on your LAN to connect to your storage? I suspect the softether.org programs could do it if you have a computer that stays home. Then you could actually do the backup remotely rather than abort it.