snaprep

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

commit 3292774151bb3be7d89c00bde648c924323accbf
parent 1543c425e5abb5ab7de4eab8aa992f78827b7c2e
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date:   Tue, 12 Aug 2014 19:06:09 +0200

add snap.marked for plain directory snapshotting
Diffstat:
Abin/snap.marked | 32++++++++++++++++++++++++++++++++
Mbin/snap.push | 2+-
2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/bin/snap.marked b/bin/snap.marked @@ -0,0 +1,32 @@ +#!/bin/sh + +usage() { + printf >&2 "Usage: %s: snapshot_dir program\n" $(basename "$0") + printf >&2 "Mark directory with a timestamp and run program" + printf >&2 "remove mark when program exits" + exit 2 +} + +die() { + printf "%s\n" "$*" + exit 1 +} + +test $# -gt 1 || usage +SNAP_SRC="$1" +export SNAP_SRC +shift +test -d "$SNAP_SRC" || die "not a directory: $SNAP_SRC" +LOCKFILE="$SNAP_SRC/.snaprep" +touch "$LOCKFILE" || exit $? +flock -n 0 <"$LOCKFILE" || exit $? +echo $$ >"$LOCKFILE" || exit $? +rm -f "$SNAP_SRC"/.snapshot.[0-9]* 2>/dev/null +mark="$SNAP_SRC/.snapshot.$(date +%s)" +touch "$mark" || exit $? + +"$@" + +RETCODE=$? +rm -f "$mark" "$LOCKFILE" +exit $RETCODE diff --git a/bin/snap.push b/bin/snap.push @@ -7,7 +7,7 @@ usage() { } die() { - printf "%s" "$*" + printf "%s\n" "$*" exit 1 }