From 028d60e078bc5fe362314a86c3436255e7020dd4 Mon Sep 17 00:00:00 2001 From: "Alan J. Pippin" Date: Thu, 15 Jan 2009 20:43:36 -0700 Subject: [PATCH] Added new destroy on full option --- zfs-replicate | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/zfs-replicate b/zfs-replicate index 57680fc..dc6dab2 100755 --- a/zfs-replicate +++ b/zfs-replicate @@ -12,6 +12,10 @@ local_pool=backups # Set the email address to send notification to mailto=alan@pippins.net +# When this variable is set, local filesystems will be destroyed +# before receiving a full streams into them from the remote source. +destroy_local_filesystem_on_full_replicate=0 + # The ssh connection doesn't find zfs without this. zfs=/usr/sbin/zfs @@ -94,9 +98,12 @@ if [ $? != 0 ]; then fi # List the snapshots on the local machine. +# Don't list the current backup marker if it exists on the local side. +# If you do, it can mess up the common finding algorithm below. local_list=$(mktemp /tmp/replicate.XXXXXX) $zfs list -H -t snapshot | grep ^${local_pool}/${remote_fs}@ | + grep -v ^${local_pool}/${current_backup_marker} | awk "{gsub(/^$local_pool./,\"\",\$1); print\$1}" > $local_list if [ $? != 0 ]; then echo "-E- local $zfs list command failed" @@ -176,9 +183,16 @@ else # Destroy the local filesystem if it exists before receving the full replicate zfs list ${local_pool}/${remote_fs} > /dev/null 2>&1 if [ $? == 0 ]; then - zfs destroy -r ${local_pool}/${remote_fs} - if [ $? != 0 ]; then - echo "-E- remote full $zfs destroy command failed" + if [[ $destroy_local_filesystem_on_full_replicate == 1 ]]; then + $zfs destroy -r ${local_pool}/${remote_fs} + if [ $? != 0 ]; then + echo "-E- remote full $zfs destroy command failed" + exit 1 + fi + else + echo "-W- We need to destroy a local filesystem before receiving a full stream." + echo " However, since the option is set to prevent this, skipping replicate operation." + echo "$zfs destroy -r ${local_pool}/${remote_fs} not able to run" | /usr/bin/mailx -s "zfs-replicate-all unable to destroy local filesystem" $mailto exit 1 fi fi -- 2.34.1