}
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
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 <hostname> <zfs filesystem>"
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
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
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