Skip to content

Commit 1468d67

Browse files
committed
Implement multiple receive hosts for the snapshot replication.
1 parent d063d3b commit 1468d67

File tree

2 files changed

+36
-25
lines changed

2 files changed

+36
-25
lines changed

src/zfs-auto-snapshot.8

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

src/zfs-auto-snapshot.sh

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ opt_label=''
3535
opt_prefix='zfs-auto-snap'
3636
opt_recursive=''
3737
opt_send_type=''
38-
opt_send_host=''
39-
opt_recv_pool=''
38+
opt_send=''
4039
opt_send_opts=''
4140
opt_recv_opts=''
4241
opt_send_ssh_opts=''
@@ -188,7 +187,7 @@ do_snapshots () # properties, flags, snapname, oldglob, [targets...]
188187
if [ $RUNSNAP -eq 1 ] && do_run "zfs snapshot $PROPS $FLAGS '$ii@$NAME'"
189188
then
190189
[ "$opt_post_snapshot" != "" ] && do_run "$opt_post_snapshot $ii $NAME"
191-
[ -n "$opt_send_host" ] && SNAPS_DONE="$SNAPS_DONE
190+
[ -n "$opt_send" ] && SNAPS_DONE="$SNAPS_DONE
192191
$ii@$NAME"
193192
SNAPSHOT_COUNT=$(( $SNAPSHOT_COUNT + 1 ))
194193
else
@@ -228,13 +227,13 @@ do_send () # snapname, oldglob
228227
local NAME="$1"
229228
local GLOB="$2"
230229
local RUNSEND=1
231-
local remote
230+
local remote_ssh="ssh $opt_send_ssh_opts"
231+
local remote_recv="zfs receive $opt_recv_opts"
232+
local remote_mbuf=""
232233
local ii
233234
local jj
234235

235-
[ -n "$opt_send_mbuf_opts" ] && remote="mbuffer $opt_send_mbuf_opts |"
236-
remote="$remote ssh $opt_send_ssh_opts $opt_send_host"
237-
remote="$remote zfs receive $opt_recv_opts"
236+
[ -n "$opt_send_mbuf_opts" ] && remote_mbuf="mbuffer $opt_send_mbuf_opts |"
238237

239238
# STEP 1: Go throug all snapshots we've created
240239
for ii in $SNAPS_DONE
@@ -309,17 +308,34 @@ $jj"
309308
fi
310309

311310
if [ $RUNSEND -eq 1 ]; then
312-
if [ "$opt_send_type" = "incr" ]; then
313-
if [ "$jj" = "$ii" -a -n "$opt_send_fallback" ]; then
314-
do_run "zfs send $opt_send_opts -R $ii | $remote -F $opt_recv_pool" \
315-
|| RUNSEND=0
311+
OLD_IFS=$IFS ; IFS=";"
312+
313+
# Go through each option to --send-{incr,full}.
314+
# rem=<remote_host>:<remote_pool>
315+
for rem in $opt_send; do
316+
if [ "$opt_send_type" = "incr" ]; then
317+
if [ "$jj" = "$ii" -a -n "$opt_send_fallback" ]; then
318+
cmd="zfs send $opt_send_opts -R $ii |"
319+
cmd="$cmd $remote_mbuf"
320+
cmd="$cmd $remote_ssh ${rem%:*}"
321+
cmd="$cmd $remote_recv -F ${rem#*:}"
322+
else
323+
cmd="zfs send $opt_send_opts -i $jj $ii |"
324+
cmd="$cmd $remote_mbuf"
325+
cmd="$cmd $remote_ssh ${rem%:*}"
326+
cmd="$cmd $remote_recv ${rem#*:}"
327+
fi
316328
else
317-
do_run "zfs send $opt_send_opts -i $jj $ii | $remote $opt_recv_pool" \
318-
|| RUNSEND=0
329+
cmd="zfs send $opt_send_opts -R $jj |"
330+
cmd="$cmd $remote_mbuf"
331+
cmd="$cmd $remote_ssh ${rem%:*}"
332+
cmd="$cmd $remote_recv ${rem#*:}"
319333
fi
320-
else
321-
do_run "zfs send $opt_send_opts -R $jj | $remote $opt_recv_pool" || RUNSEND=0
322-
fi
334+
335+
do_run "$cmd" || RUNSEND=0
336+
done
337+
338+
IFS=$OLD_IFS
323339

324340
if [ $RUNSEND = 1 -a -n "$opt_post_send" ]; then
325341
do_run "$opt_post_send $jj" || RUNSEND=0
@@ -426,18 +442,13 @@ do
426442
;;
427443
(--send-full)
428444
opt_send_type='full'
429-
430-
opt_send_host=$(echo "$2" | sed 's,:.*,,')
431-
opt_recv_pool=$(echo "$2" | sed 's,.*:,,')
432-
433445
opt_send_opts="$opt_send_opts -R"
446+
opt_send="$2"
434447
shift 2
435448
;;
436449
(--send-incr)
437450
opt_send_type='incr'
438-
439-
opt_send_host=$(echo "$2" | sed 's,:.*,,')
440-
opt_recv_pool=$(echo "$2" | sed 's,.*:,,')
451+
opt_send="$2"
441452
shift 2
442453
;;
443454
(--send-fallback)

0 commit comments

Comments
 (0)