54 lines
1.2 KiB
Bash
Executable File
54 lines
1.2 KiB
Bash
Executable File
#!/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"
|
|
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
|
|
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!"
|