Whamcloud - gitweb
c1fee969f8f5d1aafd4236ab87e37af21b999874
[fs/lustre-release.git] / lustre / demos / snapsetup.sh
1 #! /bin/bash
2 # Utility script to create an OBD snapshot.  If an existing filesystem is
3 # not already mounted on /mnt/obd, we call the basic OBD setup script to
4 # create and mount a filesystem for us.
5 OBDDIR="`dirname $0`/.."
6 . $OBDDIR/demos/config.sh
7
8
9 # prepare the snapshot drive with a file to be COW'd
10 mount | grep "$MNTOBD " > /dev/null 2>&1
11 if [ x$? = x0 ]; then 
12     echo "Stuff still mounted on $MNTOBD; clean up first."
13     exit 
14 fi
15
16 if [ ! -d /mnt/obd/lost+found ]; then 
17     $OBDDIR/demos/obdfssetup.sh
18     if [ x$? != x0 ]; then 
19         echo "Error running obdfssetup.sh"
20         exit 4
21    fi
22 fi
23
24 if [ ! -f $MNTOBD/hello ]; then
25         $OBDDIR/demos/obdtest.sh
26         if [ x$? != x0 ]; then 
27             echo "Error in obdfssetup.sh"
28         exit 4
29     fi
30 fi
31
32 umount $MNTOBD
33
34 insmod $OBDDIR/snap/obdsnap.o
35
36 rm -f $SNAPTABLE
37
38 plog log "NEW SNAP SETUP"
39 # Create two snapshots using the OBD snapshot driver.  One will be the
40 # "current" snapshot (in obd device 1), where changes will take place.
41 # The current snapshot is required in order to use the filesystem.  The
42 # second will be a snapshot of the filesystem taken "now" (in obd device 2)
43 # that will remain static (historical read-only) filesystem as changes
44 # are made to the current snapshot.
45 $OBDDIR/class/obdcontrol -f << EOF
46 snaptable
47 $SNAPTABLE
48 a
49 1
50 current
51 a
52 2
53 now
54 q
55 y
56 snapset 0 $SNAPTABLE
57 device /dev/obd1
58 attach snap_obd 0 1 0
59 setup
60 device /dev/obd2
61 attach snap_obd 0 2 0
62 setup
63 quit
64 EOF
65
66 # Mount the two filesystems.  The filesystem under $MNTOBD will be the
67 # one where changes are made, while $MNTSNAP will contain the original
68 # files at the point when the snapshot was taken.
69
70 [ ! -d "$MNTOBD" ] &&  mkdir $MNTOBD
71 [ ! -d "$MNTSNAP" ] &&  mkdir $MNTSNAP
72 plog mount -t obdfs -odevice=/dev/obd1 none $MNTOBD
73 plog mount -t obdfs -oro,device=/dev/obd2 none $MNTSNAP