dst_fs=$4
dst_hostname=$5
+# return non-zero exit code if any command in the pipe fails
+set -o pipefail
+
if [[ -z "$SCRIPT_UNDER_TEST" ]]; then
exec >> $logdir/zfs-restore.log 2>&1
fi
date=`date`
echo "$date ZFS restore started: $src_pool/$src_fs -> $dst_hostname:$dst_pool/$dst_fs"
+# check for localhost
+if [[ $dst_hostname = "localhost" ]]; then
+ dst_hostname=""
+ ssh=""
+fi
+
# Make sure the src pool and src filesystem exist, or print some errors
zpool list -H "$src_pool" >/dev/null 2>&1
if [ $? != 0 ]; then
src_pool_guid=`zpool get guid $src_pool 2>&1 | grep $src_pool | awk '{ print $3 }'`
zpool get guid $src_pool > /dev/null 2>&1
if [ $? != 0 ]; then
- fatal_and_exit "-E- Unable to extract the guid for the src pool: $src_pool" $mailto
+ fatal_and_exit "-E- Unable to extract the guid for the src pool on $hostname: $src_pool" $mailto
fi
# Setup our backup marker names
fi
# Check to make sure the dst pool exists
-ssh $dst_hostname "$zfs list ${dst_pool}" > /dev/null 2>&1
+$ssh $dst_hostname $zfs list ${dst_pool} > /dev/null 2>&1
if [ $? != 0 ]; then
fatal_and_exit "-E- The destination pool '$dst_pool' does not exist. Create the pool '$dst_pool' and try again."
fi
# Check to make sure the dst filesystem does not exist
-ssh $dst_hostname "$zfs list ${dst_pool}/${dst_fs}" > /dev/null 2>&1
+$ssh $dst_hostname $zfs list ${dst_pool}/${dst_fs} > /dev/null 2>&1
if [ $? == 0 ]; then
fatal_and_exit "-E- The destination pool/filesystem '$dst_pool/$dst_fs' already exists. Destroy the filesystem '$dst_fs' and try again."
fi
# Now send the src filesystem
if [[ -n "$SCRIPT_UNDER_TEST" ]]; then
- echo "$zfs send -R $src_pool/$last_backup_marker | ssh $dst_hostname $zfs recv -dv $dst_pool"
+ echo "$zfs send -Rc $src_pool/$last_backup_marker | $ssh $dst_hostname $zfs recv -dv $dst_pool"
else
- $zfs send -R "$src_pool/$last_backup_marker" | ssh $dst_hostname "$zfs recv -dv $dst_pool"
+ if [[ $throttle_enable == 1 && -e $throttle ]]; then
+ $zfs send -Rc "$src_pool/$last_backup_marker" | $throttle $throttle_opt | $ssh $dst_hostname $zfs recv -dv $dst_pool
+ else
+ $zfs send -Rc "$src_pool/$last_backup_marker" | $ssh $dst_hostname $zfs recv -dv $dst_pool
+ fi
fi
# Now rename the dst filesystem (move it into place)
if [[ -n "$SCRIPT_UNDER_TEST" ]]; then
- echo "$dst_hostname $zfs rename $dst_pool/$src_fs $dst_pool/$dst_fs"
+ echo "$ssh $dst_hostname $zfs rename $dst_pool/$src_fs $dst_pool/$dst_fs"
else
- ssh $dst_hostname "$zfs rename $dst_pool/$src_fs $dst_pool/$dst_fs"
+ $ssh $dst_hostname $zfs rename $dst_pool/$src_fs $dst_pool/$dst_fs
fi
# All done!