Custom command before and after backup


Maybe I missed something but is there any way ho to run custom system command (like .bat on Windows or .sh on Linux) before and after backup?

For example I want to backup PostgreSQL data directory, but whole server must be down during backup and started afterwards. Is there any way how to achieve this behavior using Duplicati?

Thank you for help

In Duplicati, the advanced options --run-script-before, --run-script-after, --run-script-before-required and --run-script-timeout can be used.

See Duplicati.CommandLine.exe help runscript for more information.

Okay, the options works fine, but I get weird warning in every run.

The script "run-postgresql-10-backup.bat" reported error messages: 'auth-password' is not recognized as an internal or external command, operable program or batch file.

There is no “auth-password” command used inside that .bat file.
The storage is normal UNC path like \\\Backup with filled credentials. The Duplicati instance runs as service in Windows environment.

Also this warning appears for every operation like listing backups etc. Also I use the conditions to check for event and operation name so the whole “logic” of script runs only for BEFORE Backup. So for restore file listing it should done nothing but still the warning appears.

Do you have any idea where the problem can be please?
Thank you.

Yeah, this is a known issue (though I can’t find the topic for it right now). At present the best way to handle this is to have your script \use the Duplicati environment variables to check that %DUPLICATI_OPERATIONNAME% = Backup otherwise abort the job:

Are you test running your commands through the web GUI Command line feature? If so, this is also a known issue where some of the pre-filled parameters are passed even if not needed for the selected command. I usually make it a point to blank out all fields not needed for my specific command and it seems to run OK.

Nothing done in the Command line window is “saved” so don’t worry - you won’t be wiping out your backup job settings or anything like that.

I already have these conditions inside the .bat file, maybe I missed something so the .bat file is below.



GOTO end



echo Got operation "%OPERATIONNAME%", ignoring
GOTO end


powershell.exe -file "F:\Program Files\PostgreSQL\10.1\run_backup.ps1"



exit /B 0

Everything is done using web interface.

Your batch file looks good - I think I was misunderstanding the error you were reporting.

You said it provides a warning, is the backup run even if this warning appears?

My guess is that you’re running into a command line parsing issue, but I’m not exactly sure where / why. Specifically, if you export your job as a command line you’ll likely see something like he following:

“C:\Program Files\Duplicati 2\Duplicati.CommandLine.exe” backup “ssh://MySever:12345//mnt/user/DuplicatiBackups/MyPC?auth-username=me&auth-password=mypassword&ssh-fingerprint=ssh-rsa_myRSA” …

I’m guessing the “&” characters in the destination connection string are being “eaten” somewhere causing auth-password (and in this example ssh-fingerprint) to look like separate parameters - which Duplicati wouldn’t recognize.

You might want to try simplifying the batch job for testing what’s going on during backup and non-backup tasks. For example:

IF *%DUPLICATI__OPERATIONNAME% EQU *Backup echo Backup>C:\output.txt
IF *%DUPLICATI__OPERATIONNAME% NEQ *Backup echo Not Backup>C:\output.txt
exit /B 0

That should let you look at C:\output.txt after test runs of various commands to make sure the appropriate IF blocks are firing.

Additionally, if the “auth-password” errors go away, then there’s a good chance the (parameter parsing?) issue is being introduced in the powershell call…

Here is the exported command line for this backup job.

"C:\Program Files\Duplicati 2\Duplicati.CommandLine.exe" backup "file://\\Diskstation\Backup\SERVER-NODE-001\PostgreSQL\/?auth-username=backup&auth-password=somepassword” "F:\Program Files\PostgreSQL\10.1\backups\\" --backup-name="PostgreSQL 10" --dbpath="C:\Users\Administrator\AppData\Local\Duplicati\UNSWUNIOZL.sqlite" --encryption-module="aes" --compression-module="zip" --dblock-size="500MB" --keep-time="6M" --passphrase=“somepassphrase” --run-script-before-required="run-postgresql-10-backup.bat" --disable-module="console-password-input"

Also I used your example batch file (appended to the top of my batch file with the “early” exit), and events are running fine and correctly. And no error about auth-password.

Thanks for the command line (and test confirmation) - the exported command looks good to me (though the “/” before the "auth-username parameter looks odd). This still feels like a parsing issue in powershell for some reason…

The run_backup.ps1 powershell file doesn’t do anything with Duplicati, does it?

Am I correct in assuming the job runs fine if you manually do what’s in run_backup.ps1 then manually start the backup job WITHOUT the --run-script-before-required?

So I can’t use .ps1 file in --run-script-after, right? Also I can’t use --run-script-after "poweshell -file C:\SomeFile.ps1".
So I have to write .cmd file what execute ps1m right?))