]> piware.de Git - bin.git/blob - backup
move backup to duplicity
[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 if [ -z "${DISPLAY:-}" ]; then
13     socket="/run/user/`id -u`/X11-display"
14     if [ -L "$socket" ]; then
15         socket=$(readlink "$socket")
16         export DISPLAY=:${socket##*/X}
17     fi
18 fi
19
20 if ! ip route | grep -q '^default.*wlan'; then
21     notify-send "Backup skipped, not on WLAN"
22     exit 0
23 fi
24
25 notify-send "Backup started"
26 mkdir -p $(dirname $LOG)
27 env PASSPHRASE="$(cat ~/.backup-passphrase)" duplicity --full-if-older-than 1M --exclude-globbing-filelist .duplicity-ignore . rsync://piware.de/backup/donald >> $LOG || { notify-send "BACKUP FAILED!"; exit 1; }
28 notify-send "Backup finished successfully"