# Set the email address to send notification to
mailto=alan@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
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"
# 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