Add scripts for making snapshots of LVs with dm-snapshot even when those LVs reside... master
authorQuentin Smith <quentin@mit.edu>
Sun, 22 May 2011 02:44:20 +0000 (22:44 -0400)
committerQuentin Smith <quentin@mit.edu>
Sun, 22 May 2011 02:44:20 +0000 (22:44 -0400)
cheap-snapshot.sh [new file with mode: 0644]
cheap-unsnapshot.sh [new file with mode: 0644]

diff --git a/cheap-snapshot.sh b/cheap-snapshot.sh
new file mode 100644 (file)
index 0000000..1caff4c
--- /dev/null
@@ -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 (file)
index 0000000..73feccd
--- /dev/null
@@ -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