I’m going to assume the answer is no, but is there any way to not execute backup job when the computer is outside of the LAN ?
I tried to test IP Address in the run-before-script and stop the backup if it is not on the LAN, but the backup doesn’t stop silently and returns an error (I would like “it says nothing”).
REM The following exit codes are supported:
REM
REM - 0: OK, run operation
REM - 1: OK, don't run operation
REM - 2: Warning, run operation
REM - 3: Warning, don't run operation
REM - 4: Error, run operation
REM - 5: Error don't run operation
REM - other: Error don't run operation
I use run before scripts to control this behaviour. They check for the presence of external USB HDDs for when I am in the office, and they also check for the presence of remote hosts for LAN or VPN accessibility. I also use these scripts to disable a backup (for whatever reason, typically when there are problems like the target being full or the software crashing or corrupting a job) which I find quicker and easier than using the Duplicati GUI.
For the path checking, I choose a folder inside the mount point rather than the mount point itself. This is so that when the drive is unmounted the check works as expected.
For the ping you can use IP or hostname, whichever you need to meet your needs. Remember that all I’m doing here is checking for accessibility to the server, not seeing if a service (e.g. SSH) is up and running.
#!/bin/bash
#Disable the backup by returning an error right away
#exit 1
#Does the target path exist?
[ ! -d “/path/to/folder/on/local/hdd/” ] && exit 1
#All good
exit 0
#!/bin/bash
#Disable the backup by returning an error right away
#exit 1
# Can we ping the device?
ping -c 2 192.168.1.1 > /dev/null && exit 0
# No dice!
exit 1
I run these on Linux Mint, there might be a need to tweak them for other Linux distributions. In general the same thing can be done on Windows, but I don’t have time to convert these to the appropriate commands. Perhaps a job for an LLM?
@echo off
REM Disable the backup by returning an error right away
REM exit /b 1
REM Can we ping the device?
ping -n 2 192.168.1.1 > nul
IF %ERRORLEVEL% EQU 0 (
exit /b 0
)
REM No dice!
exit /b 1
Unfortunately I can’t test as I don’t run Windows.