-#/bin/bash
+#!/bin/bash
# Author: Carl Baldwin & Alan Pippin
# Description: This script replicates a remote zfs filesystem to a local zfs pool.
# Create the remote lockdir before continuing with the replicate
# Spinlock on creating the lock
maxsleeptime=60
-maxattempts=100
+maxattempts=500
attempts=0
while true; do
ssh $remote mkdir "$lockdir" >/dev/null 2>&1
fatal_and_exit "-E- remote incremental $zfs rollback command failed" $mailto
fi
# Now it should be safe to send the snaps
- ssh $remote $zfs send -R -I${previous_backup_marker} ${current_backup_marker} |
- $zfs receive -vF -d ${local_pool}/${remote_pool}
+ 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 ${local_pool}/${remote_pool}
+ else
+ ssh $remote $zfs send -R -I${previous_backup_marker} ${current_backup_marker} |
+ $zfs receive -vF -d ${local_pool}/${remote_pool}
+ fi
if [ $? != 0 ]; then
fatal_and_exit "-E- remote incremental $zfs send command failed" $mailto
fi
if [[ -n "$common" ]]; then
# We found a common snapshot, incrementally send the new snaps
- ssh $remote $zfs send -R -I${common/*@/@} ${current_backup_marker} |
- $zfs receive -vF -d ${local_pool}/${remote_pool}
+ if [[ $throttle_enable == 1 && -e $throttle ]]; then
+ ssh $remote $zfs send -R -I${common/*@/@} ${current_backup_marker} |
+ $throttle $throttle_opt | $zfs receive -vF -d ${local_pool}/${remote_pool}
+ else
+ ssh $remote $zfs send -R -I${common/*@/@} ${current_backup_marker} |
+ $zfs receive -vF -d ${local_pool}/${remote_pool}
+ fi
if [ $? != 0 ]; then
fatal_and_exit "-E- remote incremental $zfs send command failed" $mailto
fi
fi
fi
# Send the full filesystem
- ssh $remote $zfs send -R ${current_backup_marker} |
- $zfs receive -vF -d ${local_pool}/${remote_pool}
+ if [[ $throttle_enable == 1 && -e $throttle ]]; then
+ ssh $remote $zfs send -R ${current_backup_marker} |
+ $throttle $throttle_opt | $zfs receive -vF -d ${local_pool}/${remote_pool}
+ else
+ ssh $remote $zfs send -R ${current_backup_marker} |
+ $zfs receive -vF -d ${local_pool}/${remote_pool}
+ fi
if [ $? != 0 ]; then
fatal_and_exit "-E- remote full $zfs send command failed" $mailto
fi