From 8b4ffe3349e9254155561c1468014f74bdb50409 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Fri, 8 Jan 2021 14:57:35 +0100 Subject: [PATCH] zfs_snapshot_cron.sh: add custom prefix support --- zfs_snapshot_cron.sh | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/zfs_snapshot_cron.sh b/zfs_snapshot_cron.sh index ad7fa83..557dfaa 100755 --- a/zfs_snapshot_cron.sh +++ b/zfs_snapshot_cron.sh @@ -1,6 +1,5 @@ #!/bin/bash -PREFIX="zsc-" CONFIG_FILE="$HOME/.zfs_snapshot_cron" FORMAT='+%Y-%m-%d' @@ -16,7 +15,17 @@ handle_pool() { W=$3 M=$4 Y=$5 - echo "--- $POOL --- $D $W $M $Y" + + PREFIX=$6 + if test -z "$PREFIX"; then + PREFIX="zsc-" + fi + + if test "!no_prefix!" = "$PREFIX"; then + PREFIX="" + fi + + echo "--- $POOL --- $D $W $M $Y $PREFIX" SNAPSHOTS=($(zfs list -t snapshot -o name | grep "$POOL@$PREFIX" | sort -r)) echo "Snapshots: ${#SNAPSHOTS[@]}" @@ -30,7 +39,7 @@ handle_pool() { EXISTS=1 fi - scomp=($(split_date "$sdate") $(date -d "$sdate" "+%u %W")) + scomp=($(split_date "$sdate") $(date -d "$stripped_date" "+%u %W")) echo -n "${scomp[3]} ${scomp[4]} | " @@ -60,20 +69,20 @@ handle_pool() { fi } -cat "$CONFIG_FILE" | while IFS=: read pool recursive d w m y; do - echo "| ##### Pool: $pool Recursive: $recursive d: $d w: $w m: $m y: $y #####" +cat "$CONFIG_FILE" | while IFS=: read pool recursive d w m y prefix; do + echo "| ##### Pool: $pool Recursive: $recursive Prefix: $prefix d: $d w: $w m: $m y: $y #####" if [ $recursive = "true" ]; then SUBPOOLS=($(zfs list -o name | grep "$pool/")) echo -e "Subpools: ${SUBPOOLS[@]}" echo -e '|' for p in "${SUBPOOLS[@]}"; do - handle_pool $p $d $w $m $y | awk '{print "| " $0}' + handle_pool $p $d $w $m $y $prefix | awk '{print "| " $0}' echo -e '|' done fi - handle_pool $pool $d $w $m $y | awk '{print "| " $0}' + handle_pool $pool $d $w $m $y $prefix | awk '{print "| " $0}' echo -e "----------------------------------------------------------------------" done