2 possible solutions come to mind:
- Assuming you’re behind a NAT router, if your router supports Hairpin NAT (most modern consumer grade routers support it out of the box, should be possible to set it up for Enterprise grade appliances), just point your destination to the public IP address of your internet connection, using the protocol for external use (SSH/FTP).
Probably your router will route the traffic back to your local network, the configured port forwarding in your router wil send the packets straight to your NAS.
- According to the documentation in the example script (line 106-108), it should be possible to change the remote URL dynamically using a script that runs before the backup operation starts.
Unfortunately I still haven’t got it working. It looks like this is a bug, unless I’m missing something. The
--remoteurl option seems to be ignored. I’ve filed a bug report at GitHub.
Anyway, this is how it should work:
Create a batch file containing this:
rem Replace with the IP address and MAC address
rem of an always-on device in your local network
rem Replace with Duplicati remote URL when on external network
rem Replace with the credentials for the remote URL when on an external network.
rem Set to %DUPLICATI__AUTH_USERNAME% and %DUPLICATI__AUTH_USERNAME%
rem to keep credentials for local backup destination
rem check if IP address replies to ICMP packets
ping -n 1 -w 1000 %IPADDRESS% > nul 2>nul
if errorlevel 1 goto ExternalNetwork
rem Check the MAC address to make sure it's your local device and not another device with the same IP
for /f "usebackq tokens=1-3 delims= " %%a in (`arp -a ^| find /i "%IPADDRESS%"`) do set FOUNDMAC=%%b
if /i "%MACADDRESS%" neq "%FOUNDMAC%" goto ExternalNetwork
%MACADDRESS% values with the IP and MAC address from a local device that’s Always available in your local network (internet router?). The MAC address is needed to make sure there is not a device in an external network with the same IP address as your local device.
%PASSWORD% with URL and credentials of the backend to use from an external location.
- Create a backup job and configure it for internal use (Local folder to your NAS). Add
--run-script-before to the configuration and call the batch file above.
The script PINGs the configured IP address and checks the error level to find out if it’s reachable. If the error level is 0 (device replied to PING), the MAC address is retrieved and checked against the configured address. If IP and MAC have the expected values, the script just exits and the backup job runs, using the internal destination (Local folder).
If IP address is not reachable and/or MAC address is not the exprected one, the script echoes a new value for the remote location and credentials. This is the part that doesn’t seem to work.
Maybe the source of the problem can be addressed by a fix in the batch script, or a bug fix in the software, making it work in a future version.