4 # 5-second regression test for dump/verify/restore. It's not intended to be
5 # an exhaustive regression test, just a quick way to verify that you haven't
6 # introduced any errors when changing code.
8 # N.B., this only verifies that THIS build of dump(8) and THIS build of
9 # restore(8) will play well together. It does not guarantee that these systems
10 # are compatible with released versions of the software! For that we need
11 # to keep images of known-good partitions and dump files.
13 # Author: Bear Giles (bgiles@coyotesong.com)
14 # License granted to dump project under non-advertising BSD license.
18 # Create 10 MB virtual partition.
20 # mkvirtpart(filename, loop device)
27 if [ "$#" -ne "2" ]; then
28 /bin/echo "usage: mkvrtpart FILENAME LOOPDEV"
32 # create 10M sparse file
33 /usr/bin/truncate -s 10M $FILENAME
34 if [ "$?" -ne "0" ]; then
35 /bin/echo "unable to create partition image."
40 /sbin/losetup $LOOPDEV $FILENAME
41 if [ "$?" -ne "0" ]; then
42 /bin/echo "setting up loop device failed."
46 /sbin/mkfs -text4 $LOOPDEV
47 if [ "$?" -ne "0" ]; then
48 /bin/echo "formating test partition failed."
49 /sbin/losetup -d $LOOPDEV
53 /sbin/losetup -d $LOOPDEV
54 if [ "$?" -ne "0" ]; then
55 /bin/echo "tearing down loop device failed."
61 # Populate test filesystem
68 if [ "$#" -ne "1" ]; then
69 /bin/echo "usage: mktestfs ROOT"
73 if [ "$ROOT" == "" -o "$ROOT" == "/" ]; then
74 /bin/echo "cowardly refusing to stomp on root."
78 /usr/bin/install -d $ROOT
81 /usr/bin/touch $ROOT/perm644
82 /bin/chmod 0644 $ROOT/perm644
84 # create typical executable
85 /usr/bin/touch $ROOT/perm755
86 /bin/chmod 0755 $ROOT/perm755
88 # create multiple symlinks
89 /usr/bin/touch $ROOT/symlink
90 /bin/ln $ROOT/symlink $ROOT/symlink1
91 /bin/ln $ROOT/symlink $ROOT/symlink2
94 /usr/bin/touch $ROOT/hardlink
95 /bin/ln $ROOT/hardlink $ROOT/hardlink1
96 /bin/ln $ROOT/hardlink $ROOT/hardlink2
99 /bin/mknod $ROOT/block b 10 20
101 # create character device
102 /bin/mknod $ROOT/char c 11 21
105 /bin/mknod $ROOT/pipe p
108 #/usr/bin/truncate -s 500k $ROOT/sparse
110 # populate some files
111 /bin/mkdir $ROOT/man1
112 /bin/cp -rp /usr/share/man/man1/* $ROOT/man1
118 dump_verify_restore() {
120 if [ "$#" -lt "5" ]; then
121 /bin/echo "usage: dump_verify_restore SRC_LOOPDEV SRC_MOUNTPOINT DEST_LOOPDEV DEST_MOUNTPOINT DUMPFILE ..."
131 shift; shift; shift; shift; shift
133 /sbin/losetup $SRC_LOOPDEV $SRC_FILENAME
134 if [ "$?" -ne "0" ]; then
135 /bin/echo "setting up loop device failed."
139 # we have to mount partition for verify to work even if we dump the
140 # underlying partition.
141 /bin/mount $SRC_LOOPDEV $SRC_MOUNTPOINT
142 if [ "$?" -ne "0" ]; then
143 /bin/echo "mounting source partition failed."
144 /sbin/losetup -d $SRC_LOOPDEV
148 # dump the test partition
149 ../dump/dump -0 $@ -f $DUMPFILE $SRC_LOOPDEV
150 if [ "$?" -ne "0" ]; then
151 echo "dump failed, error code $?"
153 /bin/umount $SRC_MOUNTPOINT
154 /sbin/losetup -d $SRC_LOOPDEV
159 ../restore/restore -C -f $DUMPFILE
160 if [ "$?" -ne "0" ]; then
161 echo "verification failed, error code $?"
163 /bin/umount $SRC_MOUNTPOINT
164 /sbin/losetup -d $SRC_LOOPDEV
168 # restore fs, compare to orginal one
169 # I can't do that yet since restore will only restore to the current directory.
170 # this makes sense for a number of reasons it difficult to test our newly
172 # ../../restore/restore -r ...
174 # tear everything down
175 /bin/umount $SRC_MOUNTPOINT
176 if [ "$?" -ne "0" ]; then
177 /bin/echo "unmounting test partition failed."
181 /sbin/losetup -d $SRC_LOOPDEV
182 if [ "$?" -ne "0" ]; then
183 /bin/echo "tearing down loop device failed."
189 # set up source partition.
191 setup_src_partition() {
196 if [ "$#" -ne "3" ]; then
197 /bin/echo "usage: setup_src_partition SRC_FILENAME SRC_LOOPDEV SRC_MOUNTPOINT"
201 mkvirtpart $SRC_FILENAME $SRC_LOOPDEV
202 if [ $? -ne 0 ]; then
203 /bin/echo "creating source test partition failed."
208 /sbin/losetup $SRC_LOOPDEV $SRC_FILENAME
209 if [ "$?" -ne "0" ]; then
210 /bin/echo "setting up loop device failed."
214 /bin/mount $SRC_LOOPDEV $SRC_MOUNTPOINT
215 if [ "$?" -ne "0" ]; then
216 /bin/echo "mounting test partition failed."
220 mktestfs $SRC_MOUNTPOINT
221 if [ "$?" -ne "0" ]; then
225 /bin/umount $SRC_LOOPDEV
226 if [ "$?" -ne "0" ]; then
227 /bin/echo "unmounting test partition failed."
231 /sbin/losetup -d $SRC_LOOPDEV
232 if [ "$?" -ne "0" ]; then
233 /bin/echo "tearing down loop device failed."
242 # clean up temporary files. We want to be extremely careful here that
243 # we don't accidently do a 'rm -rf' on /
247 if [ "$#" -ne "6" ]; then
248 /bin/echo "usage: cleanup SRC_FILENAME SRC_MOUNTPOINT DEST_FILENAME DEST_MOUNTPOINT BASEDIR DUMPFILE"
259 if [ "$BASEDIR" == "" -o "$BASEDIR" == "/" ]; then
260 /bin/echo "cowardly refusing to delete root."
264 # we don't do rm -r since we don't want to delete
265 # anything we didn't create.
266 /bin/rm -f $SRC_FILENAME
267 /bin/rmdir $SRC_MOUNTPOINT
268 /bin/rm -f $DEST_FILENAME
269 /bin/rmdir $DEST_MOUNTPOINT
276 ###############################################
280 BASEDIR=`/bin/mktemp -d`
282 SRC_FILENAME=$BASEDIR/dump-test-src.img
283 SRC_LOOPDEV=/dev/loop6
284 SRC_MOUNTPOINT=$BASEDIR/src
285 DEST_FILENAME=$BASEDIR/dump-test-dst.img
286 DEST_LOOPDEV=/dev/loop7
287 DEST_MOUNTPOINT=$BASEDIR/dest
288 DUMPFILE=$BASEDIR/dump-test.dump
290 /bin/echo BASEDIR = $BASEDIR
292 /usr/bin/install -d $BASEDIR
293 /usr/bin/install -d $SRC_MOUNTPOINT
294 /usr/bin/install -d $DEST_MOUNTPOINT
296 # Setup source partition
297 setup_src_partition $SRC_FILENAME $SRC_LOOPDEV $SRC_MOUNTPOINT
298 if [ $? -ne 0 ]; then
299 /bin/echo "creating source test partition failed."
300 cleanup $SRC_FILENAME $SRC_MOUNTPOINT $DEST_FILENAME $DEST_MOUNTPOINT $BASEDIR $DUMPFILE
304 # create dest partition (for restores)
305 mkvirtpart $DEST_FILENAME $DEST_LOOPDEV
306 if [ $? -ne 0 ]; then
307 /bin/echo "creating destination test partition failed."
308 cleanup $SRC_FILENAME $SRC_MOUNTPOINT $DEST_FILENAME $DEST_MOUNTPOINT $BASEDIR $DUMPFILE
313 echo "testing basic dump/restore"
314 dump_verify_restore $SRC_LOOPDEV $SRC_MOUNTPOINT $DEST_LOOPDEV $DEST_MOUNTPOINT $DUMPFILE
315 if [ $? -ne 0 ]; then
316 /bin/echo "dump cycle failed."
317 cleanup $SRC_FILENAME $SRC_MOUNTPOINT $DEST_FILENAME $DEST_MOUNTPOINT $BASEDIR $DUMPFILE
322 echo "testing compressed dump/restore (lzo)..."
323 dump_verify_restore $SRC_LOOPDEV $SRC_MOUNTPOINT $DEST_LOOPDEV $DEST_MOUNTPOINT $DUMPFILE -y
324 if [ $? -ne 0 ]; then
325 /bin/echo "dump cycle failed."
326 cleanup $SRC_FILENAME $SRC_MOUNTPOINT $DEST_FILENAME $DEST_MOUNTPOINT $BASEDIR $DUMPFILE
331 echo "testing compressed dump/restore (zlib)..."
332 dump_verify_restore $SRC_LOOPDEV $SRC_MOUNTPOINT $DEST_LOOPDEV $DEST_MOUNTPOINT $DUMPFILE -z2
333 if [ $? -ne 0 ]; then
334 /bin/echo "dump cycle failed."
335 cleanup $SRC_FILENAME $SRC_MOUNTPOINT $DEST_FILENAME $DEST_MOUNTPOINT $BASEDIR $DUMPFILE
340 echo "testing compressed dump/restore (bzlib)..."
341 dump_verify_restore $SRC_LOOPDEV $SRC_MOUNTPOINT $DEST_LOOPDEV $DEST_MOUNTPOINT $DUMPFILE -j2
342 if [ $? -ne 0 ]; then
343 /bin/echo "dump cycle failed."
344 cleanup $SRC_FILENAME $SRC_MOUNTPOINT $DEST_FILENAME $DEST_MOUNTPOINT $BASEDIR $DUMPFILE
348 cleanup $SRC_FILENAME $SRC_MOUNTPOINT $DEST_FILENAME $DEST_MOUNTPOINT $BASEDIR $DUMPFILE
351 /bin/echo "# success!"