From 31d1843e889423944c95ff57ad3fbeddaae28b0a Mon Sep 17 00:00:00 2001 From: "thorsten.spille" Date: Thu, 12 Oct 2023 20:05:50 +0200 Subject: [PATCH] Fix backup storage creation --- bashclub-zsync/usr/bin/bashclub-zsync | 29 +++++++++++++++++---------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/bashclub-zsync/usr/bin/bashclub-zsync b/bashclub-zsync/usr/bin/bashclub-zsync index a61fccd..69e3b0f 100644 --- a/bashclub-zsync/usr/bin/bashclub-zsync +++ b/bashclub-zsync/usr/bin/bashclub-zsync @@ -130,6 +130,16 @@ done log "$include_list" log "$exclude_list" +if ! $zfs list $target > /dev/null 2>&1 ; then + log "[DEBUG] $target does not exist. Creating..." + $zfs create -o com.sun:auto-snapshot=false $target +else + log "[DEBUG] $target exists, check auto-snapshot..." + if [[ $($zfs get -H -o value,source com.sun:auto-snapshot $target) != "false local" ]]; then + $zfs set com.sun:auto-snapshot=false $target + fi +fi + for name in "${syncvols[@]}"; do log "Replicate $name" @@ -143,23 +153,14 @@ for name in "${syncvols[@]}"; do if [[ $($ssh $sshcipher $sshport $source "zfs list -H -t snapshot -o name -S creation $name 2>/dev/null | grep -E \"$snapshot_filter\" | wc -l | tr -d ' '") -gt 0 ]]; then IFS=$' ' - if [ $($zfs list -H $target/$name > /dev/null 2>&1 ; echo $?) -gt 0 ]; then + if ! $zfs list -H $target/$name > /dev/null 2>&1 ; then if [[ $debug == "-v" ]]; then log "[DEBUG] $target/$name does not exist"; fi prefix="" for part in $(echo $target/$(echo $name | cut -d'/' -f1) | sed "s/\// /g"); do if [ $($zfs list $prefix$part > /dev/null 2>&1 ; echo $?) -gt 0 ]; then if [[ $debug == "-v" ]]; then log "[DEBUG] $prefix$part does not exist"; fi log "Creating $prefix$part" - if [[ $prefix/$part == $target ]]; then - if [[ $debug == "-v" ]]; then log "[DEBUG] Disabling com.sun:auto-snapshot on $prefix$part"; fi - autosnap=-ocom.sun:auto-snapshot=false - fi $zfs create $autosnap -p $prefix$part - else - if [[ $prefix/$part == $target ]] && [[ $(zfs get -H -o value,source com.sun:auto-snapshot $prefix/$part) != "false local" ]]; then - if [[ $debug == "-v" ]]; then log "[DEBUG] Disabling com.sun:auto-snapshot on $prefix$part"; fi - $zfs set com.sun:auto-snapshot=false $prefix/$part - fi fi prefix="$prefix$part/" done @@ -170,6 +171,12 @@ for name in "${syncvols[@]}"; do log "Start initial replication: $snap => $target/$(echo $name | cut -d'/' -f1)" $ssh $ssh_ipher $sshport $source "zfs send -w -p $debug $snap" | $zfs receive $mp $cm -x $tag -x com.sun:auto-snapshot $debug -dF $target/$(echo $name | cut -d'/' -f1) done + else + log "[DEBUG] $target already exists, check if com.sun:auto-snapshot is disabled" + if [[ $($zfs get -H -o value,source com.sun:auto-snapshot $target) != "false local" ]]; then + log "[DEBUG] com.sun:auto-snapshot is enabled on $target - disabling..." + $zfs set com.sun:auto-snapshot=false $target + fi fi if [[ $debug == "-v" ]]; then log "[DEBUG] $name - Start incremental replication"; fi @@ -207,4 +214,4 @@ for name in "${syncvols[@]}"; do else if [[ $debug == "-v" ]]; then log "[DEBUG] $name - No snapshots found with filter $snapshot_filter"; fi fi -done \ No newline at end of file +done