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

**URL:** https://forum.duplicati.com/t/how-to-run-a-backup-job-only-if-storage-server-is-available/8913
**Category:** How-To
**Created:** [January 18, 2020, 10:02pm UTC](https://forum.duplicati.com/t/how-to-run-a-backup-job-only-if-storage-server-is-available/8913 "2020-01-18T22:02:29Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![likesource](https://forum.duplicati.com/user_avatar/forum.duplicati.com/likesource/32/2453_2.png) [@likesource](https://forum.duplicati.com/u/likesource)
#### Post date: [January 18, 2020, 10:02pm UTC](https://forum.duplicati.com/t/how-to-run-a-backup-job-only-if-storage-server-is-available/8913/1 "2020-01-18T22:02:29Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![drwtsn32](https://forum.duplicati.com/user_avatar/forum.duplicati.com/drwtsn32/32/2591_2.png) [@drwtsn32](https://forum.duplicati.com/u/drwtsn32)
#### Post date: [January 20, 2020, 1:53pm UTC](https://forum.duplicati.com/t/how-to-run-a-backup-job-only-if-storage-server-is-available/8913/2 "2020-01-20T13:53:10Z")

</div>

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](https://github.com/Pectojin/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
}

```

---

<div class="post-metadata">

### Author: ![ts678](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@ts678](https://forum.duplicati.com/u/ts678)
#### Post date: [January 20, 2020, 3:09pm UTC](https://forum.duplicati.com/t/how-to-run-a-backup-job-only-if-storage-server-is-available/8913/3 "2020-01-20T15:09:44Z")

</div>

I wonder if [–run-script-before](https://duplicati.readthedocs.io/en/latest/06-advanced-options/#run-script-before) with a big [–run-script-timeout](https://duplicati.readthedocs.io/en/latest/06-advanced-options/#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.

---

<div class="post-metadata">

### Author: ![drwtsn32](https://forum.duplicati.com/user_avatar/forum.duplicati.com/drwtsn32/32/2591_2.png) [@drwtsn32](https://forum.duplicati.com/u/drwtsn32)
#### Post date: [January 20, 2020, 5:28pm UTC](https://forum.duplicati.com/t/how-to-run-a-backup-job-only-if-storage-server-is-available/8913/4 "2020-01-20T17:28:50Z")

</div>

> [@ts678](#):
>
> I wonder if [–run-script-before](https://duplicati.readthedocs.io/en/latest/06-advanced-options/#run-script-before) with a big [–run-script-timeout](https://duplicati.readthedocs.io/en/latest/06-advanced-options/#run-script-timeout) could hold off actual backup while testing?

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.

---

<div class="post-metadata">

### Author: ![kees-z](https://forum.duplicati.com/user_avatar/forum.duplicati.com/kees-z/32/29_2.png) [@kees-z](https://forum.duplicati.com/u/kees-z)
#### Post date: [January 20, 2020, 5:58pm UTC](https://forum.duplicati.com/t/how-to-run-a-backup-job-only-if-storage-server-is-available/8913/5 "2020-01-20T17:58:54Z")

</div>

Errorlevel 1 should abandon the backup job silently:

> [@Improvements for --run-script-before/after options](https://forum.duplicati.com/t/improvements-for-run-script-before-after-options/519/11):
>
> So can this be “Solved” and taken out of Planned mode based on this release? For the record it looks like the acceptable return codes are: 0 (run the job) 1 (abort job silently) 3 (abort job with warning) 5 (abort job with error)

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):

> [@Duplicati vs. CrashPlan Home](https://forum.duplicati.com/t/duplicati-vs-crashplan-home/515/4):
>
> As a workaround, you can use the command line option --run-script-before-required to launch a script that performs one or more tests. If one of the tests succeeds, the script exits with errorlevel 0, otherwise it exits with errorlevel 1. Duplicati will abort the backup job if the script specified with --run-script-before-required returns anything else than 0. A script could look something like this: @echo off setlocal enabledelayedexpansion set ErrLev=1 rem Check if connected to SSID "MyHo…

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!)

---

<div class="post-metadata">

### Author: ![drwtsn32](https://forum.duplicati.com/user_avatar/forum.duplicati.com/drwtsn32/32/2591_2.png) [@drwtsn32](https://forum.duplicati.com/u/drwtsn32)
#### Post date: [January 20, 2020, 6:41pm UTC](https://forum.duplicati.com/t/how-to-run-a-backup-job-only-if-storage-server-is-available/8913/6 "2020-01-20T18:41:34Z")

</div>

> [@kees-z](#):
>
> Errorlevel 1 should abandon the backup job silently:

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

---

<div class="post-metadata">

### Author: ![ts678](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@ts678](https://forum.duplicati.com/u/ts678)
#### Post date: [January 20, 2020, 9:05pm UTC](https://forum.duplicati.com/t/how-to-run-a-backup-job-only-if-storage-server-is-available/8913/7 "2020-01-20T21:05:45Z")

</div>

[run-script-example.bat](https://github.com/duplicati/duplicati/blob/master/Duplicati/Library/Modules/Builtin/run-script-example.bat) shows some of the things one can do, not that I’ve actually tried much of it…

---

<div class="post-metadata">

### Author: ![Geek4eye](https://forum.duplicati.com/letter_avatar_proxy/v4/letter/g/b9e5f3/32.png) [@Geek4eye](https://forum.duplicati.com/u/Geek4eye)
#### Post date: [February 9, 2020, 2:01am UTC](https://forum.duplicati.com/t/how-to-run-a-backup-job-only-if-storage-server-is-available/8913/8 "2020-02-09T02:01:29Z")

</div>

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](http://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](http://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](https://www.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.
