Error while executing script

Hi, i’m trying to run and script in --run-script-before-required, try various ideas but always return error 255. My last script just has this:

#!/bin/bash

# We read a few variables first.
EVENTNAME=$DUPLICATI__EVENTNAME
OPERATIONNAME=$DUPLICATI__OPERATIONNAME
echo "+++ XS Script v.2 +++"

# Basic setup, we use the same file for both before and after,
# so we need to figure out which event has happened
# if [ "$EVENTNAME" = "BEFORE" ]; then
    # if [ "$OPERATIONNAME" = "Backup" ]; then
        # docker exec -it nextcloud occ maintenance:mode --on
        # codigo_salida=$?
        # echo "Mantenimiento. Código de salida: $codigo_salida"
    # else
        ##This will be ignored
        # echo "Got operation \"$OPERATIONNAME\", ignoring"
    # fi
# elif [ "$EVENTNAME" = "AFTER" ]; then
    # if [ "$OPERATIONNAME" = "Backup" ]; then
        # docker exec -it nextcloud occ maintenance:mode --off
    # else
        ##This will be ignored
        # echo "Got operation \"$OPERATIONNAME\", ignoring"
    # fi
# else
    # echo "Got unknown event \"$EVENTNAME\", ignoring" 2>&1
# fi
exit 0

duplicati is running on ASUSTOR NAS and has busybox as shell (I think), so trying #!/bin/sh as well…

this is the output:

Input command: backup
Input arguments: 
	webdavs://...
	/volume1/Docker/Nextcloud/config/

Input options: 
backup-name: TEST nextcloud
dbpath: ...
encryption-module: aes
compression-module: zip
dblock-size: 50mb
keep-time: 3M
passphrase: ...
run-script-before-required: /volume1/home/userxx/.scripts/duplicati-run-script.sh
run-script-after: /volume1/home/userxx/.scripts/duplicati-run-script.sh
debug-output: true
disable-module: console-password-input

Backup started at 03/06/2025 01:56:02
Error while executing script "/volume1/home/userxx/.scripts/duplicati-run-script.sh": The script "/volume1/home/userxx/.scripts/duplicati-run-script.sh" returned with exit code 255 => Duplicati.Library.Interface.UserInformationException: The script "/volume1/home/userxx/.scripts/duplicati-run-script.sh" returned with exit code 255
  at Duplicati.Library.Modules.Builtin.RunScript.Execute (System.String scriptpath, System.String eventname, System.String operationname, System.String& remoteurl, System.String[]& localpath, System.Int32 timeout, System.Boolean requiredScript, System.Collections.Generic.IDictionary`2[TKey,TValue] options, System.String datafile, System.Nullable`1[T] level) [0x001c4] in <0c128520bd854358a4b1ab8a996ba54d>:0 
The script "/volume1/home/userxx/.scripts/duplicati-run-script.sh" returned with exit code 255

Duplicati.Library.Interface.UserInformationException: The script "/volume1/home/userxx/.scripts/duplicati-run-script.sh" returned with exit code 255
  at Duplicati.Library.Modules.Builtin.RunScript.Execute (System.String scriptpath, System.String eventname, System.String operationname, System.String& remoteurl, System.String[]& localpath, System.Int32 timeout, System.Boolean requiredScript, System.Collections.Generic.IDictionary`2[TKey,TValue] options, System.String datafile, System.Nullable`1[T] level) [0x004fb] in <0c128520bd854358a4b1ab8a996ba54d>:0 
  at Duplicati.Library.Modules.Builtin.RunScript.OnStart (System.String operationname, System.String& remoteurl, System.String[]& localpath) [0x0000d] in <0c128520bd854358a4b1ab8a996ba54d>:0 
  at Duplicati.Library.Main.Controller.SetupCommonOptions (Duplicati.Library.Main.ISetCommonOptions result, System.String[]& paths, Duplicati.Library.Utility.IFilter& filter) [0x002ec] in <9cab5b8f1b4f49ec980acae8e278968b>:0 
  at Duplicati.Library.Main.Controller.RunAction[T] (T result, System.String[]& paths, Duplicati.Library.Utility.IFilter& filter, System.Action`1[T] method) [0x0026f] in <9cab5b8f1b4f49ec980acae8e278968b>:0 
  at Duplicati.Library.Main.Controller.Backup (System.String[] inputsources, Duplicati.Library.Utility.IFilter filter) [0x00074] in <9cab5b8f1b4f49ec980acae8e278968b>:0 
  at Duplicati.CommandLine.Commands.Backup (System.IO.TextWriter outwriter, System.Action`1[T] setup, System.Collections.Generic.List`1[T] args, System.Collections.Generic.Dictionary`2[TKey,TValue] options, Duplicati.Library.Utility.IFilter filter) [0x00119] in <81fea8e154eb4fd9aa8b06aac66d311a>:0 
  at Duplicati.CommandLine.Program.ParseCommandLine (System.IO.TextWriter outwriter, System.Action`1[T] setup, System.Boolean& verboseErrors, System.String[] args) [0x00342] in <81fea8e154eb4fd9aa8b06aac66d311a>:0 
  at Duplicati.CommandLine.Program.RunCommandLine (System.IO.TextWriter outwriter, System.IO.TextWriter errwriter, System.Action`1[T] setup, System.String[] args) [0x00002] in <81fea8e154eb4fd9aa8b06aac66d311a>:0 
Return code: 100

What else can I try?

many thanks…

Hi, since you have already tested with /bin/bash and /bin/sh, can you check the permissions on the scripts? Might be missing the execute permission or ownership issue?

ls -l /volume1/home/userxx/.scripts/duplicati*

It seems that everything is in order

userxx@asustor:/volume1/home/userxx/.scripts $ ls -la
total 4
drwxr-xr-x    1 userxx users           46 Mar  6 01:55 ./
drwxr-xr-x    1 userxx users          132 Mar  6 01:20 ../
-rwxrwxrwx    1 userxx users          988 Mar  6 01:55 duplicati-run-script.sh*

Any chance this file has carriage returns chars?

cat -v /volume1/home/userxx/.scripts/duplicati-run-script.sh

if you see ^M it means there is a \r\n which could be an issue for ash (if this busybox is using it)

Yeahh, lot of them, removed with:

sed -i 's/\r//' /volume1/home/userxxx/.scripts/duplicati-run-script.sh

Error 255 has gone and backup started…

thereafter, reworked the script:

#!/bin/sh

# We read a few variables first.
EVENTNAME=$DUPLICATI__EVENTNAME
OPERATIONNAME=$DUPLICATI__OPERATIONNAME
echo "+++ XS Script v.2 +++" >&2

# Basic setup, we use the same file for both before and after,
# so we need to figure out which event has happened
if [ "$EVENTNAME" = "BEFORE" ]; then
    if [ "$OPERATIONNAME" = "Backup" ]; then
	    echo "Ejecutando Mantenimiento ON" >&2
        docker exec -it nextcloud occ maintenance:mode --on
        codigo_salida=$?
        echo "Mantenimiento ON. Salida: $codigo_salida" >&2
    else
        #This will be ignored
        echo "Got operation \"$OPERATIONNAME\", ignoring"
    fi
elif [ "$EVENTNAME" = "AFTER" ]; then
    if [ "$OPERATIONNAME" = "Backup" ]; then
        docker exec -it nextcloud occ maintenance:mode --off
		codigo_salida=$?
        echo "Mantenimiento OFF. Salida: $codigo_salida"
    else
        #This will be ignored
        echo "Got operation \"$OPERATIONNAME\", ignoring"
    fi
else
    echo "Got unknown event \"$EVENTNAME\", ignoring"
fi
exit $codigo_salida

Result: looks better, but another error:

Backup started at 03/06/2025 17:44:50
Error while executing script "/volume1/home/userxxx/.scripts/duplicati-run-script.sh": The script "/volume1/home/userxxx/.scripts/duplicati-run-script.sh" returned with exit code 1 => Duplicati.Library.Interface.UserInformationException: The script "/volume1/home/userxxx/.scripts/duplicati-run-script.sh" returned with exit code 1
  at Duplicati.Library.Modules.Builtin.RunScript.Execute (System.String scriptpath, System.String eventname, System.String operationname, System.String& remoteurl, System.String[]& localpath, System.Int32 timeout, System.Boolean requiredScript, System.Collections.Generic.IDictionary`2[TKey,TValue] options, System.String datafile, System.Nullable`1[T] level) [0x001c4] in <0c128520bd854358a4b1ab8a996ba54d>:0 
The script "/volume1/home/userxxx/.scripts/duplicati-run-script.sh" reported error messages: +++ XS Script v.2 +++

Duplicati.Library.Interface.UserInformationException: The script "/volume1/home/userxxx/.scripts/duplicati-run-script.sh" returned with exit code 1
  at Duplicati.Library.Modules.Builtin.RunScript.Execute (System.String scriptpath, System.String eventname, System.String operationname, System.String& remoteurl, System.String[]& localpath, System.Int32 timeout, System.Boolean requiredScript, System.Collections.Generic.IDictionary`2[TKey,TValue] options, System.String datafile, System.Nullable`1[T] level) [0x004fb] in <0c128520bd854358a4b1ab8a996ba54d>:0 
  at Duplicati.Library.Modules.Builtin.RunScript.OnStart (System.String operationname, System.String& remoteurl, System.String[]& localpath) [0x0000d] in <0c128520bd854358a4b1ab8a996ba54d>:0 
  at Duplicati.Library.Main.Controller.SetupCommonOptions (Duplicati.Library.Main.ISetCommonOptions result, System.String[]& paths, Duplicati.Library.Utility.IFilter& filter) [0x002ec] in <9cab5b8f1b4f49ec980acae8e278968b>:0 
  at Duplicati.Library.Main.Controller.RunAction[T] (T result, System.String[]& paths, Duplicati.Library.Utility.IFilter& filter, System.Action`1[T] method) [0x0026f] in <9cab5b8f1b4f49ec980acae8e278968b>:0 
  at Duplicati.Library.Main.Controller.Backup (System.String[] inputsources, Duplicati.Library.Utility.IFilter filter) [0x00074] in <9cab5b8f1b4f49ec980acae8e278968b>:0 
  at Duplicati.CommandLine.Commands.Backup (System.IO.TextWriter outwriter, System.Action`1[T] setup, System.Collections.Generic.List`1[T] args, System.Collections.Generic.Dictionary`2[TKey,TValue] options, Duplicati.Library.Utility.IFilter filter) [0x00119] in <81fea8e154eb4fd9aa8b06aac66d311a>:0 
  at Duplicati.CommandLine.Program.ParseCommandLine (System.IO.TextWriter outwriter, System.Action`1[T] setup, System.Boolean& verboseErrors, System.String[] args) [0x00342] in <81fea8e154eb4fd9aa8b06aac66d311a>:0 
  at Duplicati.CommandLine.Program.RunCommandLine (System.IO.TextWriter outwriter, System.IO.TextWriter errwriter, System.Action`1[T] setup, System.String[] args) [0x00002] in <81fea8e154eb4fd9aa8b06aac66d311a>:0 
Return code: 100

try to set another echos, but just the first is displayed…

Now, I’m going to try another approach: Docker Image https://hub.docker.com/r/linuxserver/duplicati/
maybe docker has bash and everything will be easier…

Which one do you dislike? The script looks like it means to notice an error and error Duplicati.

If you want flexibility, don’t use run-script-before-required, just use run-script-before.

Example Scripts and see exit codes section.

If you’re trying to put messages into logs, the manual doesn’t show it yet, but there’s this now:

v2.0.9.110_canary_2024-11-09

Added option to let scripts create log entries

and from its date, I think it made it (without a claim) into the later non-Canary releases as well.

1 Like

Hi ts678,

Excelent news!, I will try it.

let me explain the script:
I use --run-script-before-required, because i want to backup nextcloud, so to do not generate inconsistencies I have to put in maintenance mode with instruction “docker exec…”. This is crucial, if fails, backup must dont continue. thats is why I use required (and because i dont use exit 0, too).
I tested the instruction in command line and executed ok. In script doesnt work (nextcloud do not enter in mantenaince mode) so, something is bad…

Moreover, asustor NAS has no bash, an made more dificult all.

I’m leaning towards docker because that way I get the latest version. App from ASUSTOR NAS store is not the last…

ASUSTOR NAS → You are currently running Duplicati - 2.0.7.1_beta_2023-05-25
Docker → You are currently running Duplicati - 2.1.0.5_stable_2025-03-04

Another option would be to create the script outside (in Linux) that calls duplicati from the command line (CLI), schedule it and so on… but I’m not an expert (I’d like to use the GUI)

Thank you very much for your help!

I wasn’t sure how noisy you wanted a non-run to be, but the non-required option gives choices:

# - 0: OK, run operation
# - 1: OK, don't run operation
# - 2: Warning, run operation
# - 3: Warning, don't run operation
# - 4: Error, run operation
# - 5: Error don't run operation
# - other: Error don't run operation

I don’t use Docker, but does that run have to be by any particular user?

To see Duplicati user, you can see About → SystemInfo → UserName.

Good luck with your setup.

 think it made it (without a claim) into the later non-Canary releases as well.

FYI: Its all the way into the stable.

Thanks. I guess it just missed even the detailed release notices later on.
It’d still be nice to get it in the example sometime to save pointing at PR.
Maybe user manual will someday assist, but example is pretty complete.

Good point, I will add to docs. I’ve opened an issue not to lose track of it.

Hi ts678,

I successfully install duplicati on docker, works like a charm… but (always are “buts” in linux…) docker images dont see each other… so my script become complex…

I don’t use Docker, but does that run have to be by any particular user?

Yes, has root, same displayed in SystemInfo…

Now instead of using the duplicati script inside the image, i create a script on the host that first calls:

  • Nextcloud docker to enter maintenance mode
  • backup the sql database
  • calls duplicati docker to do its magic
  • calls nextcloud docker again to exit maintenance mode