aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsystemd-zfs-partition-backup.sh22
-rw-r--r--systemd-zfs-partition-backup/AUR/PKGBUILD2
-rw-r--r--systemd-zfs-partition-backup/systemd/systemd-zfs-partition-backup@.service2
-rw-r--r--systemd-zfs-partition-backup/udev/rules.d/90-systemd-zfs-partition-backup.rules3
4 files changed, 16 insertions, 13 deletions
diff --git a/systemd-zfs-partition-backup.sh b/systemd-zfs-partition-backup.sh
index 2310414..8a89718 100755
--- a/systemd-zfs-partition-backup.sh
+++ b/systemd-zfs-partition-backup.sh
@@ -6,7 +6,6 @@ test -f /etc/default/systemd-zfs-partition-backup &&\
6 source /etc/default/systemd-zfs-partition-backup 6 source /etc/default/systemd-zfs-partition-backup
7 7
8DISK_NAME=$1 8DISK_NAME=$1
9DISK_NAME_ESCAPED=$(systemd-escape "$DISK_NAME")
10 9
11function beep() { 10function beep() {
12 test -f /usr/bin/beep &&\ 11 test -f /usr/bin/beep &&\
@@ -21,13 +20,13 @@ function fail() {
21} 20}
22 21
23function start() { 22function start() {
24 systemctl start media-$DISK_NAME_ESCAPED.automount ||\ 23 UNIT_NAME=$(systemd-escape --suffix=automount $1)
25 (fail "could not start disk with service media-$DISK_NAME_ESCAPED.automount"; exit 1) 24 systemctl start "$UNIT_NAME" || (fail "$UNIT_NAME not found." ; exit 1)
26} 25}
27 26
28function stop() { 27function stop() {
29 systemctl stop media-$DISK_NAME_ESCAPED.automount ||\ 28 UNIT_NAME=$(systemd-escape --suffix=automount $1)
30 (fail "could not stop disk with service media-$DISK_NAME_ESCAPED.automount"; exit 1) 29 systemctl stop "$UNIT_NAME" || (fail "$UNIT_NAME not found." ; exit 1)
31} 30}
32 31
33 32
@@ -46,19 +45,22 @@ logger -p debug "${#DATASETS_WITH_DISKNAME[@]} Datasets: $DATASETS_WITH_DISKNAME
46# iterate over all datasets 45# iterate over all datasets
47for i in ${DATASETS_WITH_DISKNAME[@]}; 46for i in ${DATASETS_WITH_DISKNAME[@]};
48do 47do
49 logger -p debug "assertion: $(basename $i) ?= $DISK_NAME" 48 logger -p debug "assertion: "$i" =~ .*/$DISK_NAME"
50 49
51 # compare the 'tail' of the PATH against the disk name... 50 # compare the 'tail' of the PATH against the disk name...
52 if [ "$(basename $i)" == "$DISK_NAME" ]; then 51 if [[ $i =~ .*/$DISK_NAME ]]; then
53 start
54 52
55 DISK_MOUNTPOINT="/media/$DISK_NAME" 53 DISK_MOUNTPOINT="/media/$DISK_NAME"
54
55 start "media/$DISK_NAME" # without leading slash for the unit file
56
56 if ! findmnt $DISK_MOUNTPOINT; then 57 if ! findmnt $DISK_MOUNTPOINT; then
57 logger -p debug "Expected to find disk '$DISK_NAME' mounted under '$DISK_MOUNTPOINT'. But it is not there. Aborting backup." 58 logger -p debug "Expected to find disk '$DISK_NAME' mounted under '$DISK_MOUNTPOINT'. But it is not there. Aborting backup."
58 beep -f 40 -l 500 59 beep -f 40 -l 500
59 exit 1 60 exit 1
60 fi 61 fi
61 62
63
62 DATASET=$i 64 DATASET=$i
63 DATASET_LAST_SNAPSHOT=$(zfs list -t snap -o name -s creation "$DATASET" | tail -n1) ||\ 65 DATASET_LAST_SNAPSHOT=$(zfs list -t snap -o name -s creation "$DATASET" | tail -n1) ||\
64 (fail "we could not find a previous backup. Backup may still be possible (first time backup?)") 66 (fail "we could not find a previous backup. Backup may still be possible (first time backup?)")
@@ -92,9 +94,11 @@ do
92 fi 94 fi
93 fi 95 fi
94 96
95 stop 97 stop "media/$DISK_NAME" # without leading slash for the unit file
96 98
97 beep -f 831 -l 120 -n -f 294 -l 200 -n -f 147 99 beep -f 831 -l 120 -n -f 294 -l 200 -n -f 147
100 else
101 logger -p error "assertion failed: [[ $i =~ .*/$DISK_NAME ]] => false"
98 fi 102 fi
99done 103done
100 104
diff --git a/systemd-zfs-partition-backup/AUR/PKGBUILD b/systemd-zfs-partition-backup/AUR/PKGBUILD
index 39b4e4c..d2543f6 100644
--- a/systemd-zfs-partition-backup/AUR/PKGBUILD
+++ b/systemd-zfs-partition-backup/AUR/PKGBUILD
@@ -14,7 +14,7 @@ depends=(
14 'rsync' 14 'rsync'
15) 15)
16source=("http://git.entwicklerseite.de/zfs-bash-tools/snapshot/zfs-bash-tools-master.tar.gz") 16source=("http://git.entwicklerseite.de/zfs-bash-tools/snapshot/zfs-bash-tools-master.tar.gz")
17sha256sums=('2930678316eb0a6e67ab29f2ad378ea4d6e90ec49870742d68f78278c1a949e3') 17sha256sums=('b89036a82f8ab86214016514931e7921027efdcaedeadaec0776a5eb94e33d18')
18 18
19package() { 19package() {
20 install -D zfs-bash-tools-master/${pkgname}.sh \ 20 install -D zfs-bash-tools-master/${pkgname}.sh \
diff --git a/systemd-zfs-partition-backup/systemd/systemd-zfs-partition-backup@.service b/systemd-zfs-partition-backup/systemd/systemd-zfs-partition-backup@.service
index d7948a8..a4577c4 100644
--- a/systemd-zfs-partition-backup/systemd/systemd-zfs-partition-backup@.service
+++ b/systemd-zfs-partition-backup/systemd/systemd-zfs-partition-backup@.service
@@ -3,5 +3,5 @@ Description=Generic backup
3 3
4[Service] 4[Service]
5Type=simple 5Type=simple
6ExecStart=/usr/bin/systemd-zfs-partition-backup.sh %I 6ExecStart=/usr/bin/systemd-zfs-partition-backup.sh "%I"
7 7
diff --git a/systemd-zfs-partition-backup/udev/rules.d/90-systemd-zfs-partition-backup.rules b/systemd-zfs-partition-backup/udev/rules.d/90-systemd-zfs-partition-backup.rules
index 2a92960..3d05925 100644
--- a/systemd-zfs-partition-backup/udev/rules.d/90-systemd-zfs-partition-backup.rules
+++ b/systemd-zfs-partition-backup/udev/rules.d/90-systemd-zfs-partition-backup.rules
@@ -1,2 +1 @@
1ACTION=="add", ENV{ID_PART_ENTRY_NUMBER}=="[0-9]", ENV{SYSTEMD_WANTS}="systemd-zfs-partition-backup@$env{ID_SERIAL}\\x2dpart$env{ID_PART_ENTRY_NUMBER}.service" ACTION=="add", SUBSYSTEM=="block", ENV{DEVTYPE}=="partition", PROGRAM="/bin/systemd-escape --template systemd-zfs-partition-backup@.service $env{ID_MODEL}.$env{ID_SERIAL_SHORT}/$env{ID_FS_UUID}", ENV{SYSTEMD_WANTS}+="$result"
2LABEL="External disk drive backup"
..