Skip to content

Allow reconciliation if single dataset is missing snapshots #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
41 changes: 41 additions & 0 deletions zfs-replicate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,47 @@ snapCreate() {
## get source and destination snapshots
srcSnaps=$(snapList "$src" "$srcHost" 1)
dstSnaps=$(snapList "$dst" "$dstHost" 0)
## we need to list all src snapshots for next step
srcSnapsAll=$(snapList "$src" "$srcHost" 0)
## check that all datasets have matching snapshots
## reset fail variable
snapCheckFail=0
## loop and check that snapshots match recursively on src and dst
for ssnap in $srcSnapsAll; do
## reset snapMatch variable
snapMatch=0
for dsnap in $dstSnaps; do
## trim first part of dst snap name
dsnap=$(printf "%s\n" "$dsnap" | cut -f2- -d/)
## loop through and try to find a match
if [ "$dsnap" != "$ssnap" ]; then
continue
## if found, set snapMatch var
elif [ "$dsnap" = "$ssnap" ]; then
snapMatch=1
break
fi
done
## if no matching snapshots found, destroy
## if ALLOW_RECONCILIATION=1, otherwise skip set
if [ "$snapMatch" -eq 1 ]; then
continue
elif [ "$snapMatch" -eq 0 ] && [ "${ALLOW_RECONCILIATION}" -eq 1 ]; then
snapDestroy "$ssnap" "$srcHost"
continue
else
snapCheckFail=1
continue
fi
done
## skip set if no matching snapshots are found for all datasets
if [ "$snapCheckFail" -eq 1 ]; then
temps=$(printf "source snapshot '%s' not in destination dataset: %s" "$ssnap" "$dst")
temps=$(printf "%s - set 'ALLOW_RECONCILIATION=1' to override" "$temps")
printf "WARNING: skipping replication set '%s' - %s\n" "$pair" "$temps" 1>&2
__SKIP_COUNT=$((__SKIP_COUNT + 1))
continue
fi
for snap in $srcSnaps; do
## while we are here...check for our current snap name
if [ "$snap" = "${src}@${name}" ]; then
Expand Down
Loading