@@ -51,6 +51,7 @@ opt_post_snapshot=''
5151opt_pre_send=' '
5252opt_post_send=' '
5353opt_do_snapshots=1
54+ opt_send_fallback=0
5455
5556# Global summary statistics.
5657DESTRUCTION_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
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