Abort backup if not if computer not in location x

I’m using duplicati on my laptop. I spend about 50% of my time in city A and 50% in city B. When I’m in my home location, I backup to my NAS, when I’m in the other location, I back up to an external drive.

I run a backup hourly to replace the Windows File History function which doesn’t work well - so I have two backup jobs, one for each location. Of course I get an error message each time the backup runs for the location where I am not at currently.

I’m trying to suppress the backup based on my current location. If I’m in A then suppress backup B and vice versa. I can determine my location using a Powershell script which works well for me. What I can’t figure out is how to use that information to suppress a backup. I’m pretty sure its by using the option run-script-before-required but I can’t figure it out.

The script currently returns a -1, if I am not in location A but I can’t figure out how to run a powershell script from duplicati.

Does anyone have any ideas?


This is my powershell script:

$MyLocation = (Invoke-WebRequest ipinfo.io | ConvertFrom-Json).city
if ($MyLocation -eq “Vancouver”)
return 0
else {
return -1

Checkout my PS script.


If the drive isn’t connected it won’t run the job.

Can I suggest a bit different approach? I have a similar situation too.

I use the windows scheduler to launch a python script thath check if my laptop is connect to a specific wireless (my home wireless) If yes it start backup process. In order to launch the backup process I use duplicati-client: it interacts with duplicati-server so I can view the actual status of backup jobs in web-ui.

Finally you can launch every our (via windows scheduler) a script that check if you are connect to a wireless or another wireless and according to response start only the correct backup job.

I’m pretty sure you need to use “exit” instead of “return” in a PowerShell script to set the errorlevel. How you use “return” in your script probably just outputs the numeric value to the screen, which isn’t the same thing.

Also you should set the errorlevel to 1 if you want Duplicati to not run the backup and not produce a warning or error message. (See this post for more info on that.)

Set --run-script-before to be the full path to your PowerShell script, including the .ps1 extension.

Thank you everyone for your help. I’m looking at the different options presented, I appreciate your help.

Thank you but I get the following error when trying to run a powershell script on Windows 11. Of course it runs outside of duplicati.
The specified executable is not a valid application for this OS platform.

Ok, maybe you’ll need to use a regular batch file wrapper. Try creating a cmd batch file with this as its contents:

powershell.exe c:\path\to\script.ps1

Then set Duplicati to use that cmd file instead of the ps1 file. It’s kind of clunky but should work.

Yep, I use this dirty trick too. :expressionless: