From: Quentin Smith Date: Sun, 22 May 2011 02:44:20 +0000 (-0400) Subject: Add scripts for making snapshots of LVs with dm-snapshot even when those LVs reside... X-Git-Url: http://xvm.mit.edu/gitweb/invirt/scripts/pv-fixup.git/commitdiff_plain/HEAD?ds=sidebyside Add scripts for making snapshots of LVs with dm-snapshot even when those LVs reside on a clustered VG --- diff --git a/cheap-snapshot.sh b/cheap-snapshot.sh new file mode 100644 index 0000000..1caff4c --- /dev/null +++ b/cheap-snapshot.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +set -e +set -x + +BASE="$1" +BASEDUP="basedup" +ORIGIN="origin" +TOP="top" +COWFILE="/tmp/cowfile" + +[ -e "/dev/mapper/$BASE" ] || exit 1 + +[ -e "$COWFILE" ] || exit 1 + +COWDEVICE="$(losetup -sf $COWFILE)" + +echo 3 > /proc/sys/vm/drop_caches + +# Copy the base's table onto basedup +dmsetup table $BASE | dmsetup create $BASEDUP + +# Prepare COW image +CHUNK=8 +dd if=/dev/zero of=$COWDEVICE bs=512 count=$CHUNK + +# Create a snapshot +echo 0 $(blockdev --getsize /dev/mapper/$BASEDUP) \ + snapshot /dev/mapper/$BASEDUP $COWDEVICE p 8 | \ + dmsetup create $TOP + +# Suspend I/O to base +dmsetup suspend $BASE +echo "Snapshot as of" +date + +echo 0 $(blockdev --getsize /dev/mapper/$BASEDUP) \ + snapshot-origin /dev/mapper/$BASEDUP | \ + dmsetup create $ORIGIN + +dmsetup table $ORIGIN | dmsetup load $BASE + +dmsetup resume $BASE diff --git a/cheap-unsnapshot.sh b/cheap-unsnapshot.sh new file mode 100644 index 0000000..73feccd --- /dev/null +++ b/cheap-unsnapshot.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +set -e +set -x + +BASE="$1" +BASEDUP="basedup" +ORIGIN="origin" +TOP="top" + +[ -e "/dev/mapper/$BASE" ] || exit 1 + +dmsetup suspend $BASE +dmsetup remove $TOP +dmsetup remove $ORIGIN +dmsetup table $BASEDUP | dmsetup load $BASE +dmsetup resume $BASE