lobaro / restic-backup-docker

A docker container to automate backups with restic
Apache License 2.0
330 stars 114 forks source link

Create hook to run a script before notification email is sent #70

Open ftwegner opened 2 years ago

ftwegner commented 2 years ago

I like to have a hook to insert a script which runs before a notification email is sent.

Motivation: I like to see the total space occupied by all restic snapshots on the target server. I need this, because my target server has a quota, and I like to make sure I do not exceed the quota with the backup snapshots. As a hack-y workaround I modified /bin/backup and inserted four lines before the notifications are generated when I do rclone backups via sftp:

logLast " "
logLast " "
logLast "Total size occupied by all restic snapshots:"
ssh -i /volume1/docker/privatekey.pem ssh-user@111111111111.hostingkunde.de 'du -h restic/ | tail -1' >> ${lastLogfile} 2>&1

This is for my web space at Domain Factory's ManagedHosting 64 Medium which contains ssh access. It has a 50 GB quota. The snapshots are in the sub-folder "restic/". The generated text in the email I get ends with:

Total size occupied by all restic snapshots:
8.4G    restic/

Of course, it would be much nicer and more sustainable to have this built in. And maybe there is a much more elegant way to find out if I get close to exceeding the available space on the target medium?

niondir commented 2 years ago

Having some documented "hooks" .sh scripts that are called optionally if linked or placed inside the container would be fine I guess. It should not change the default behavior if someone do not want to use any hooks.

PR is welcome.