X-Git-Url: http://git.pippins.net/embedvideo/.git/static/git-logo.png?a=blobdiff_plain;f=zfs-replicate;h=09cb3babb7600f0526a14b4b2c2f945f41660ea4;hb=984d48e66a916fd9ba533ae19b43aafd449dad77;hp=57680fc637c4910e887c69d40c85279de229c07c;hpb=64e85d923d59ee7b95cb123f12bfa3750f42dc0f;p=zfs-ubuntu%2F.git diff --git a/zfs-replicate b/zfs-replicate index 57680fc..09cb3ba 100755 --- a/zfs-replicate +++ b/zfs-replicate @@ -10,11 +10,23 @@ remote_lockdir="/tmp/zfs-admin-lock" local_pool=backups # Set the email address to send notification to -mailto=alan@pippins.net +mailto=root@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 +# Setup our cleanup and exit trap +cleanup() { + ssh $remote rm -rf "$remote_lockdir" + exit +} +trap cleanup INT +trap cleanup EXIT + # Make sure we have valid arguments if [[ -z "$remote" ]] || [[ -z "$remote_fs" ]]; then echo "Usage: $0 " @@ -74,10 +86,6 @@ while true; do fi done -# Declare a cleanup() method to remove the remote lockdir -cleanup() { ssh $remote rm -rf "$remote_lockdir"; } -trap cleanup EXIT - # Setup our backup marker names current_backup_marker=${remote_fs}@current-backup-${local_pool_guid} previous_backup_marker=${remote_fs}@previous-backup-${local_pool_guid} @@ -94,9 +102,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 +187,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