snaprep

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

commit 7dfeff7ea36be16deaac4ae89e5cde40301a267f
parent 8d8ce8e508960ef554947fb1fa71618667b4e386
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date:   Tue, 18 Feb 2014 14:43:24 +0100

move stuff around
Diffstat:
Rsnap.push.single -> bin/snap.push.single | 0
Rpost -> bin/snap.rsync.post | 0
Rpre -> bin/snap.rsync.pre | 0
Rsnap.shell -> bin/snap.shell | 0
Asbin/snap.lvm2 | 44++++++++++++++++++++++++++++++++++++++++++++
Dsnapshot.lvm2 | 41-----------------------------------------
6 files changed, 44 insertions(+), 41 deletions(-)

diff --git a/snap.push.single b/bin/snap.push.single diff --git a/post b/bin/snap.rsync.post diff --git a/pre b/bin/snap.rsync.pre diff --git a/snap.shell b/bin/snap.shell diff --git a/sbin/snap.lvm2 b/sbin/snap.lvm2 @@ -0,0 +1,44 @@ +#!/bin/sh +# usage: snapshot.lvm2 vg/lv executable [args] +SRC="$1" +shift +S_VOL="${SRC}.snaprep" +S_DEV="/dev/${SRC}.snaprep" +SNAPSHOT="/mnt/snaprep/${SRC//\//-}" +export SNAPSHOT +LOCKDIR=/var/lock/snaprep +test -d "$LOCKDIR" || mkdir -p "$LOCKDIR" || exit $? +LOCKFILE="$LOCKDIR/lvm2.${SRC//\//-}" +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 + umount $S_DEV || exit $? + fi + lvremove -f "$S_DEV" || exit $? +fi +if test -d "$SNAPSHOT"; then + # make sure it's empty and unused + rmdir "$SNAPSHOT" || exit $? +fi +echo $$ >"$LOCKFILE" || exit $? +mkdir -p "$SNAPSHOT" || exit $? +lvcreate -n "${SRC##*/}.snaprep" -L "${SNAPSHOT_SIZE:-10G}" -s "$SRC" || exit $? +die_lvremove() { + lvremove -f "$S_VOL" + exit $? +} +case file in "$(file -b -s "$S_DEV")"; do + (*XFS*) mount -t xfs -o nouuid "$S_DEV" "$SNAPSHOT" || die_lvremove $?;; + (*) mount "$S_DEV" "$SNAPSHOT" || die_lvremove $?;; +esac +SNAP_SRC=$SNAPSHOT +export SNAP_SRC +touch $SNAP_SRC/.snapshot.$(date +%s) +"$@" +RETCODE=$? +umount "$SNAPSHOT" +lvremove -f "$S_VOL" +rm "$LOCKFILE" +exit $RETCODE diff --git a/snapshot.lvm2 b/snapshot.lvm2 @@ -1,41 +0,0 @@ -#!/bin/sh -# usage: snapshot.lvm2 vg/lv executable [args] -SRC="$1" -shift -S_VOL="${SRC}.snaprep" -S_DEV="/dev/${SRC}.snaprep" -SNAPSHOT="/mnt/snaprep/${SRC//\//-}" -export SNAPSHOT -LOCKDIR=/var/lock/snaprep -test -d "$LOCKDIR" || mkdir -p "$LOCKDIR" || exit $? -LOCKFILE="$LOCKDIR/lvm2.${SRC//\//-}" -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 - umount $S_DEV || exit $? - fi - lvremove -f "$S_DEV" || exit $? -fi -if test -d "$SNAPSHOT"; then - # make sure it's empty and unused - rmdir "$SNAPSHOT" || exit $? -fi -echo $$ >"$LOCKFILE" || exit $? -mkdir -p "$SNAPSHOT" || exit $? -lvcreate -n "${SRC##*/}.snaprep" -L "${SNAPSHOT_SIZE:-10G}" -s "$SRC" || exit $? -die_lvremove() { - lvremove -f "$S_VOL" - exit $? -} -mount "$S_DEV" "$SNAPSHOT" || die_lvremove $? -SNAP_SRC=$SNAPSHOT -export SNAP_SRC -touch $SNAP_SRC/.snapshot.$(date +%s) -"$@" -RETCODE=$? -umount "$SNAPSHOT" -lvremove -f "$S_VOL" -rm "$LOCKFILE" -exit $RETCODE