backup script
authorMart Lubbers <mart@martlubbers.net>
Tue, 24 Jul 2018 10:29:21 +0000 (12:29 +0200)
committerMart Lubbers <mart@martlubbers.net>
Tue, 24 Jul 2018 10:29:42 +0000 (12:29 +0200)
shell/.config/tmux/config
shell/.local/bin/backup.sh [new file with mode: 0755]
udev/backup.rules [new file with mode: 0644]

index 7bf6ba8..127a0ed 100644 (file)
@@ -17,3 +17,9 @@ bind H split-window -h
 
 # Start not at index 0 but at one for windows
 set -g base-index 1
+
+# vi copy and pasting
+bind-key -T copy-mode-vi 'v' send -X begin-selection
+bind-key -T copy-mode-vi 'y' send -X copy-selection
+bind-key -T copy-mode-vi 'Space' send -X halfpage-down
+bind-key -T copy-mode-vi 'Bspace' send -X halfpage-up
diff --git a/shell/.local/bin/backup.sh b/shell/.local/bin/backup.sh
new file mode 100755 (executable)
index 0000000..d3a8c23
--- /dev/null
@@ -0,0 +1,33 @@
+#!/bin/sh
+trap 'um' 0 1 3 6 15
+um ()
+{
+       if mountpoint -q /mnt/backupdrive; then umount /mnt/backupdrive; fi
+}
+
+start="$(date)"
+if [ ! -n "$1" ]
+then
+       echo "Was this script called from udev? I need the ID_FS_UUID_ENC variable" | tee /home/mrl/backup.log
+       exit 1
+elif mountpoint -q /mnt/backupdrive
+then
+       cat<<MAIL | su -c 'ssh helheim /usr/lib/sendmail backups@martlubbers.net' mrl
+To: mart@martlubbers.net
+From: backups@martlubbers.net
+Subject: Backup failed ($start)
+Backup failed at at $(date) because /mnt/backupdrive was already a mountpoint
+MAIL
+elif mount -U "$1"
+then
+       mkdir -p /mnt/backupdrive/home/mrl /mnt/backupdrive/mnt/data &&\
+       rsync --delete --bwlimit=20M --exclude 'minidlna/*' --exclude 'transmission/ipt/*' -va /mnt/data/ /mnt/backupdrive/mnt/data > /home/mrl/backup.log &&\
+       rsync --delete --bwlimit=20M -va /home/mrl/ /mnt/backupdrive/home/mrl >> /home/mrl/backup.log &&\
+       umount /mnt/backupdrive &&\
+       cat<<MAIL | su -c 'ssh helheim /usr/lib/sendmail backups@martlubbers.net' mrl
+To: mart@martlubbers.net
+From: backups@martlubbers.net
+Subject: Backup finished ($start)
+Successfully finished at $(date)
+MAIL
+fi
diff --git a/udev/backup.rules b/udev/backup.rules
new file mode 100644 (file)
index 0000000..34b3264
--- /dev/null
@@ -0,0 +1 @@
+ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd?", RUN+="/bin/sh -c 'echo /home/mrl/.local/bin/backup.sh %E{ID_FS_UUID_ENC} | batch'"