Skip to content

Commit

Permalink
Merge pull request #29 from mmalecki/pre-post
Browse files Browse the repository at this point in the history
Add pre and post snapshot hooks
  • Loading branch information
dajhorn committed Oct 14, 2014
2 parents 9d2398e + 10f9b3e commit 0be4466
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/zfs-auto-snapshot.8
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ Snapshot named filesystem and all descendants.
\fB\-v\fR, \fB\-\-verbose\fR
Print info messages.
.TP
\fB\-\-pre-snapshot\fR
Command to run before snapshotting. It is passed the
filesystem and snapshot name. If it returns non-zero,
snapshotting this filesystem is aborted.
.TP
\fB\-\-post-snapshot\fR
Command to run after snapshotting. It is passed the
filesystem and snapshot name.
.TP
name
Filesystem and volume names, or '//' for all ZFS datasets.
.SH SEE ALSO
Expand Down
15 changes: 14 additions & 1 deletion src/zfs-auto-snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ opt_setauto=''
opt_syslog=''
opt_skip_scrub=''
opt_verbose=''
opt_pre_snapshot=''
opt_post_snapshot=''

# Global summary statistics.
DESTRUCTION_COUNT='0'
Expand Down Expand Up @@ -156,8 +158,10 @@ do_snapshots () # properties, flags, snapname, oldglob, [targets...]

for ii in $TARGETS
do
if do_run "zfs snapshot $PROPS $FLAGS '$ii@$NAME'"
do_run "$opt_pre_snapshot $ii $NAME"
if [ $? -eq 0 ] && do_run "zfs snapshot $PROPS $FLAGS '$ii@$NAME'"
then
do_run "$opt_post_snapshot $ii $NAME"
SNAPSHOT_COUNT=$(( $SNAPSHOT_COUNT + 1 ))
else
WARNING_COUNT=$(( $WARNING_COUNT + 1 ))
Expand Down Expand Up @@ -198,6 +202,7 @@ GETOPT=$(getopt \
--longoptions=default-exclude,dry-run,fast,skip-scrub,recursive \
--longoptions=event:,keep:,label:,prefix:,sep: \
--longoptions=debug,help,quiet,syslog,verbose \
--longoptions=pre-snapshot:,post-snapshot: \
--options=dnshe:l:k:p:rs:qgv \
-- "$@" ) \
|| exit 128
Expand Down Expand Up @@ -308,6 +313,14 @@ do
opt_verbose='1'
shift 1
;;
(--pre-snapshot)
opt_pre_snapshot="$2"
shift 2
;;
(--post-snapshot)
opt_post_snapshot="$2"
shift 2
;;
(--)
shift 1
break
Expand Down

0 comments on commit 0be4466

Please sign in to comment.