Skip to content

Commit a0c67c5

Browse files
committed
Implement multiple receive hosts for the snapshot replication.
1 parent 46a6772 commit a0c67c5

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_send_only=''
4241
opt_recv_opts=''
@@ -189,7 +188,7 @@ do_snapshots () # properties, flags, snapname, oldglob, [targets...]
189188
if [ $RUNSNAP -eq 1 ] && do_run "zfs snapshot $PROPS $FLAGS '$ii@$NAME'"
190189
then
191190
[ "$opt_post_snapshot" != "" ] && do_run "$opt_post_snapshot $ii $NAME"
192-
[ -n "$opt_send_host" ] && SNAPS_DONE="$SNAPS_DONE
191+
[ -n "$opt_send" ] && SNAPS_DONE="$SNAPS_DONE
193192
$ii@$NAME"
194193
SNAPSHOT_COUNT=$(( $SNAPSHOT_COUNT + 1 ))
195194
else
@@ -244,13 +243,13 @@ do_send () # snapname, oldglob
244243
local NAME="$1"
245244
local GLOB="$2"
246245
local RUNSEND=1
247-
local remote
246+
local remote_ssh="ssh $opt_send_ssh_opts"
247+
local remote_recv="zfs receive $opt_recv_opts"
248+
local remote_mbuf=""
248249
local ii
249250
local jj
250251

251-
[ -n "$opt_send_mbuf_opts" ] && remote="mbuffer $opt_send_mbuf_opts |"
252-
remote="$remote ssh $opt_send_ssh_opts $opt_send_host"
253-
remote="$remote zfs receive $opt_recv_opts"
252+
[ -n "$opt_send_mbuf_opts" ] && remote_mbuf="mbuffer $opt_send_mbuf_opts |"
254253

255254
# STEP 1: Go throug all snapshots we've created
256255
for ii in $SNAPS_DONE
@@ -325,17 +324,34 @@ $jj"
325324
fi
326325

327326
if [ $RUNSEND -eq 1 ]; then
328-
if [ "$opt_send_type" = "incr" ]; then
329-
if [ "$jj" = "$ii" -a -n "$opt_send_fallback" ]; then
330-
do_run "zfs send $opt_send_opts -R $ii | $remote -F $opt_recv_pool" \
331-
|| RUNSEND=0
327+
OLD_IFS=$IFS ; IFS=";"
328+
329+
# Go through each option to --send-{incr,full}.
330+
# rem=<remote_host>:<remote_pool>
331+
for rem in $opt_send; do
332+
if [ "$opt_send_type" = "incr" ]; then
333+
if [ "$jj" = "$ii" -a -n "$opt_send_fallback" ]; then
334+
cmd="zfs send $opt_send_opts -R $ii |"
335+
cmd="$cmd $remote_mbuf"
336+
cmd="$cmd $remote_ssh ${rem%:*}"
337+
cmd="$cmd $remote_recv -F ${rem#*:}"
338+
else
339+
cmd="zfs send $opt_send_opts -i $jj $ii |"
340+
cmd="$cmd $remote_mbuf"
341+
cmd="$cmd $remote_ssh ${rem%:*}"
342+
cmd="$cmd $remote_recv ${rem#*:}"
343+
fi
332344
else
333-
do_run "zfs send $opt_send_opts -i $jj $ii | $remote $opt_recv_pool" \
334-
|| RUNSEND=0
345+
cmd="zfs send $opt_send_opts -R $jj |"
346+
cmd="$cmd $remote_mbuf"
347+
cmd="$cmd $remote_ssh ${rem%:*}"
348+
cmd="$cmd $remote_recv ${rem#*:}"
335349
fi
336-
else
337-
do_run "zfs send $opt_send_opts -R $jj | $remote $opt_recv_pool" || RUNSEND=0
338-
fi
350+
351+
do_run "$cmd" || RUNSEND=0
352+
done
353+
354+
IFS=$OLD_IFS
339355

340356
if [ $RUNSEND = 1 -a -n "$opt_post_send" ]; then
341357
do_run "$opt_post_send $jj" || RUNSEND=0
@@ -442,18 +458,13 @@ do
442458
;;
443459
(--send-full)
444460
opt_send_type='full'
445-
446-
opt_send_host=$(echo "$2" | sed 's,:.*,,')
447-
opt_recv_pool=$(echo "$2" | sed 's,.*:,,')
448-
449461
opt_send_opts="$opt_send_opts -R"
462+
opt_send="$2"
450463
shift 2
451464
;;
452465
(--send-incr)
453466
opt_send_type='incr'
454-
455-
opt_send_host=$(echo "$2" | sed 's,:.*,,')
456-
opt_recv_pool=$(echo "$2" | sed 's,.*:,,')
467+
opt_send="$2"
457468
shift 2
458469
;;
459470
(--send-fallback)

0 commit comments

Comments
 (0)