zsc.sh: allow disabling snapshot creation

This commit is contained in:
Alice Gaudon 2021-03-07 15:59:22 +01:00
parent 1bca577ede
commit 06a1b7aec7

23
zsc.sh
View File

@ -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
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