Skip to content

Commit

Permalink
Added new switch -E which treats omitting a snapshot as an error.
Browse files Browse the repository at this point in the history
  • Loading branch information
serpedon committed Mar 14, 2016
1 parent e32f0ea commit 234f5fc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# btrfs-snap Changelog
## v1.7.0 (Mar 14 2016)
* Added new switch -E which treats omitting a snapshot as an error.

## v1.6.1 (Mar 14 2016)
* Bugfix: touch to update the timestamp is only needed for option '-t'.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ btrfs-snap [-r] [-b basedir] mountpoint prefix count
* -r makes the snapshot readonly (requires btrfs-tools v0.20)
* -c generates more compatible snapshot names
(ie. no colons that confuse SAMBA/Window$ clients)
* -E treats omitting of snapshots as error
* -p redefines the prefix to be used as postfix
* -d dir places the snapshot in dir, relative to the mountpoint
* -b basedir places the snapshot in basedir with a directory structure that mimics the mountpoint
Expand Down
17 changes: 12 additions & 5 deletions btrfs-snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
set -u

LOG_FACILITY=local0
VERSION="1.6.0"
VERSION="1.7.0"
prog=${0##*/}
PATH="$PATH:/usr/sbin:/usr/bin:/sbin:/bin"

Expand Down Expand Up @@ -46,6 +46,9 @@ if '-c' is given, snapshots are created with more compatible names
if '-p' is given, the <prefix> will be used as a postfix, i.e. it is
appended which might be usefull for automatic chronological sorting.
if '-E' is given, omitting a snapshot (e.g. due to options -t/-T) is
treated as an error and a non-zero exit code is returned.
if '-d dir' is given, snapshots are created in dir, relative to
mountpoint (default: '.snapshot', conflicts with -b and -B).
Expand Down Expand Up @@ -105,8 +108,9 @@ use_as_prefix=true
use_transid=false
time_delim=":"
ONE_OF_b_B_d_GIVEN=false
OMITT_ERROR_CODE=0
time_duration=0
while getopts "hVrpb:d:B:ct:T:" arg; do
while getopts "hVrpEb:d:B:ct:T:" arg; do
case "${arg}" in
h )
echo "$SYNOPSIS"
Expand All @@ -118,6 +122,9 @@ while getopts "hVrpb:d:B:ct:T:" arg; do
p )
use_as_prefix=false
;;
E )
OMITT_ERROR_CODE=1
;;
t )
time_duration=$((0+$OPTARG))
;;
Expand Down Expand Up @@ -237,21 +244,21 @@ if [ $time_duration -gt 0 ]; then
id_mount=$(btrfs subvolume find-new "${mp}" 99999999| sed 's/[^0-9]//g')
if [ $id_mount -le $id_snap ]; then
log.info "No snapshot created since no changes since last snapshot. (Transaction id of $newestSnapshot is newer or equal to $mp.)"
exit 0;
exit $OMITT_ERROR_CODE
fi
else
mp_time=`stat -c "%Y" "${mp}"`
if [ $snap_time == $mp_time ]; then
log.info "No snapshot created since timestamp of newest snapshot $newestSnapshot equal $mp."
exit 0;
exit $OMITT_ERROR_CODE
fi
# Force update of source timestamp to prevent outdated timestamps on the folders
touch "${mp}"
fi

if [ $(($snap_time + $time_duration)) -gt $cur_time ]; then
log.info "No snapshot created since timestamp of newest snapshot $newestSnapshot is less than $time_duration seconds away."
exit 0;
exit $OMITT_ERROR_CODE
fi
fi
fi
Expand Down

0 comments on commit 234f5fc

Please sign in to comment.