How to use scripts on Duplicati

On windows 10 64 bit

I’m trying to run a script (I already tested it standalone and it works fine) to run before a backup on duplicati.

On the advanced tab, I add a new option named “run-script-before”, and write the path to the script.

However, it never runs, it always display the same warning: " [Warning-Duplicati.Library.Modules.Builtin.RunScript-ScriptExecuteError]: Error while executing script “D:\wake-up.ps1”: The specified executable is not a valid application for this OS platform."

Any solution to this?

1 Like

Hello

try to specify an actual executable like ‘powershell -file yourscript.ps1’. The ‘run-script-before’ name for this command line switch is a misnomer, it should have been named ‘run-command-before’.

1 Like

While it might run command, I don’t think it will run a command and arguments, the way it’s done now:

It hasn’t set ProcessStartInfo.Arguments Property which is a string giving its command line arguments which are interpreted by the application, although on Windows it might do it per Windows conventions. Linux compatibility worries me a bit, as Linux applications rely on shells to deliver parsed args to them.

Having shells involved begs the questions of how to pick what shell, and can malicious ones be put in?
subprocess — Subprocess management explains how Python used to fall for those, but it’s been fixed.

execvp(3) - Linux man page explains its couple of tricks, such as how it can do PATH search, or handle ENOEXEC error by passing the file to hardcoded /bin/sh to see if it can handle given file successfully.

It might be nice if Duplicati can safely (keeping compatibility with all current simplistic uses) upgrade to handling arguments directly. Current workaround is a batch file wrapper. If not, maybe add new option?

Some open issues:

Support Powershell Pre-Script #4290
Arguments for scripts before/after options #2926

I’m trying to run a wake on lan script befor the backup to turn on a remote pc, and hopefully another script at the end of the backup to shut it down. Is this even possible with Duplicati?

I can’t comment on the content of your scripts, but did you read above post on using batch file wrapper?
Also read the links at its bottom. Any questions about them?

im sorry but i’m not very tech savy and was hoping there was a more straightforward way to do what I had in mind. The ony way I made that simple script to turn on the pc was using the AI on chat gpt. Howver I’m gonna try and read what you wrote on the previous post.

Thanks for the help

You don’t have to read the comments to developer, but look at the end. For example:

says run a batch file (maybe one line) that runs your PowerShell script.

1 Like

i used a batch file like you guys suggested, works like a charm, thanks for the help

2 Likes

BTW, just to make sure, is there a way to run a script after the “Backup_ProcessingFiles” phase of a backup? my remote pc shuts down before this phase is completed since there is no network activity

Scripting options describes your options, basically before and after, not in chosen spots in the middle. Posssibly you could start something before that would poke the remote until an after script stopped it.

As gaps in activity can happen in many places, I don’t see why you would NOT want constant keepalive, however seeing phases is easier on command line, maybe especially with third-party duplicati-client tool.

My thoughts on this:

  • How do we differentiate between arguments and a file path with spaces? Old scripts would need to be escaped with quotes, so that would break compatibility. Also quote escaping is difficult for the user, when specified via command line there needs to be double escaping.
  • Therefore, if we implement script arguments I think it should be a separate flag (which means two or three new flags in total).
  • I believe running other script types is mostly a problem on Windows, because Linux launches the process differently.
    Maybe we could instead provide some different script extensions for Windows (especially Powershell because it is popular and needs to be run with powershell.exe -executionpolicy unrestricted -file {}, unless system settings are changed).