commit 0da287d5e599484f70b420db829b2da14ddd7b2a Author: Paul van Tilburg Date: Fri May 20 22:45:05 2016 +0200 Initial import of the script diff --git a/restic-cron b/restic-cron new file mode 100755 index 0000000..dffcad8 --- /dev/null +++ b/restic-cron @@ -0,0 +1,56 @@ +#!/bin/bash +# +# restic-cron - Runs a Restic backup on the homedir +# +# by Paul van Tilburg + +# Nofication function +notify() { + notify-send -i deja-dup "$1" +} + +# Check if a --verbose argument is passed, otherwise use quiet +RESTIC_QUIET="--quiet" +if [ "$1" = "--verbose" ]; then + RESTIC_QUIET="" +fi + +# Allow for connecting to X11 and the SSH agent +eval $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ) +export DBUS_SESSION_BUS_ADDRESS +export DISPLAY=:0 +export SSH_AUTH_SOCK=/run/user/1000/keyring/ssh +export SSH_AGENT_PID=$(pidof ssh-agent) +export XAUTHORITY=/run/user/1000/gdm/Xauthority + +# Restic settings +export RESTIC_BACKUP_OPTIONS="--exclude-file=$HOME/.config/restic/exclude" +export RESTIC_REPOSITORY="sftp://void//media/Backup/entropy" + +# Start the backup by asking for the passphrase +notify "Starting backup…" +sleep 3 +export RESTIC_PASSWORD=$(zenity --title="Restic backup passphrase" --password) + +if [ -z "$RESTIC_PASSWORD" ]; then + notify "Backup aborted due to empty passphrase or cancellation!" + exit 1 +fi + +# Create a new backup +restic $RESTIC_QUIET backup $HOME $RESTIC_BACKUP_OPTIONS + +if [ $? -ne 0 ]; then + notify "Unable to finish the backup!" + exit 2 +fi + +# Verify the backup +restic $RESTIC_QUIET check + +if [ $? -ne 0 ]; then + notify "Repository check of the backup failed!" + exit 3 +fi + +notify "Backup finished!"