]> piware.de Git - bin.git/blob - backup
backup: Clean up old backups
[bin.git] / backup
1 #!/bin/sh
2 set -eu
3 cd $HOME
4 LOG=.cache/duplicity/log
5
6 # do backup every day
7 if [ -e "$LOG" ] && [ $(( `date +%s` - `stat -c %Y $LOG` )) -lt 86300 ]; then
8     exit 0
9 fi
10
11 # figure out $DISPLAY when running from cron
12 export DISPLAY="${DISPLAY:-:0}"
13
14 if ! ip route | grep -q '^default.*wl'; then
15     notify-send "Backup skipped, not on WLAN"
16     exit 0
17 fi
18
19 # figure out ssh agent when running from cron
20 if [ -z "${SSH_AUTH_SOCK:-}" ]; then
21     ssh_socket=$(ls /run/user/`id -u`/keyring*/ssh 2>/dev/null)
22     if [ -S "$ssh_socket" ]; then
23         export SSH_AUTH_SOCK="$ssh_socket"
24     fi
25 fi
26
27 notify-send "Backup started"
28 mkdir -p $(dirname $LOG)
29 env PASSPHRASE="$(cat ~/.backup-passphrase)" duplicity --allow-source-mismatch --full-if-older-than 1M --exclude-filelist .duplicity-ignore . rsync://piware.de/backup/donald >> $LOG || { notify-send "BACKUP FAILED!"; exit 1; }
30 notify-send "Backup finished successfully"
31 duplicity remove-all-but-n-full 6 --force rsync://piware.de/backup/donald