aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMirek Kratochvil <exa.exa@gmail.com>2014-05-30 17:20:01 +0200
committerMirek Kratochvil <exa.exa@gmail.com>2014-05-30 17:20:01 +0200
commit05f6cae8f841785ba60010dfa8b398e037fb0876 (patch)
tree9e29acb29c8f6d100273925b821cc40df9d6d68a
parentb0e495a4e8c701af87edee9e208fd4184daacae0 (diff)
downloadzfs-backup-05f6cae8f841785ba60010dfa8b398e037fb0876.tar.gz
zfs-backup-05f6cae8f841785ba60010dfa8b398e037fb0876.tar.bz2
pulling
-rwxr-xr-xzb-cleanup13
-rwxr-xr-xzb-pull57
2 files changed, 67 insertions, 3 deletions
diff --git a/zb-cleanup b/zb-cleanup
index 825de43..e193fbf 100755
--- a/zb-cleanup
+++ b/zb-cleanup
@@ -6,16 +6,21 @@ if [[ -z "$1" || -z "$2" ]] ; then
fi
timestamp () {
- t="`echo \"$1\" |sed -e 's/^.*@zb-//' |tr 'p_' '+ '`"
+ t="`echo \"$1\" |sed -ne 's/^.*@zb-//p' |tr 'p_' '+ '`"
+ [[ -z "$t" ]] && return 1
date --date="$t" +%s
+ return $?
}
density="$2"
timenow=`date +%s`
lasttime=0
+# list snapshots
zfs list -t snapshot -r -d 1 -H "$1" |awk '{print $1;}' | while read l ; do
- echo `timestamp "$l"` "$l"
+ #link unix timestamps
+ unixtime=`timestamp "$l"` || continue
+ echo "$unixtime" "$l"
done |sort -n | while read l ; do
curtime=${l%% *}
snapname=${l#* }
@@ -24,7 +29,9 @@ done |sort -n | while read l ; do
break
fi
- if [ $(( $density*($curtime-$lasttime)/($timenow-$lasttime) )) -lt 1] ; then
+ #if it's too dense, delete the closer snapshot
+ if [ $(( $density*($curtime-$lasttime)/($timenow-$lasttime) )) -lt 1]
+ then
zfs destroy "$snapname"
else
lasttime="$curtime"
diff --git a/zb-pull b/zb-pull
index 13f4793..af8f9cd 100755
--- a/zb-pull
+++ b/zb-pull
@@ -1,2 +1,59 @@
#!/bin/sh
+if [[ -z "$1" || -z "$2" || -z "$3" ]] ; then
+ echo "usage: $0 <ssh_remote> <remote_zfs_object> <local_zfs_object>" >&2
+ exit 1
+fi
+
+timestamp () {
+ t="`echo \"$1\" |sed -ne 's/^.*@zb-//p' |tr 'p_' '+ '`"
+ [[ -z "$t" ]] && return 1
+ date --date="$t" +%s
+ return $?
+}
+
+
+ssh_remote="$1"
+remote_zfs="$2"
+local_zfs="$3"
+
+# find newest available and newest common snapshot
+newest="N/A"
+newest_common="N/A"
+
+ssh $ssh_remote "zfs list -t snapshot -r -d 1 -H \"${remote_zfs}\" " | while read l ; do
+ #link unix timestamps
+ unixtime=`timestamp "$l"` || continue
+ echo "$unixtime" "$l"
+done | sort -n | while read l ; do
+ curtime=${l%% *}
+ snapname=${l#* }
+
+ newest="$snapname"
+
+ if zfs list -t snapshot -H "${local_zfs}@zb-${snapname}" >/dev/null ; then
+ newest_common="$snapname"
+ fi
+done
+
+# some checks
+
+if [ "$newest" = "N/A" ] ; then
+ echo "$0: no remote snapshots available to pull" >&2
+ exit 2
+fi
+
+if [ "$newest" = "$newest_common" ] ; then
+ echo "$0: nothing new to pull" >&2
+ exit 0
+fi
+
+if [ "$newest_common" = "N/A" ] ; then
+ #do a full send
+ ssh $ssh_remote "zfs send \"${remote_zfs}@zb-${newest}\"" | zfs recv -F "${local_zfs}"
+ exit $?
+else
+ #do incremental send
+ ssh $ssh_remote "zfs send -I \"${remote_zfs}@zb-${newest_common}\" \"${remote_zfs}@zb-${$newest}\"" | zfs recv -F "${local_zfs}"
+ exit $?
+fi