Skip to content

Commit

Permalink
Implement {pre,post}-send option for the snapshot replication.
Browse files Browse the repository at this point in the history
  • Loading branch information
FransUrbo committed Apr 3, 2015
1 parent eeda303 commit 0ea3552
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/zfs-auto-snapshot.8
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ aborted.
Command to run after each dataset is snapshotted.
It is passed the dataset and snapshot name.
.TP
\fB\-\-pre-send\fR=\fICOMMAND\fR
Command to run before each snapshot is sent to
remote host. It is passed the snapshot name. If
it returns non-zero, sending this dataset is
aborted.
.TP
\fB\-\-post-send\fR=\fICOMMAND\fR
Command to run after each snapshot have been sent.
It is passed the snapshot name.
.TP
\fB\-\-destroy-only\fR
Do not create new snapshots, but do destroy older
snapshots. Has no effect unless used with \fB\-k\fR.
Expand Down
31 changes: 27 additions & 4 deletions src/zfs-auto-snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ opt_skip_scrub=''
opt_verbose=''
opt_pre_snapshot=''
opt_post_snapshot=''
opt_pre_send=''
opt_post_send=''
opt_do_snapshots=1

# Global summary statistics.
Expand Down Expand Up @@ -220,6 +222,7 @@ do_send () # snapname, oldglob
local GLOB="$2"
local ii
local remote="ssh $opt_send_host zfs receive $opt_recv_opts $opt_recv_pool"
local RUNSEND=1

# STEP 1: Go throug all snapshots we've created
for ii in $SNAPS_DONE
Expand Down Expand Up @@ -278,11 +281,22 @@ $jj"
# STEP 4: Go through all snapshots that is to be transfered and send them.
for jj in $SNAPS_SEND
do
if [ "$opt_send_type" = "incr" ]; then
echo "zfs send $opt_send_opts -i $jj $ii | $remote"
else
echo "zfs send $opt_send_opts -R $jj | $remote"
if [ -n "$opt_pre_send" ]; then
do_run "$opt_pre_send $jj" || RUNSEND=0
fi

if [ $RUNSEND -eq 1 ]; then
if [ "$opt_send_type" = "incr" ]; then
do_run "zfs send $opt_send_opts -i $jj $ii | $remote" || RUNSEND=0
else
do_run "zfs send $opt_send_opts -R $jj | $remote" || RUNSEND=0
fi
fi

if [ $RUNSEND = 1 -a -n "$opt_post_send" ]; then
do_run "$opt_post_send $jj" || RUNSEND=0
fi

done
done
}
Expand All @@ -296,6 +310,7 @@ GETOPT=$(getopt \
--longoptions=debug,help,quiet,syslog,verbose \
--longoptions=pre-snapshot:,post-snapshot:,destroy-only \
--longoptions=send-full:,send-incr:,send-opts:,recv-opts: \
--longoptions=pre-send:,post-send: \
--options=dnshe:l:k:p:rs:qgv \
-- "$@" ) \
|| exit 128
Expand Down Expand Up @@ -438,6 +453,14 @@ do
opt_post_snapshot="$2"
shift 2
;;
(--pre-send)
opt_pre_send="$2"
shift 2
;;
(--post-send)
opt_post_send="$2"
shift 2
;;
(--destroy-only)
opt_do_snapshots=''
shift 1
Expand Down

0 comments on commit 0ea3552

Please sign in to comment.