Skip to content

Commit 705ec33

Browse files
wankdankerFransUrbo
authored andcommitted
Implement --send-only for the snapshot replication.
Used for skipping snapshotting and only do the replication part.
1 parent 41054fc commit 705ec33

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

src/zfs-auto-snapshot.sh

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ opt_send_type=''
3838
opt_send_host=''
3939
opt_recv_pool=''
4040
opt_send_opts=''
41+
opt_send_only=''
4142
opt_recv_opts=''
4243
opt_send_ssh_opts=''
4344
opt_send_mbuf_opts=''
@@ -85,6 +86,7 @@ print_usage ()
8586
--send-ssh-opts Option(s) passed to 'ssh'.
8687
--send-mbuf-opts Use mbuffer (with these options) between 'zfs send'
8788
and 'ssh <host> zfs receive'.
89+
--send-only Only send the the most recent snapshot
8890
--sep=CHAR Use CHAR to separate date stamps in snapshot names.
8991
-g, --syslog Write messages into the system log.
9092
-r, --recursive Snapshot named filesystem and all descendants.
@@ -265,29 +267,35 @@ $ii@$NAME"
265267
fi
266268
fi
267269

270+
[ -n "$opt_send_only" ] && tmp=$(find_last_snap "$ii@$NAME" "$GLOB")
271+
[ -n "$tmp" ] && SNAPS_DONE="$SNAPS_DONE
272+
$tmp"
273+
268274
# Retain at most $opt_keep number of old snapshots of this filesystem,
269275
# including the one that was just recently created.
270276
test -z "$opt_keep" && continue
271277
KEEP="$opt_keep"
272278

273-
# ASSERT: The old snapshot list is sorted by increasing age.
274-
for jj in $SNAPSHOTS_OLD
275-
do
276-
# Check whether this is an old snapshot of the filesystem.
277-
if [ -z "${jj#$ii@$GLOB}" ]
278-
then
279-
KEEP=$(( $KEEP - 1 ))
280-
if [ "$KEEP" -le '0' ]
279+
if [ -z "$opt_send_only" ]; then
280+
# ASSERT: The old snapshot list is sorted by increasing age.
281+
for jj in $SNAPSHOTS_OLD
282+
do
283+
# Check whether this is an old snapshot of the filesystem.
284+
if [ -z "${jj#$ii@$GLOB}" ]
281285
then
282-
if do_run "zfs destroy $FLAGS '$jj'"
286+
KEEP=$(( $KEEP - 1 ))
287+
if [ "$KEEP" -le '0' ]
283288
then
284-
DESTRUCTION_COUNT=$(( $DESTRUCTION_COUNT + 1 ))
285-
else
286-
WARNING_COUNT=$(( $WARNING_COUNT + 1 ))
289+
if do_run "zfs destroy $FLAGS '$jj'"
290+
then
291+
DESTRUCTION_COUNT=$(( $DESTRUCTION_COUNT + 1 ))
292+
else
293+
WARNING_COUNT=$(( $WARNING_COUNT + 1 ))
294+
fi
287295
fi
288296
fi
289-
fi
290-
done
297+
done
298+
fi
291299
done
292300
}
293301

@@ -351,7 +359,7 @@ GETOPT=$(getopt \
351359
--longoptions=pre-snapshot:,post-snapshot:,destroy-only \
352360
--longoptions=send-full:,send-incr:,send-opts:,recv-opts: \
353361
--longoptions=send-ssh-opts:,send-mbuf-opts:,pre-send:,post-send: \
354-
--longoptions=send-fallback \
362+
--longoptions=send-fallback,send-only \
355363
--options=dnshe:l:k:p:rs:qgv \
356364
-- "$@" ) \
357365
|| exit 128
@@ -456,6 +464,11 @@ do
456464
opt_send_fallback=1
457465
shift 1
458466
;;
467+
(--send-only)
468+
opt_send_only=1
469+
opt_do_snapshots=''
470+
shift 1
471+
;;
459472
(--send-opts)
460473
opt_send_opts="$2"
461474
shift 2

0 commit comments

Comments
 (0)