Skip to content

Commit 6e89625

Browse files
committed
Implement multiple receive hosts for the snapshot replication.
1 parent 8cfeb12 commit 6e89625

File tree

2 files changed

+36
-25
lines changed

2 files changed

+36
-25
lines changed

src/zfs-auto-snapshot.8

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ PRE is 'zfs\-auto\-snap' by default.
4949
\fB\-q\fR, \fB\-\-quiet\fR
5050
Suppress warnings and notices at the console.
5151
.TP
52-
\fB\-\-send\-full\fR=[\fIremote host\fR]:[\fIremote pool\fR]
52+
\fB\-\-send\-full\fR=[\fIremote host\fR]:[\fIremote pool\fR][;...]
5353
Send zfs full backup to remote hostname (or IP address) and put it in remote pool.
5454
.TP
55-
\fB\-\-send\-incr\fR=[\fIremote host\fR]:[\fIremote pool\fR]
55+
\fB\-\-send\-incr\fR=[\fIremote host\fR]:[\fIremote pool\fR][;...]
5656
Send zfs incremental backup to remote hostname (or IP address) and put it in remote pool.
5757
.TP
5858
\fB\-\-send\-fallback\fR

src/zfs-auto-snapshot.sh

+34-23
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ opt_label=''
3636
opt_prefix='zfs-auto-snap'
3737
opt_recursive=''
3838
opt_send_type=''
39-
opt_send_host=''
40-
opt_recv_pool=''
39+
opt_send=''
4140
opt_send_opts=''
4241
opt_recv_opts=''
4342
opt_send_ssh_opts=''
@@ -229,7 +228,7 @@ do_snapshots () # properties, flags, snapname, oldglob, [targets...]
229228
if [ $RUNSNAP -eq 1 ] && do_run "zfs snapshot $PROPS $FLAGS '$ii@$NAME'"
230229
then
231230
[ "$opt_post_snapshot" != "" ] && do_run "$opt_post_snapshot $ii $NAME"
232-
[ -n "$opt_send_host" ] && SNAPS_DONE="$SNAPS_DONE
231+
[ -n "$opt_send" ] && SNAPS_DONE="$SNAPS_DONE
233232
$ii@$NAME"
234233
SNAPSHOT_COUNT=$(( $SNAPSHOT_COUNT + 1 ))
235234
else
@@ -269,13 +268,13 @@ do_send () # snapname, oldglob
269268
local NAME="$1"
270269
local GLOB="$2"
271270
local RUNSEND=1
272-
local remote
271+
local remote_ssh="ssh $opt_send_ssh_opts"
272+
local remote_recv="zfs receive $opt_recv_opts"
273+
local remote_mbuf=""
273274
local ii
274275
local jj
275276

276-
[ -n "$opt_send_mbuf_opts" ] && remote="mbuffer $opt_send_mbuf_opts |"
277-
remote="$remote ssh $opt_send_ssh_opts $opt_send_host"
278-
remote="$remote zfs receive $opt_recv_opts"
277+
[ -n "$opt_send_mbuf_opts" ] && remote_mbuf="mbuffer $opt_send_mbuf_opts |"
279278

280279
# STEP 1: Go throug all snapshots we've created
281280
for ii in $SNAPS_DONE
@@ -350,17 +349,34 @@ $jj"
350349
fi
351350

352351
if [ $RUNSEND -eq 1 ]; then
353-
if [ "$opt_send_type" = "incr" ]; then
354-
if [ "$jj" = "$ii" -a -n "$opt_send_fallback" ]; then
355-
do_run "zfs send $opt_send_opts -R $ii | $remote -F $opt_recv_pool" \
356-
|| RUNSEND=0
352+
OLD_IFS=$IFS ; IFS=";"
353+
354+
# Go through each option to --send-{incr,full}.
355+
# rem=<remote_host>:<remote_pool>
356+
for rem in $opt_send; do
357+
if [ "$opt_send_type" = "incr" ]; then
358+
if [ "$jj" = "$ii" -a -n "$opt_send_fallback" ]; then
359+
cmd="zfs send $opt_send_opts -R $ii |"
360+
cmd="$cmd $remote_mbuf"
361+
cmd="$cmd $remote_ssh ${rem%:*}"
362+
cmd="$cmd $remote_recv -F ${rem#*:}"
363+
else
364+
cmd="zfs send $opt_send_opts -i $jj $ii |"
365+
cmd="$cmd $remote_mbuf"
366+
cmd="$cmd $remote_ssh ${rem%:*}"
367+
cmd="$cmd $remote_recv ${rem#*:}"
368+
fi
357369
else
358-
do_run "zfs send $opt_send_opts -i $jj $ii | $remote $opt_recv_pool" \
359-
|| RUNSEND=0
370+
cmd="zfs send $opt_send_opts -R $jj |"
371+
cmd="$cmd $remote_mbuf"
372+
cmd="$cmd $remote_ssh ${rem%:*}"
373+
cmd="$cmd $remote_recv ${rem#*:}"
360374
fi
361-
else
362-
do_run "zfs send $opt_send_opts -R $jj | $remote $opt_recv_pool" || RUNSEND=0
363-
fi
375+
376+
do_run "$cmd" || RUNSEND=0
377+
done
378+
379+
IFS=$OLD_IFS
364380

365381
if [ $RUNSEND = 1 -a -n "$opt_post_send" ]; then
366382
do_run "$opt_post_send $jj" || RUNSEND=0
@@ -471,18 +487,13 @@ do
471487
;;
472488
(--send-full)
473489
opt_send_type='full'
474-
475-
opt_send_host=$(echo "$2" | sed 's,:.*,,')
476-
opt_recv_pool=$(echo "$2" | sed 's,.*:,,')
477-
478490
opt_send_opts="$opt_send_opts -R"
491+
opt_send="$2"
479492
shift 2
480493
;;
481494
(--send-incr)
482495
opt_send_type='incr'
483-
484-
opt_send_host=$(echo "$2" | sed 's,:.*,,')
485-
opt_recv_pool=$(echo "$2" | sed 's,.*:,,')
496+
opt_send="$2"
486497
shift 2
487498
;;
488499
(--send-fallback)

0 commit comments

Comments
 (0)