From: Alan J. Pippin Date: Wed, 19 Mar 2014 16:47:25 +0000 (-0600) Subject: Consolidated zfs send and recv operations into replicate function X-Git-Url: http://git.pippins.net/embedvideo/.git/%7Bdelete%7D?a=commitdiff_plain;h=82203a84c03675d42694a0ce3e63e814094e6464;p=zfs-ubuntu%2F.git Consolidated zfs send and recv operations into replicate function Fixed bug in fatal_and_exit removing previous backup marker, when it should have just been removing the current backup markers. --- diff --git a/zfs-replicate b/zfs-replicate index 1455061..9f72b06 100755 --- a/zfs-replicate +++ b/zfs-replicate @@ -33,17 +33,17 @@ cleanup() { } fatal_and_exit() { echo -e 2>&1 "$1" - # Destroy the backup markers on the local filesystem if they exist + # Destroy the current backup markers from the local backup_pool and remote_pool if they exist if [[ -n "$current_backup_marker" ]]; then - zfs list -t snapshot ${backup_pool}/${current_backup_marker} > /dev/null 2>&1 + # Local backup pool current backup marker + $zfs list -t snapshot ${backup_pool}/${current_backup_marker} > /dev/null 2>&1 if [ $? == 0 ]; then $zfs destroy ${backup_pool}/${current_backup_marker} fi - fi - if [[ -n "$previous_backup_marker" ]]; then - zfs list -t snapshot ${backup_pool}/${previous_backup_marker} > /dev/null 2>&1 + # Remote pool current backup marker + $ssh $remote zfs list -t snapshot ${current_backup_marker} > /dev/null 2>&1 if [ $? == 0 ]; then - $zfs destroy ${backup_pool}/${previous_backup_marker} + $ssh $remote $zfs destroy ${current_backup_marker} fi fi # send email notification @@ -56,6 +56,27 @@ fatal_and_exit() { trap fatal_and_exit INT trap cleanup EXIT +# Declare a function to handle the replicate operation +replicate() { + zfs_send="$1" + zfs_recv="$zfs receive -vF -d ${backup_pool}/${remote_pool}" + glue="$throttle $throttle_opt" + if [[ $throttle_enable == 1 && -e $throttle ]]; then + # handle using the glue in the local and remote host case properly + if [[ -z "$ssh" ]]; then + # local host glue case + $zfs_send | $glue | $zfs_recv + else + # remote host glue case + $ssh $remote "$zfs_send | $glue" | $zfs_recv + fi + else + # no glue case - works for both the local and remote host cases + $ssh $remote $zfs_send | $zfs_recv + fi + # The return code of the zfs_send | zfs_recv operation will be returned to the caller +} + # Make sure we have valid arguments if [[ -z "$remote" ]] || [[ -z "$remote_fs" ]]; then fatal_and_exit "Usage: $0 " @@ -180,13 +201,7 @@ if [ $no_markers == 0 ]; then fatal_and_exit "-E- remote incremental $zfs rollback command failed on $hostname" $mailto fi # Now it should be safe to send the snaps - if [[ $throttle_enable == 1 && -e $throttle ]]; then - $ssh $remote "$zfs send -R -I${previous_backup_marker} ${current_backup_marker} | - $throttle $throttle_opt" | $zfs receive -vF -d ${backup_pool}/${remote_pool} - else - $ssh $remote $zfs send -R -I${previous_backup_marker} ${current_backup_marker} | - $zfs receive -vF -d ${backup_pool}/${remote_pool} - fi + replicate "$zfs send -R -I${previous_backup_marker} ${current_backup_marker}" if [ $? != 0 ]; then fatal_and_exit "-E- remote incremental $zfs send command failed on $hostname" $mailto fi @@ -205,13 +220,7 @@ else if [[ -n "$common" ]]; then # We found a common snapshot, incrementally send the new snaps - if [[ $throttle_enable == 1 && -e $throttle ]]; then - $ssh $remote "$zfs send -R -I${common/*@/@} ${current_backup_marker} | - $throttle $throttle_opt" | $zfs receive -vF -d ${backup_pool}/${remote_pool} - else - $ssh $remote $zfs send -R -I${common/*@/@} ${current_backup_marker} | - $zfs receive -vF -d ${backup_pool}/${remote_pool} - fi + replicate "$zfs send -R -I${common/*@/@} ${current_backup_marker}" if [ $? != 0 ]; then fatal_and_exit "-E- remote incremental $zfs send command failed on $hostname" $mailto fi @@ -233,13 +242,7 @@ else fi fi # Send the full filesystem - if [[ $throttle_enable == 1 && -e $throttle ]]; then - $ssh $remote "$zfs send -R ${current_backup_marker} | - $throttle $throttle_opt" | $zfs receive -vF -d ${backup_pool}/${remote_pool} - else - $ssh $remote $zfs send -R ${current_backup_marker} | - $zfs receive -vF -d ${backup_pool}/${remote_pool} - fi + replicate "$zfs send -R ${current_backup_marker}" if [ $? != 0 ]; then fatal_and_exit "-E- remote full $zfs send command failed on $hostname" $mailto fi