diff options
Diffstat (limited to 'systemd-zfs-partition-backup.sh')
| -rwxr-xr-x | systemd-zfs-partition-backup.sh | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/systemd-zfs-partition-backup.sh b/systemd-zfs-partition-backup.sh index e40c241..aa3951f 100755 --- a/systemd-zfs-partition-backup.sh +++ b/systemd-zfs-partition-backup.sh | |||
| @@ -1,16 +1,6 @@ | |||
| 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 | |||
| 11 | logger "Disk: $DISK_NAME" | ||
| 12 | logger " : $DISK_NAME_ESCAPED (escaped)" | ||
| 13 | |||
| 14 | function beep() { | 4 | function beep() { |
| 15 | test -f /usr/bin/beep &&\ | 5 | test -f /usr/bin/beep &&\ |
| 16 | env -u SUDO_GID -u SUDO_COMMAND -u SUDO_USER -u SUDO_UID /usr/bin/beep $@ | 6 | env -u SUDO_GID -u SUDO_COMMAND -u SUDO_USER -u SUDO_UID /usr/bin/beep $@ |
| @@ -34,9 +24,29 @@ function stop() { | |||
| 34 | } | 24 | } |
| 35 | 25 | ||
| 36 | 26 | ||
| 27 | |||
| 28 | # check for a configuration file and source it in if its there | ||
| 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 | |||
| 38 | DATASETS_WITH_DISKNAME=$(zfs list -H -o name | grep $DISK_NAME) | ||
| 39 | |||
| 40 | |||
| 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 | |||
| 37 | # iterate over all datasets | 46 | # iterate over all datasets |
| 38 | for i in $(zfs list -H -o name); | 47 | for i in ${DATASETS_WITH_DISKNAME[@]}; |
| 39 | do | 48 | do |
| 49 | logger "assertion: $(basename $i) == $DISK_NAME" | ||
| 40 | # compare the 'tail' of the PATH against the disk name... | 50 | # compare the 'tail' of the PATH against the disk name... |
| 41 | if [ "$(basename $i)" == "$DISK_NAME" ]; then | 51 | if [ "$(basename $i)" == "$DISK_NAME" ]; then |
| 42 | start $DISK_NAME | 52 | start $DISK_NAME |
