From 06a1b7aec736eaf1790a169eedaf659b4f5147aa Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Sun, 7 Mar 2021 15:59:22 +0100 Subject: [PATCH] zsc.sh: allow disabling snapshot creation --- zsc.sh | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/zsc.sh b/zsc.sh index 2eece61..2d893ac 100755 --- a/zsc.sh +++ b/zsc.sh @@ -22,12 +22,13 @@ split_date() { handle_dataset() { DATASET=$1 - D=$2 - W=$3 - M=$4 - Y=$5 + AUTO_CREATE=$2 + D=$3 + W=$4 + M=$5 + Y=$6 - PREFIX=$6 + PREFIX=$7 if test -z "$PREFIX"; then PREFIX="zsc-" fi @@ -75,25 +76,29 @@ handle_dataset() { done if [ $EXISTS -eq 0 ]; then - echo -e "Creating snapshot $DATASET@$PREFIX$DATE" - zfs snapshot $DATASET@$PREFIX$DATE + if [ $AUTO_CREATE == "true" ]; then + echo -e "Creating snapshot $DATASET@$PREFIX$DATE" + zfs snapshot $DATASET@$PREFIX$DATE + else + echo -e "Skip snapshot creation" + fi fi } -cat "$CONFIG_FILE" | while IFS=: read dataset recursive d w m y prefix; do - echo "| ##### Dataset: $dataset Recursive: $recursive Prefix: $prefix d: $d w: $w m: $m y: $y #####" +cat "$CONFIG_FILE" | while IFS=: read dataset recursive auto_create d w m y prefix; do + echo "| ##### Dataset: $dataset Recursive: $recursive Auto create: $auto_create Prefix: $prefix d: $d w: $w m: $m y: $y #####" if [ $recursive = "true" ]; then SUBDATASETS=($(zfs list -o name | grep "$dataset/")) echo -e "| Subdatasets: ${SUBDATASETS[@]}" echo -e '|' for p in "${SUBDATASETS[@]}"; do - handle_dataset $p $d $w $m $y $prefix | awk '{print "| " $0}' + handle_dataset $p $auto_create $d $w $m $y $prefix | awk '{print "| " $0}' echo -e '|' done fi - handle_dataset $dataset $d $w $m $y $prefix | awk '{print "| " $0}' + handle_dataset $dataset $auto_create $d $w $m $y $prefix | awk '{print "| " $0}' echo -e "----------------------------------------------------------------------" done