5 # Usage: replicate <hostname> <zfs filesystem>
9 # change to match the name of the local backup pool
12 # The ssh connection doesn't find zfs without this.
15 # List the snapshots on the remote machine.
16 remote_list=$(mktemp /tmp/replicate.XXXXXX)
18 $zfs list -H -t snapshot |
20 awk '{print$1}' > $remote_list
22 # List the snapshots on the local machine.
23 local_list=$(mktemp /tmp/replicate.XXXXXX)
24 $zfs list -H -t snapshot |
25 grep ^${local_pool}/${remote_fs}@ |
26 awk '{gsub(/^${local_pool}./,"",$1); print$1}' > $local_list
28 # See what the most recent snapshot on the remote end is.
29 latest=$(tail -n 1 $remote_list)
31 # I did this to make sure that diff would always display the most recent common
32 echo bogus.remote >> $remote_list
33 echo bogus.local >> $local_list
34 common=$(diff -u $remote_list $local_list | grep '^ ' | tail -n 1)
36 ssh $remote $zfs send -R -I${common/*@/@} $latest |
37 $zfs receive -vF -d ${local_pool}/${remote_fs%/*}
39 rm -f $local_list $remote_list