submodules
[dotfiles.git] / shell / .local / bin / backup.sh
1 #!/bin/sh
2 trap 'um' 0 1 3 6 15
3 um ()
4 {
5 if mountpoint -q /mnt/backupdrive; then umount /mnt/backupdrive; fi
6 }
7
8 start="$(date)"
9 if [ ! -n "$1" ]
10 then
11 echo "Was this script called from udev? I need the UUID as the first argument" > /home/mrl/backup.log
12 exit 1
13 elif mountpoint -q /mnt/backupdrive
14 then
15 cat<<MAIL | su -c 'ssh helheim /usr/lib/sendmail backups@martlubbers.net' mrl
16 To: mart@martlubbers.net
17 From: backups@martlubbers.net
18 Subject: Backup failed ($start)
19 Backup failed at at $(date) because /mnt/backupdrive was already a mountpoint
20 MAIL
21 elif mount -U "$1"
22 then
23 mkdir -p /mnt/backupdrive/home/mrl /mnt/backupdrive/mnt/data &&\
24 rsync --delete --bwlimit=20M --exclude 'minidlna/*' --exclude 'transmission/ipt/*' -va /mnt/data/ /mnt/backupdrive/mnt/data > /home/mrl/backup.log &&\
25 rsync --delete --bwlimit=20M \
26 --exclude '.local' \
27 --exclude '.zotero' \
28 --exclude '.config' \
29 --exclude '.cache' \
30 --exclude '.mozilla' \
31 --exclude '.java' \
32 --exclude 'VirtualBox VMs' \
33 -va /home/mrl/ /mnt/backupdrive/home/mrl >> /home/mrl/backup.log &&\
34 umount /mnt/backupdrive &&\
35 cat<<MAIL | su -c 'ssh helheim /usr/lib/sendmail backups@martlubbers.net' mrl
36 To: mart@martlubbers.net
37 From: backups@martlubbers.net
38 Subject: Backup finished ($start)
39 Successfully finished at $(date)
40 MAIL
41 fi