Posting duplicati backup events to Slack channel

First off, I really enjoy duplicati. It’s a great project that has already spared me a lot of time building my own custom backup solution (for backing up to Google Drive).

I was wondering if anyone has managed to get posting messages to Slack working. I’d like to report to Slack if a backup was run (the backup name) and the outcome (succes/fail). I think I have to use the global options ‘send-http-url’ and ‘send-http-any-operation’, but have not really found how to add useful parameters to the message.

So, before re-inventing the wheel, has anyone else done this (or something alike) and/or can point me to some examples and/or can point me to some documentation?

1 Like

I’m not familiar with Slack, but assuming it’s got a CLI available for it you could probably use the ‘run-script-after’ feature.

Various info about the competed job should be available in ‘duplicati__XXXX’ style environment variables (note the 2 underscores).

It’s a bit more “hackey” than an http API but is better than nothing. :slight_smile:

1 Like

Thank you for your quick reply.

I’ll give the run-script-after feature a try, using curl under the hoods (Slack has a very decent HTTP API).
Knowing the environment variables pattern helps me.

This is the script’ content that worked for me:
(don’t forget to make the file executable, if on mac or linux)

#!/bin/bash

SLACK_WEBHOOK_URL=https://hooks.slack.com/services/OBFUSCATED
SLACK_CHANNEL="#backups"
SLACK_MSG="Backup performed for ${DUPLICATI__backup_name}"

curl -s -X POST --data-urlencode "payload={\"channel\": \"${SLACK_CHANNEL}\", \"username\": \"duplicati\", \"text\": \"${SLACK_MSG}\", \"icon_emoji\": \":information_source:\"}" "${SLACK_WEBHOOK_URL}"

The only wish that I have left right now is to be able to detect whether a backup failed, so I can change how I post the message to slack (with a big exclamation if it failed). I couldn’t find an appropriate DUPLICATI__xxx environment variable for that, not from the environment variables printed, neither from source

1 Like

That was fast - well done!

This list from another topic might help…

Edit: Removed scripting code that somehow got in there with a copy paste (sorry about that).

2 Likes

That would help me achieve what I want. However, the DUPLICATI__PARSED_RESULT is not shown to me, only these:

DUPLICATI__backup_name=nodered
DUPLICATI__block_hash_algorithm=SHA256
DUPLICATI__blocksize=102400b
DUPLICATI__compression_module=zip
DUPLICATI__dblock_size=50mb
DUPLICATI__dbpath=/config/ZSXXMASDPH.sqlite
DUPLICATI__disable_module=console-password-input
DUPLICATI__encryption_module=aes
DUPLICATI__EVENTNAME=AFTER
DUPLICATI__file_hash_algorithm=SHA256
DUPLICATI__keep_time=1M
DUPLICATI__LOCALPATH=/source/nodered/data/
DUPLICATI__main_action=Backup
DUPLICATI__OPERATIONNAME=Backup
DUPLICATI__passphrase=OBFUSCATED
DUPLICATI__REMOTEURL=googledrive://nodered?authid=OBFUSCATED
DUPLICATI__RESULTFILE=/tmp/dup-33ef979a-d629-4257-93a7-f7cb44cc2ef3
DUPLICATI__run_script_after=/config/slack_msg.sh
DUPLICATI__throttle_download=
DUPLICATI__throttle_upload=

Could this be a bug? I’m running duplicati version 2.0.2.1 from the docker container provided by linuxserver.io.

Update: just found out that this variable was added on September 1st. I’ll try to update my duplicati (read: build my own container).

Oops, sorry about that - I don’t think I realized it wasn’t in the “standard” Docker yet since I don’t use the feature myself.

Good luck with your custom container! Let us know how it goes - or better yet, when you get it going post how you did it in the How-To category. :smiley:

I’m using the linuxserver.io docker container and found out that updating to latest Canary from the Duplicati web interface was easiest. Not a good solution because a re-deploy of the container means I’ll have to do it again, but good enough for now.

1 Like

Maybe we should make a Slack module, so it is a matter of supplying the channel and API token.

1 Like

I’m still new to Docker so maybe there’s a taboo against this but couldn’t a “Duplicati Canary” container be created & maintained with the latest Canary versions?

Yes, it could. It would also be easy to integrate with the release build script.

It would probably just be “derive from the mono image, then install unzip, then download and unzip the canary.zip, then run Duplicati.Server.exe”

hi,

did anything happen?
would also like to see some kind of messenger integration like slack, discord, nextcloud (talk) or mastodon etc

Apprise - Push Notifications that work with just about every platform! is a push notification specialist that supports many but not all of the services mentioned. It can probably be run directly, or by integration with
Announcing dupReport - A Duplicati Email Report Summary Generator (presumably with higher latency).

1 Like

Yes, Docker images are now created as part of the build process:
https://hub.docker.com/r/duplicati/duplicati

The most flexible way is to do it in a script, as shown by @randomname872634

Slack and Discord both supports a simple API for sending a POST message. I assume NextCloud and Mastodon have similar features.

If someone wants to develop a more streamlined integration for one of the providers, there is basic HTTP post code here:

It would be a fairly simple change, mostly deciding which parameters to expose (channel name, token, avatar, etc). A good “getting started” project for contributing to Duplicati.

Sorry didn’t want to be rude :slight_smile:
But I am using the docker image for quite some time already, with automatic updates using watchtower and all I can say - rock solid :smiley:

And thanks for the rest :slight_smile: of the information.

1 Like

I did not read it as being rude. I thought you were requesting status on the Docker builds, but since you are already using them, did you ask for something else?

I was actually only interested in the slack notification status, because this is something I would like to use, but I got my answer anyhow.