#!/bin/bash # # restic-cron - Runs a Restic backup on the homedir # # by Paul van Tilburg # Nofication function notify() { notify-send -i deja-dup "$1" test -z "$RESTIC_QUIET" && echo "I: $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 export SSH_AUTH_SOCK=/run/user/1000/keyring/ssh export SSH_AGENT_PID=$(pidof ssh-agent) # Restic settings RESTIC_BACKUP_OPTIONS="--exclude-file=$HOME/.config/restic/exclude" RESTIC_FORGET_OPTIONS="--keep-weekly=4 --keep-monthly=12 --keep-yearly=60" RESTIC_DIR="$HOME" 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 test -z "$RESTIC_QUIET" && echo "I: Backup step…" restic $RESTIC_QUIET backup $RESTIC_DIR $RESTIC_BACKUP_OPTIONS status=$? if [ $status -ne 0 ]; then notify "Unable to finish the backup!" exit 2 fi # Forget old snapshots test -z "$RESTIC_QUIET" && echo "I: Forget step…" restic $RESTIC_QUIET forget $RESTIC_FORGET_OPTIONS status=$? if [ $status -ne 0 ]; then echo "E: Exit code was $status" notify "Was not able to forget old snapshots!" exit 3 fi # Prune the repository test -z "$RESTIC_QUIET" && echo "I: Prune step…" restic $RESTIC_QUIET prune status=$? if [ $status -ne 0 ]; then echo "E: Exit code was $status" notify "Was not able to prune the repository!" exit 4 fi # Verify the backup test -z "$RESTIC_QUIET" && echo "I: Check step…" restic $RESTIC_QUIET check status=$? if [ $status -ne 0 ]; then echo "E: Exit code was $status" notify "Repository check of the backup failed!" exit 5 fi notify "Backup finished!"