snaprep

git mirror of https://ccx.te2000.cz/bzr/snaprep
git clone https://ccx.te2000.cz/git/snaprep
Log | Files | Refs

snap.marked (778B)


      1 #!/bin/sh
      2 
      3 usage() {
      4 	printf >&2 "Usage: %s: snapshot_dir program\n" $(basename "$0")
      5 	printf >&2 "Mark directory with a timestamp and run program"
      6 	printf >&2 "remove mark when program exits"
      7 	exit 2
      8 }
      9 
     10 die() {
     11 	printf "%s\n" "$*"
     12 	exit 1
     13 }
     14 
     15 test $# -gt 1 || usage
     16 SNAP_SRC="$1"
     17 : ${SNAP_WRITESRC:=$SNAP_SRC}
     18 export SNAP_SRC SNAP_WRITESRC
     19 shift
     20 test -d "$SNAP_SRC" || die "not a directory: $SNAP_SRC"
     21 test -d "$SNAP_WRITESRC" || die "not a directory: $SNAP_WRITESRC"
     22 LOCKFILE="$SNAP_WRITESRC/.snaprep"
     23 touch "$LOCKFILE" || exit $?
     24 flock -n 0 <"$LOCKFILE" || exit $?
     25 echo $$ >"$LOCKFILE" || exit $?
     26 rm -f "$SNAP_WRITESRC"/.snapshot.[0-9]* 2>/dev/null
     27 mark="$SNAP_WRITESRC/.snapshot.$(date +%s)"
     28 touch "$mark" || exit $?
     29 
     30 "$@"
     31 
     32 RETCODE=$?
     33 rm -f "$mark" "$LOCKFILE"
     34 exit $RETCODE