aboutsummaryrefslogtreecommitdiff
path: root/backup/backup.sh
diff options
context:
space:
mode:
authorMax Christian Pohle2020-07-11 14:11:07 +0200
committerMax Christian Pohle2020-07-11 14:11:07 +0200
commit76e0da0ef07a921e27b12a447692d1e952d922f4 (patch)
tree656932887f776bb0f838ce86ab8d4d16f430b097 /backup/backup.sh
parentd9804a00d1d2164f5c25d743d18bd4f6a8776f31 (diff)
downloadzfs-bash-tools-76e0da0ef07a921e27b12a447692d1e952d922f4.tar.bz2
zfs-bash-tools-76e0da0ef07a921e27b12a447692d1e952d922f4.zip
Spring cleaning
Diffstat (limited to 'backup/backup.sh')
-rwxr-xr-xbackup/backup.sh75
1 files changed, 0 insertions, 75 deletions
diff --git a/backup/backup.sh b/backup/backup.sh
deleted file mode 100755
index 91acdfc..0000000
--- a/backup/backup.sh
+++ /dev/null
@@ -1,75 +0,0 @@
1#!/usr/bin/bash
2logger "================================================================================"
3
4# BACKUP_NAME=$ID_SERIAL-part$ID_PART_ENTRY_NUMBER
5BACKUP_NAME=$(echo $1 | sed -e 's/\\x2d/-/g')
6MOUNT_TARGET=/media/$BACKUP_NAME
7
8function fail() {
9 logger -s -t "$0" "Backup '$1' -> '$2' failed."
10 sudo -u max beep -f 40 -l 500
11 # sudo -u max beep -f 523 -l 150 -n -f 54 -l 600
12}
13
14function start() {
15 DEVNAME=$(echo $1 | sed 's/-/\\x2d/')
16 systemctl restart media-$DEVNAME.automount
17
18 logger -t "$0" "Backup '$1' -> '$2' started."
19 sudo -u max beep -f 147 -l 120 -n -f 294 -l 200 -n -f 831
20}
21
22function stop() {
23 DEVNAME=$(echo $1 | sed 's/-/\\x2d/')
24 systemctl stop media-$DEVNAME.automount
25
26 logger -t "$0" "Backup '$1' -> '$2' finished."
27 sudo -u max beep -f 831 -l 120 -n -f 294 -l 200 -n -f 147
28}
29
30function zfs_snapshot() {
31 zfs diff $LAST_SNAPSHOT > $ZFS_PATH/backup-differences.txt
32 zfs snap media-backup/$BACKUP_NAME@$(date +%Y-%m-%d--%H-%M)
33 echo "Here comes a list of changes since your last backup: $LAST_SNAPSHOT" | mailx -A typesafe -a $ZFS_PATH/backup-differences.txt -s 'Backup overview' max@entwicklerseite.de
34}
35
36start $1
37
38if ! findmnt $MOUNT_TARGET; then
39 logger "$MOUNT_TARGET is not mounted. Cannot back it up."
40 exit 0
41fi
42
43logger ">> Inspecting $BACKUP_NAME"
44ZFS_PATH=$(zfs get mountpoint -H -o value media-backup/$BACKUP_NAME) || fail "$MOUNT_TARGET" "(no zfs dataset found)"
45ZFS_MOUNTPATH=$(findmnt -no source $ZFS_PATH) || fail "$ZFS_PATH (not mounted)" "(no association)"
46LAST_SNAPSHOT=$(zfs list -t snap -o name -s creation media-backup/$BACKUP_NAME | tail -n1)
47
48
49# Make sure, that we are really writing where a mountpoint is
50if [ "$ZFS_PATH" == "/$ZFS_MOUNTPATH" ]; then
51 sudo -u max beep -f 831
52 logger "We can start $MOUNT_TARGET -> $ZFS_PATH"
53 rsync -ahoi -x --delete --info=all \
54 "/media/$BACKUP_NAME/" \
55 "$ZFS_PATH" \
56 2>&1 | tee $ZFS_PATH/backup-report.txt && zfs_snapshot
57
58else
59 fail $ZFS_PATH $ZFS_MOUNTPATH
60 exit 1
61fi
62
63
64
65stop $1
66
67# sleep a second so that /dev/disk/by-id/*-part become available
68# sleep 1
69
70# DISK=$(readlink -f /dev/disk/by-id/$ID_BUS-$ID_SERIAL)
71# if ! [ -e "$DISK" ]; then
72# fail
73# logger "$DISK: Disk not there :("
74# exit 1
75# fi
..