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