Duplicati + healthchecks

Hi there!

Is there anyone, who tried to use duplicati with mychecks?
All I want to do is to make my duplicati job status reported on mychecks. Basically duplicati have to send a http request after doing the backup job depending of its result, for example:

when job passes:
http://mychecks.example/check_id....

or
http://mychecks.example/check_id..../fail
when it fails.

I was reading some docu and want to try executing –run-script-after. Is it a good way or is there some better?

Cheers!

1 Like

Hello

what’s wrong with reporting send-http options ?

1 Like

I don’t know. Is it really something wrong with it?
I was expecting some hints, because it’s really hard to understand the docu. Let’s have a very first - –run-script-after. Description - “HTTP report url.”. Nice, but what it really does? What is report? How do I know what the job exit code is and how to use it to send proper http request?

All I need is to request
http://mychecks.example/check_id....
or
http://mychecks.example/check_id..../fail
accordingly with job’s exit code. That’s it.

1 Like

I don’t know what your mychecks runs, but I found several that run the healthchecks.io code.

If this is the same as healthchecks.io documents (and your example is quite reminiscent of it):

In case someone else comes around looking for an example script for healthchecks.io,
posted a starter script and then an issue. but at least that should qualify as a try in my opinion.

Duplicati Notifcation forum topic has some of the same information that I’m posting now.
Example Scripts covers DUPLICATI__PARSED_RESULT as used in linked example script.
There are probably some other script variables that you would want to use for the need.

The example script covers this if you use bash. If this is Windows, you can translate that.

Although you might not need it for your simple two-URL-no-report approach, it’s set using
Reporting options in the User Manual, and is very flexible but possibly also not necessary.

Pinging API seems to allow HTTP POST if you want to put in some additional information.
I don’t know if you ever send reports by email, but I think the HTTP report is rather similar.

Below is a third-party Duplicati-specific option that had an outage and healthchecks.io talk:

I have no script to give, but there are some hints. I collected healthchecks topics via forum search box.
If mychecks is healthchecks, great. If not, some of the ideas might apply, or you can cover differences.

2 Likes

Hi @ts678!

You helped me a lot! Thanks :smile:

You’re right, mychecks is not common name, healthchecks is better :slight_smile: so I’ve changed this topic’s name.

Yes, this is basically what I need now. I forgot to check github before :face_with_open_eyes_and_hand_over_mouth:. Definitely I will try this.

I will check it out and if it will be valuable enough I will post some guide here.
Thanks again.

2 Likes

So I’ve prepared scripts for executing before and after the job using issues/4220. It’s a quite good way to send the status to healthchecks. My tries showed the issue is that script has to be hardcoded with UID value, so preparing and having separate scripts (actually 2 of them, for before and after) for each duplicati’s job will be painful.

What I’ve tried so far is to have universal script with 1 positional argument (for UID) and execute it from duplicati like “before.sh 1234-5678-abc”. Doesn’t work, because duplicat can’t find this file (just because of positional argument, it works without it).

The best way would be to have these 2 scripts universal (without any hardoced vaules inside). So I wanted to ask you about:

  1. Is there way to pass somehow UID to the script with duplicati GUI?
  2. Is it possible to set my custom variable and set it as environment variable with duplicati GUI? So the scripts could easily read it.
  3. Is there some advanced option in duplicati GUI that could be used for passing the UID value? I was looking at them by the name and found parameters-file, but I’m not sure it could help.
1 Like

Arguments for scripts before/after options #2926 is enhancement you likely wish is done.

Unless there is a conflict, you can probably get before script to save UUID for after to read.
That still means script for every job. Are jobs all on one system, or spread across various?

The parameters-file option only works on the commandline. GUI uses server database.

Duplicati gives you lots of environment variables. Can’t script map, say, job name to UUID?
DUPLICATI__backup_name would be job name, and Linux probably has host info if needed.
If you want some ideas, just have the script write environment variables to a file, for a study.

EDIT:

DUPLICATI__REMOTEURL could also be used. Typically the folder is unique for every backup.
For this or the job name, I suppose you could put the UUID in the string, instead of mapping.

1 Like

which rules out putting maps in the script. You can decide which is tidier, but in addition to extracting the UUID from variables like job names or destinations, you could pass it in any option that isn’t being used, such as Reporting options strings that aren’t used because you’re doing the reporting in a different way.

Not exactly meeting the universal script rule, but avoiding parallel-maintaining multiple scripts that could eventually get rather complicated if you get ambitious is to put most of the processing into another script which is called from a trivial first script that exists just to pass UUID in. Or you can use links and use $0.

1 Like

Great info all around!
@majki Do you know about https://www.duplicati-monitoring.com/ ?

OK, I’m done.

First of all, that was a nightmare to setup duplicati with healthchecks, but apparently it’s possible and working.

What I did is to use:

  • before script,
  • after script,
  • non-used String field to pass the check’s link to both scripts. Here it is send-http-extra-parameters, because it was not used. If it’s used in your instance, you need to use another one.

In my case I put both script files into /home.

Scripts

before.sh

#!/bin/bash

URL="$DUPLICATI__send_http_extra_parameters/start"

curl -m 10 --retry 5 -s ${URL}

exit 0

after.sh

#!/bin/bash

URL=$DUPLICATI__send_http_extra_parameters

if [[ ${DUPLICATI__PARSED_RESULT} = "Success" ]]; then
  echo "Success"
  curl -m 10 --retry 5 -s --data-binary @$DUPLICATI__RESULTFILE ${URL}
else
  echo "Fail"
  curl -m 10 --retry 5 -s --data-binary @$DUPLICATI__RESULTFILE ${URL}/fail
fi

exit 0

Setup

In duplicati job open last tab and Advanced options. Add 3 options there:

  1. send-http-extra-parameters and put the check link as value,
  2. run-script-after and put /home/after.sh,
  3. run-script-before and put /home/before.sh.

And that’s it! Now run the job and check if the status has been updated in your healthchecks. Repeat to your other jobs, replacing only send-http-extra-parameters value :grin:

2 Likes

Good job, that is a nice guide. I hope it will help others to simplify the setup.

I see a few things that can be improved:

REM DUPLICATI__EVENTNAME
REM Eventname is BEFORE if invoked as --run-script-before, and AFTER if 
REM invoked as --run-script-after. This value cannot be changed by writing
REM it back!

REM DUPLICATI__OPERATIONNAME
REM Operation name can be any of the operations that Duplicati supports. For
REM example it can be "Backup", "Cleanup", "Restore", or "DeleteAllButN".
REM This value cannot be changed by writing it back!

You can use the event name to combine both scripts into a single one, that works before and after. That might be more convenient.

Also, in the past some people with scripts ran into issues, because they will also run for restore operations. So I would recommend to check the operation for backup, if that is not wanted.

1 Like

Right, so I’ve updated the script with @Jojo-1000’s advice - thanks Mate! Now it’s 1-filer for both before and after to apply. Rest remains the same. You can use both versions alternatively.

Quick brief:

  • 1-file for before and after, script distinguishes both automatically,
  • will work only for backup jobs, otherwise it will exit safely to restoring be possible,
  • logging added, two log files for each event,
  • job’s name logged.

1-file script:

#!/bin/bash

LOGFILE_BEFORE="/home/before.log"
LOGFILE_AFTER="/home/after.log"

EVENTNAME=$DUPLICATI__EVENTNAME
OPERATIONNAME=$DUPLICATI__OPERATIONNAME
NAME=$DUPLICATI__backup_name

if [[ "$OPERATIONNAME" != "Backup" ]]; then
  echo "Not a backup job, exiting." > $LOGFILE_BEFORE
  exit 0  # has to be 0 or else you won't be able to fetch backups list for restore
fi

if [[ "$EVENTNAME" = "BEFORE" ]]; then
  URL="$DUPLICATI__send_http_extra_parameters/start"

  echo "Before script started for: $NAME" > $LOGFILE_BEFORE
  echo "EVENTNAME=$EVENTNAME" >> $LOGFILE_BEFORE
  echo "OPERATIONNAME=$OPERATIONNAME" >> $LOGFILE_BEFORE
  echo "URL=$URL" >> $LOGFILE_BEFORE

  curl -m 10 --retry 5 -s ${URL}
  exit 0

elif [[ "$EVENTNAME" = "AFTER" ]]; then
  echo "After script started for: $NAME" > $LOGFILE_AFTER
  URL=$DUPLICATI__send_http_extra_parameters

  if [[ ${DUPLICATI__PARSED_RESULT} = "Success" ]]; then
    # echo "Success"
    curl -m 10 --retry 5 -s --data-binary @$DUPLICATI__RESULTFILE ${URL}
  else
    # echo "Fail"
    curl -m 10 --retry 5 -s --data-binary @$DUPLICATI__RESULTFILE ${URL}/fail
  fi

  echo "EVENTNAME=$EVENTNAME" >> $LOGFILE_AFTER
  echo "OPERATIONNAME=$OPERATIONNAME" >> $LOGFILE_AFTER
  echo "URL=$URL" >> $LOGFILE_AFTER
  echo "DUPLICATI__PARSED_RESULT=$DUPLICATI__PARSED_RESULT" >> $LOGFILE_AFTER

  exit 0
fi
1 Like