aboutsummaryrefslogtreecommitdiffstats
path: root/send-to-babar
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2017-10-11 23:36:34 -0400
committerBrian Cully <bjc@kublai.com>2017-10-12 00:01:17 -0400
commitb6e77390279ca0b5ae4953df8f651311420f6238 (patch)
tree95c91c179d3ca2b62fe5922213133cc740441d93 /send-to-babar
downloadzfs-scripts-b6e77390279ca0b5ae4953df8f651311420f6238.tar.gz
zfs-scripts-b6e77390279ca0b5ae4953df8f651311420f6238.zip
Initial commit.
Diffstat (limited to 'send-to-babar')
-rwxr-xr-xsend-to-babar37
1 files changed, 37 insertions, 0 deletions
diff --git a/send-to-babar b/send-to-babar
new file mode 100755
index 0000000..139e058
--- /dev/null
+++ b/send-to-babar
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+src=zhome/bjc
+dst=babar/bjc
+
+host=ditto.local
+
+first=`ssh $host zfs list -Hd1 -t snap -o name -s creation $dst | cut -d@ -f2 | tail -1`
+last=`zfs list -Hd1 -t snap -o name -s creation $src | cut -d@ -f2 | tail -1`
+
+if [ $first != $last ]; then
+ echo "Sending $src from $first to $last"
+ zfs send -I $src@$first $src@$last | ssh $host zfs recv $dst
+ if [ $? -ne 0 ]; then
+ echo "Couldn't send snapshot stream" 1>&2
+ exit 1
+ fi
+else
+ echo "Skipping snapshot replication: $host:$dst@$last already exists."
+fi
+
+echo "Verifying final snapshot is $dst@$last"
+verify=`ssh $host zfs list -Hd1 -t snap -o name $dst | grep $last`
+if [ x"$verify" == x ]; then
+ echo "Last snapshot not sent on $host:$dst" 1>&2
+ exit 2
+fi
+
+echo "Removing local snapshots up to $src@$last"
+for ds in `zfs list -Hd1 -t snap -o name -s creation $src | cut -d@ -f2`; do
+ if [ $ds == $last ]; then
+ break
+ fi
+ sudo zfs destroy $src@$ds
+done
+
+echo "Finished. Last snapshot sent: $src@$last"