diff options
-rwxr-xr-x | systemd-zfs-partition-backup.sh | 50 | ||||
-rw-r--r-- | systemd-zfs-partition-backup/AUR/PKGBUILD | 2 |
2 files changed, 26 insertions, 26 deletions
diff --git a/systemd-zfs-partition-backup.sh b/systemd-zfs-partition-backup.sh index aa3951f..2310414 100755 --- a/systemd-zfs-partition-backup.sh +++ b/systemd-zfs-partition-backup.sh | |||
@@ -1,14 +1,21 @@ | |||
1 | #!/usr/bin/bash | 1 | #!/usr/bin/bash |
2 | # Written in 2020 by Max Christian Pohle <webmaster@coderonline.de> | 2 | # Written in 2020 by Max Christian Pohle <webmaster@coderonline.de> |
3 | 3 | ||
4 | # check for a configuration file and source it in if its there | ||
5 | test -f /etc/default/systemd-zfs-partition-backup &&\ | ||
6 | source /etc/default/systemd-zfs-partition-backup | ||
7 | |||
8 | DISK_NAME=$1 | ||
9 | DISK_NAME_ESCAPED=$(systemd-escape "$DISK_NAME") | ||
10 | |||
4 | function beep() { | 11 | function beep() { |
5 | test -f /usr/bin/beep &&\ | 12 | test -f /usr/bin/beep &&\ |
6 | env -u SUDO_GID -u SUDO_COMMAND -u SUDO_USER -u SUDO_UID /usr/bin/beep $@ | 13 | env -u SUDO_GID -u SUDO_COMMAND -u SUDO_USER -u SUDO_UID /usr/bin/beep $@ |
7 | } | 14 | } |
8 | 15 | ||
9 | function fail() { | 16 | function fail() { |
10 | # logger -s -t "$0" "Backup '$1' -> '$2' failed." | 17 | # logger -p debug -t "$0" "Backup '$1' -> '$2' failed." |
11 | logger -s "$@" | 18 | logger -p debug "$@" |
12 | beep -f 40 -l 500 | 19 | beep -f 40 -l 500 |
13 | # sudo -u max beep -f 523 -l 150 -n -f 54 -l 600 | 20 | # sudo -u max beep -f 523 -l 150 -n -f 54 -l 600 |
14 | } | 21 | } |
@@ -24,36 +31,30 @@ function stop() { | |||
24 | } | 31 | } |
25 | 32 | ||
26 | 33 | ||
34 | logger -p debug "disk: $DISK_NAME [esc]=> $DISK_NAME_ESCAPED" | ||
27 | 35 | ||
28 | # check for a configuration file and source it in if its there | 36 | DATASETS_WITH_DISKNAME=($(zfs list -H -o name | grep $DISK_NAME)) |
29 | test -f /etc/default/systemd-zfs-partition-backup &&\ | ||
30 | source /etc/default/systemd-zfs-partition-backup | ||
31 | |||
32 | DISK_NAME=$1 | ||
33 | DISK_NAME_ESCAPED=$(systemd-escape "$DISK_NAME") | ||
34 | |||
35 | logger "Disk: $DISK_NAME" | ||
36 | logger " : $DISK_NAME_ESCAPED (escaped)" | ||
37 | 37 | ||
38 | DATASETS_WITH_DISKNAME=$(zfs list -H -o name | grep $DISK_NAME) | 38 | if [ ${#DATASETS_WITH_DISKNAME[@]} -eq 0 ]; then |
39 | fail "No dataset found with '$DISK_NAME' as last part of its name."\ | ||
40 | "Please create such if you want to backup that partition." | ||
41 | exit 0 | ||
42 | fi | ||
39 | 43 | ||
40 | 44 | logger -p debug "${#DATASETS_WITH_DISKNAME[@]} Datasets: $DATASETS_WITH_DISKNAME" | |
41 | [ -z "$DATASETS_WITH_DISKNAME" ] &&\ | ||
42 | (fail "no datasets found with name $DISK_NAME. Please create some." ; exit 1) | ||
43 | |||
44 | logger "Datasets: $DATASETS_WITH_DISKNAME" | ||
45 | 45 | ||
46 | # iterate over all datasets | 46 | # iterate over all datasets |
47 | for i in ${DATASETS_WITH_DISKNAME[@]}; | 47 | for i in ${DATASETS_WITH_DISKNAME[@]}; |
48 | do | 48 | do |
49 | logger "assertion: $(basename $i) == $DISK_NAME" | 49 | logger -p debug "assertion: $(basename $i) ?= $DISK_NAME" |
50 | |||
50 | # compare the 'tail' of the PATH against the disk name... | 51 | # compare the 'tail' of the PATH against the disk name... |
51 | if [ "$(basename $i)" == "$DISK_NAME" ]; then | 52 | if [ "$(basename $i)" == "$DISK_NAME" ]; then |
52 | start $DISK_NAME | 53 | start |
53 | 54 | ||
54 | DISK_MOUNTPOINT="/media/$DISK_NAME" | 55 | DISK_MOUNTPOINT="/media/$DISK_NAME" |
55 | if ! findmnt $DISK_MOUNTPOINT; then | 56 | if ! findmnt $DISK_MOUNTPOINT; then |
56 | logger -s "Expected to find disk '$DISK_NAME' mounted under '$DISK_MOUNTPOINT'. But it is not there. Aborting backup." | 57 | logger -p debug "Expected to find disk '$DISK_NAME' mounted under '$DISK_MOUNTPOINT'. But it is not there. Aborting backup." |
57 | beep -f 40 -l 500 | 58 | beep -f 40 -l 500 |
58 | exit 1 | 59 | exit 1 |
59 | fi | 60 | fi |
@@ -69,13 +70,12 @@ do | |||
69 | findmnt -no source "$ZFS_MOUNTPOINT" ||\ | 70 | findmnt -no source "$ZFS_MOUNTPOINT" ||\ |
70 | (fail "Dataset $DATASET is not mounted at $ZFS_MOUNTPOINT" ; exit 1) | 71 | (fail "Dataset $DATASET is not mounted at $ZFS_MOUNTPOINT" ; exit 1) |
71 | 72 | ||
72 | logger -s "Backup from '$DISK_MOUNTPOINT' -> '$ZFS_MOUNTPOINT' possible. Starting in 10 seconds..." | 73 | logger -p debug "Backup from '$DISK_MOUNTPOINT' -> '$ZFS_MOUNTPOINT' possible. Starting..." |
73 | |||
74 | beep -f 147 -l 120 -n -f 294 -l 200 -n -f 831 | 74 | beep -f 147 -l 120 -n -f 294 -l 200 -n -f 831 |
75 | 75 | ||
76 | set -x | 76 | set -x |
77 | rsync -ahoi -x --delete --info=all \ | 77 | rsync -ahoi -x --delete --info=all \ |
78 | "$DISK_MOUNTPOINT" "$ZFS_MOUNTPOINT" \ | 78 | "$DISK_MOUNTPOINT/" "$ZFS_MOUNTPOINT/" \ |
79 | 2>&1 | tee $ZFS_MOUNTPOINT/backup-report.txt | 79 | 2>&1 | tee $ZFS_MOUNTPOINT/backup-report.txt |
80 | set +x | 80 | set +x |
81 | 81 | ||
@@ -87,12 +87,12 @@ do | |||
87 | zfs diff $DATASET_LAST_SNAPSHOT > $ZFS_MOUNTPOINT_VERIFIED/"$SYSTEMD_ZFS_PARTITION_BACKUP_DIFF_FILENAME" | 87 | zfs diff $DATASET_LAST_SNAPSHOT > $ZFS_MOUNTPOINT_VERIFIED/"$SYSTEMD_ZFS_PARTITION_BACKUP_DIFF_FILENAME" |
88 | 88 | ||
89 | if [ -n "$SYSTEMD_ZFS_PARTITION_BACKUP_EMAIL" ]; then | 89 | if [ -n "$SYSTEMD_ZFS_PARTITION_BACKUP_EMAIL" ]; then |
90 | logger -s "Here comes a list of changes since your last backup: $LAST_SNAPSHOT" |\ | 90 | logger -p debug "Here comes a list of changes since your last backup: $LAST_SNAPSHOT" |\ |
91 | mailx -A typesafe -a $ZFS_MOUNTPOINT_VERIFIED/"$SYSTEMD_ZFS_PARTITION_BACKUP_DIFF_FILENAME" -s 'Backup overview' "$SYSTEMD_ZFS_PARTITION_BACKUP_EMAIL" | 91 | mailx -A typesafe -a $ZFS_MOUNTPOINT_VERIFIED/"$SYSTEMD_ZFS_PARTITION_BACKUP_DIFF_FILENAME" -s 'Backup overview' "$SYSTEMD_ZFS_PARTITION_BACKUP_EMAIL" |
92 | fi | 92 | fi |
93 | fi | 93 | fi |
94 | 94 | ||
95 | stop $DISK_NAME | 95 | stop |
96 | 96 | ||
97 | beep -f 831 -l 120 -n -f 294 -l 200 -n -f 147 | 97 | beep -f 831 -l 120 -n -f 294 -l 200 -n -f 147 |
98 | fi | 98 | fi |
diff --git a/systemd-zfs-partition-backup/AUR/PKGBUILD b/systemd-zfs-partition-backup/AUR/PKGBUILD index 8150e9b..b0fd026 100644 --- a/systemd-zfs-partition-backup/AUR/PKGBUILD +++ b/systemd-zfs-partition-backup/AUR/PKGBUILD | |||
@@ -13,7 +13,7 @@ depends=( | |||
13 | 'mkinitcpio' | 13 | 'mkinitcpio' |
14 | ) | 14 | ) |
15 | source=("http://git.entwicklerseite.de/zfs-bash-tools/snapshot/zfs-bash-tools-master.tar.gz") | 15 | source=("http://git.entwicklerseite.de/zfs-bash-tools/snapshot/zfs-bash-tools-master.tar.gz") |
16 | sha256sums=('a6089d8abb9c5a433f0f1513194b726f7c6072849891e1922cd664be79cc4df0') | 16 | sha256sums=('ef17307fcf662f867b98e6b5d883f2eb9fcd1f38205d516d9f85f53787ed58f1') |
17 | 17 | ||
18 | package() { | 18 | package() { |
19 | install -D zfs-bash-tools-master/${pkgname}.sh \ | 19 | install -D zfs-bash-tools-master/${pkgname}.sh \ |