snaprep

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

commit e55fdf495157891cc7f0f3d029df4a12c64956b9
parent 7dfeff7ea36be16deaac4ae89e5cde40301a267f
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date:   Tue, 18 Feb 2014 23:49:24 +0100

make it work
Diffstat:
Mbin/snap.push.single | 15++++++++++-----
Msbin/snap.lvm2 | 9+++++++--
2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/bin/snap.push.single b/bin/snap.push.single @@ -7,27 +7,32 @@ die() { if [[ -z $SNAP_SRC ]]; then SNAP_SRC=$1;shift fi +SNAP_SRC=${SNAP_SRC%%/} + if [[ -z $SNAP_DST ]]; then SNAP_DST=$1;shift fi +SNAP_DST=${SNAP_DST%%/} + +rsync=( rsync -aA --delete "$@" ) marks=( $SNAP_SRC/.snapshot.[0-9]*(N) ) (( $#marks != 1 )) && die invalid marks ${(qqq)marks} if [[ $SNAP_DST == *:* ]]; then # remote - rsync -aA --delete "$@" --exclude=/.snapshot.\* $SNAP_SRC/ $SNAP_DST/ && \ - rsync -aA --delete "$@" $SNAP_SRC/ $SNAP_DST/ + $rsync --exclude=/.snapshot.\* $SNAP_SRC/ $SNAP_DST/ && \ + $rsync $SNAP_SRC/ $SNAP_DST/ else # local [[ -d $SNAP_DST ]] || die destination not a directory: ${(qqq)SNAP_DST} - ts=${f##*.} + ts=${marks##*.} snapshots=( ${SNAP_DST}/.snapshot.[1-9]*(N) ) if (($#snapshots)); then link=${SNAP_DST}/${${snapshots[-1]}##*.} - rsync -aA --link-dest=$link "$@" $SNAP_SRC/ $SNAP_DST/$ts/ || exit $? + $rsync --link-dest=$link $SNAP_SRC/ $SNAP_DST/$ts/ || exit $? else - rsync -aA "$@" $SNAP_SRC/ $SNAP_DST/$ts/ || exit $? + $rsync $SNAP_SRC/ $SNAP_DST/$ts/ || exit $? fi touch ${SNAP_DST}/$marks:t fi diff --git a/sbin/snap.lvm2 b/sbin/snap.lvm2 @@ -1,5 +1,9 @@ #!/bin/sh # usage: snapshot.lvm2 vg/lv executable [args] +if test $# -lt 2; then + echo 'usage: snap.lvm2 vg/lv executable [args]' + exit +fi SRC="$1" shift S_VOL="${SRC}.snaprep" @@ -13,7 +17,7 @@ touch "$LOCKFILE" || exit $? flock -n 0 <"$LOCKFILE" || exit $? if test -b "$S_DEV"; then echo >&2 "removing stale snapshot" - if grep -qF "$S_DEV"; then # TODO match only on start of line + if grep -qF "$S_DEV" /proc/mounts; then # TODO match only on start of line umount $S_DEV || exit $? fi lvremove -f "$S_DEV" || exit $? @@ -29,7 +33,8 @@ die_lvremove() { lvremove -f "$S_VOL" exit $? } -case file in "$(file -b -s "$S_DEV")"; do +magic="$(file -b -s "$(realpath "$S_DEV")")" +case "$magic" in (*XFS*) mount -t xfs -o nouuid "$S_DEV" "$SNAPSHOT" || die_lvremove $?;; (*) mount "$S_DEV" "$SNAPSHOT" || die_lvremove $?;; esac