Skip to content

Commit a955674

Browse files
committed
Implement --send-fallback for the snapshot replication.
This allows a --send-incr to fallback to --send-full if it can't find an earlier snapshot.
1 parent 7b4d6d7 commit a955674

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/zfs-auto-snapshot.8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ Send zfs full backup to \fIhost\fR (or \fIip address\fR).
5252
\fB\-\-send\-incr\fR=\fIhost\fR
5353
Send zfs incremental backup to \fIhost\fR (or \fIip address\fR).
5454
.TP
55+
\fB\-\-send\-fallback\fR
56+
Allow to fallback from incremental to full snapshot replication.
57+
.sp
58+
This implies \fI-R\fR to \fBzfs send\fR and \fI-F\fR to \fBzfs receive\fR.
59+
.TP
5560
\fB\-\-send\-opts\fR=\fIOPTS\fR
5661
Option(s) passed to 'zfs send'.
5762
.TP

src/zfs-auto-snapshot.sh

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ opt_post_snapshot=''
5151
opt_pre_send=''
5252
opt_post_send=''
5353
opt_do_snapshots=1
54+
opt_send_fallback=0
5455

5556
# Global summary statistics.
5657
DESTRUCTION_COUNT='0'
@@ -77,6 +78,7 @@ print_usage ()
7778
-q, --quiet Suppress warnings and notices at the console.
7879
--send-full=F Send zfs full backup. Unimplemented.
7980
--send-incr=F Send zfs incremental backup. Unimplemented.
81+
--send-fallback Fallback from incremental to full if needed.
8082
--send-opts=F Option(s) passed to 'zfs send'.
8183
--recv-opts=F Option(s) passed to 'zfs receive'.
8284
--send-ssh-opts Option(s) passed to 'ssh'.
@@ -230,8 +232,8 @@ do_send () # snapname, oldglob
230232
local ii
231233

232234
[ -n "$opt_send_mbuf_opts" ] && remote="mbuffer $opt_send_mbuf_opts |"
233-
remote="$remote ssh $opt_send_ssh_opts $opt_send_host "
234-
remote="$remote zfs receive $opt_recv_opts $opt_recv_pool"
235+
remote="$remote ssh $opt_send_ssh_opts $opt_send_host"
236+
remote="$remote zfs receive $opt_recv_opts"
235237

236238
# STEP 1: Go throug all snapshots we've created
237239
for ii in $SNAPS_DONE
@@ -262,11 +264,14 @@ do_send () # snapname, oldglob
262264
# 1: We change from incremental to full.
263265
# 2: We accept that the user have said INCR, and stick with
264266
# it.
265-
if [ "$opt_send_type" = "incr" -a -z "$last_snap" ]; then
267+
# Normally we do point 2, but if --send-fallback is specified,
268+
# we allow it and convert to a full send instead.
269+
if [ "$opt_send_type" = "incr" -a -z "$last_snap" -a -z "$opt_send_fallback" ]; then
266270
if [ -n "$opt_verbose" ]; then
267271
echo "WARNING: No previous snapshots exist but we where called"
268272
echo " with --send-incr. Can not continue."
269273
echo " Please rerun with --send-full."
274+
echo " Or use --send-fallback."
270275
fi
271276
return 1
272277
fi
@@ -296,9 +301,15 @@ $jj"
296301

297302
if [ $RUNSEND -eq 1 ]; then
298303
if [ "$opt_send_type" = "incr" ]; then
299-
do_run "zfs send $opt_send_opts -i $jj $ii | $remote" || RUNSEND=0
304+
if [ "$jj" = "$ii" -a -n "$opt_send_fallback" ]; then
305+
do_run "zfs send $opt_send_opts -R $ii | $remote -F $opt_recv_pool" \
306+
|| RUNSEND=0
307+
else
308+
do_run "zfs send $opt_send_opts -i $jj $ii | $remote $opt_recv_pool" \
309+
|| RUNSEND=0
310+
fi
300311
else
301-
do_run "zfs send $opt_send_opts -R $jj | $remote" || RUNSEND=0
312+
do_run "zfs send $opt_send_opts -R $jj | $remote $opt_recv_pool" || RUNSEND=0
302313
fi
303314
fi
304315

@@ -320,6 +331,7 @@ GETOPT=$(getopt \
320331
--longoptions=pre-snapshot:,post-snapshot:,destroy-only \
321332
--longoptions=send-full:,send-incr:,send-opts:,recv-opts: \
322333
--longoptions=send-ssh-opts:,send-mbuf-opts:,pre-send:,post-send: \
334+
--longoptions=send-fallback \
323335
--options=dnshe:l:k:p:rs:qgv \
324336
-- "$@" ) \
325337
|| exit 128
@@ -420,6 +432,10 @@ do
420432
opt_recv_pool=$(echo "$2" | sed 's,.*:,,')
421433
shift 2
422434
;;
435+
(--send-fallback)
436+
opt_send_fallback=1
437+
shift 1
438+
;;
423439
(--send-opts)
424440
opt_send_opts="$2"
425441
shift 2

0 commit comments

Comments
 (0)