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