Skip to content

Commit 074b2e7

Browse files
committed
Implement do_destroy_remotes() to destroy the exact same snapshots
on remote host(s) which is destroyed on localhost.
1 parent 88725d9 commit 074b2e7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/zfs-auto-snapshot.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ WARNING_COUNT='0'
6161
# Other global variables.
6262
SNAPSHOTS_OLD=''
6363
SNAPS_DONE=''
64+
SNAPS_DESTROY=''
6465

6566

6667
print_usage ()
@@ -288,6 +289,8 @@ $tmp"
288289
if do_run "zfs destroy $FLAGS '$jj'"
289290
then
290291
DESTRUCTION_COUNT=$(( $DESTRUCTION_COUNT + 1 ))
292+
[ -n "$opt_send" ] && SNAPS_DESTROY="$SNAPS_DESTROY
293+
$jj"
291294
else
292295
WARNING_COUNT=$(( $WARNING_COUNT + 1 ))
293296
fi
@@ -361,6 +364,24 @@ do_send () # snapname, oldglob
361364
done
362365
}
363366

367+
368+
do_destroy_remotes ()
369+
{
370+
local FLAGS="$1"
371+
local ii
372+
local remote_ssh="ssh $opt_send_ssh_opts"
373+
374+
# Go through each option to --send-{incr,full}.
375+
# rem=<remote_host>:<remote_pool>
376+
for rem in $opt_send; do
377+
for ii in $SNAPS_DESTROY
378+
do
379+
do_run "$remote_ssh ${rem%:*} zfs destroy $FLAGS '$ii'"
380+
done
381+
done
382+
}
383+
384+
364385
# main ()
365386
# {
366387

@@ -774,6 +795,7 @@ do_snapshots "$SNAPPROP" "" "$SNAPNAME" "$SNAPGLOB" "$TARGETS_REGULAR"
774795
do_snapshots "$SNAPPROP" "-r" "$SNAPNAME" "$SNAPGLOB" "$TARGETS_RECURSIVE"
775796

776797
do_send "$SNAPNAME" "$SNAPGLOB"
798+
do_destroy_remotes
777799

778800
print_log notice "@$SNAPNAME," \
779801
"$SNAPSHOT_COUNT created," \

0 commit comments

Comments
 (0)