"run-script-after" only if backup finished - how?

Hi, I am using “run-script-after” - but the script is also running, when I abort backup, which I often do. I don’t want to run the script in such a case. Is there some kind of error levels or environment variables which I can use?

In a general sense, all the Duplicati options are exposed as environment variables prefixed with “DUPLICATI__” and, due to some some env. variables not allowing dahes, all dashes (-) replaced with underscores (_).

So if you’re running a DOS batch file you could get to your --throttle-upload setting by using %DUPLICATI__throttle_upload%.

There are also some special non-option vairables that are probably what you’re intersted in:

  • DUPLICATI__EVENTNAME = when script was triggered such as “BEFORE” or “AFTER”
  • DUPLICATI__OPERATIONNAME = operation, such as “Backup”, “Cleanup”, “Restore”, etc.
  • DUPLICATI__RESULTFILE = path to file in which result data is stored
  • DUPLICATI__REMOTEURL = “URL” target backend
  • DUPLICATI__LOCALPATH = path to folders being backed up or restored
  • DUPLICATI__PARSED_RESULT = run result such as “Unknown”, “Success”, “Warning”, “Error”, or “Fatal”

So in your case (and assuming a DOS batch file) I’m guessing your script should start with something along the lines of if *%DUPLCATI__PARSED_RESULT%* NEQ *Success* goto :EOF (or something like that).

1 Like

Hey thanks… Yes I am running a .cmd file on Win7. Will need to test later. %DUPLICATI__PARSED_RESULT% returned an empty string, maybe it’s %DUPLICATI–PARSED-RESULT% … or I’ll send the output of “set” to a file to see what actually exists. I hope the variables operate in a global scope…

echo “%DUPLICATI–PARSED-RESULT%”>"%temp%\dup1.txt"
echo “%DUPLICATI-PARSED-RESULT%”>"%temp%\dup2.txt"
echo “%DUPLICATI__PARSED_RESULT%”>"%temp%\dup3.txt"
echo “%DUPLICATI_PARSED_RESULT%”>"%temp%\dup4.txt"

All files only have the “” characters in them. I.e., all variables were empty in the script.

It does not work this way :frowning:

The DUPLICATI__PARSED_RESULT status variable was introduced in v2.0.2.3-
If you’re in the Experimental or Beta update channel, you probably use a version number that’s below
As a workaround, you can use a script similar to this one to pull the parsed result from the result file:

Ah, there is a file, yes I can use this… I’m loving doing cmd magic :slight_smile: Yes I am on experimental.

Btw I think Duplicati UI should show more support as for this topic.

Is there a table of all the possible values these:


can take?

I am looking at possibly writing a universal before/after script.

was answered in Valid Values for Script ENV variables? by @warwickmm (thanks!)

but because there’s no documented API to version-manage, the values could change.

Oof. I will have to think about which ones should be stable enough to risk it.

The good news for you is that Duplicati development is so low on staff that I’m not sure change is likely.

Still, values pulled from code aren’t a solid guarantee that code won’t change. I suppose this should be considered a user-visible thing (via scripting), and maybe the future developers will keep that in mind…

One problem with a few current OPERATIONNAME values is they don’t match the name from rest of UI however getting them to line up may be hard to do without breaking scripts expecting the current names.

As I am looking at the list of OPERATIONNAME values and thinking about what a “universal script” might actually DO, so far it seems to me that the only ones which will be triggering specific action are Backup and Restore. The others will probably just be treated as attributes to be reported on / logged.

I suspect those will always be there, and the names seem fine (so no temptation to “improve” name).

That’s reasonable, though I don’t want to overemphasize the chance of change, except that I strongly suspect any attempt at handling every current operation will someday find some new operation made.