restic-cron/restic-cron

53 lines
1.2 KiB
Plaintext
Raw Normal View History

2016-05-20 22:45:05 +02:00
#!/bin/bash
#
# restic-cron - Runs a Restic backup on the homedir
#
# by Paul van Tilburg <paul@luon.net>
# 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
export SSH_AUTH_SOCK=/run/user/1000/keyring/ssh
export SSH_AGENT_PID=$(pidof ssh-agent)
# 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
2016-05-20 22:45:05 +02:00
if [ $? -ne 0 ]; then
notify "Unable to finish the backup!"
exit 2
fi
# Verify the backup
restic $RESTIC_QUIET check
2016-05-20 22:45:05 +02:00
if [ $? -ne 0 ]; then
notify "Repository check of the backup failed!"
exit 3
fi
notify "Backup finished!"