chiark / gitweb /
@@ -1,3 +1,9 @@
authorianmdlvl <ianmdlvl>
Sun, 21 Sep 2003 19:09:08 +0000 (19:09 +0000)
committerianmdlvl <ianmdlvl>
Sun, 21 Sep 2003 19:09:08 +0000 (19:09 +0000)
+chiark-utils (4.0.99.0.1) unstable; urgency=low
+
+  * backup: new lvm/remount-ro snapshotting feature.
+
+ --
+
 chiark-utils (4.0.0) unstable; urgency=medium

   New programs and utilities:

backup/Makefile
backup/backuplib.pl
backup/driver
backup/examples/chiark/settings.sh [new file with mode: 0755]
backup/full
backup/increm
backup/iwjbackup.txt
backup/lvm [new file with mode: 0755]
backup/remount [new file with mode: 0755]
backup/snap-drop [new file with mode: 0755]
debian/changelog

index 91f76640fbadd683ddd3488093fc32890822d38c..ce06ceef824f6a70d63b2264a1b90c0b252b08fa 100644 (file)
@@ -28,17 +28,20 @@ include ../settings.make
 BINSCRIPTS=    checkallused loaded driver takedown whatsthis labeltape
 SHARESCRIPTS=  bringup full increm
 SHAREFILES=    backuplib.pl
+SNAPKINDS=     lvm remount
 
 EXAMPLES=      relativity chiark
 
 all:
 
 install:               all
-               $(INSTALL_DIRECTORY) $(confdir) $(bindir) $(sharedir) $(vardir) $(man1dir)
+               $(INSTALL_DIRECTORY) $(confdir) $(confdir)/snap $(bindir) \
+                       $(sharedir) $(vardir) $(man1dir)
                set -e; for s in $(BINSCRIPTS); do \
                        $(INSTALL_SCRIPT) $$s $(bindir)/backup-$$s; done
                $(INSTALL_SHARE) $(SHAREFILES) $(sharedir)
                $(INSTALL_SCRIPT) $(SHARESCRIPTS) $(sharedir)
+               $(INSTALL_SCRIPT) $(SNAPKINDS) $(confdir)/snap
 
 install-docs:
                $(INSTALL_DIRECTORY) $(txtdocdir)
index 174dc812c9678320c53328e31c0ea0d50a05cfd0..1c6b64c4ceb62c4d59e5d869cdf264eea62cc08f 100644 (file)
@@ -43,8 +43,7 @@ sub setstatus ($) {
 # used to implement the funky pipeline stuff.
 sub startprocess ($$$) {
     my ($i,$o,$c) = @_;
-    print LOG "  $c\n" or die $!;
-    print "  $c\n" or die $!;
+    pboth("  $c\n");
     defined($p= fork) or die $!;
     if ($p) { $processes{$p}= $c; return; }
     open STDIN,"$i" or die "$c stdin $i: $!";
@@ -137,6 +136,8 @@ sub readfsysfile ($) {
            $prefix{$1}= $2;
        } elsif (m/^prefix\-df\s+(\w+)\s+(\S.*\S)$/) {
            $prefixdf{$1}= $2;
+       } elsif (m/^snap(?:\=(\w+))?\s+(\w+)\s+(\w+)$/) {
+            push @excldir,$1;
        } elsif (m/^excludedir\s+(\S.*\S)$/) {
             push @excldir,$1;
         } elsif (m/^exclude\s+(\S.*\S)$/) {
@@ -195,7 +196,9 @@ sub parsefsys () {
     foreach $dopt (split /\,/,$dopts) {
        if (grep { $dopt eq $_ } qw(gz)) {
            $dopt{$dopt}= 'y';
-       } elsif ($dopt =~ m/\=/ && grep { $` eq $_ } qw(gz)) {
+       if (grep { $dopt eq $_ } qw(snap)) {
+           $dopt{$dopt}= $dopt;
+       } elsif ($dopt =~ m/\=/ && grep { $` eq $_ } qw(gz snap)) {
            $dopt{$`}= $';
        } elsif (length $dopt) {
            die "unknown option $dopt (in $dopts $tf)";
@@ -216,6 +219,37 @@ sub parsefsys () {
     }
 }
 
+sub prepfsys () {
+    if (length $dopt{'snap'}) {
+       system('snap-drop'); $? and die $?;
+       
+       $snapscripts= '/etc/chiark-backup/snap';
+       $snapbase= "$pcstr $snapscripts/$dopt{'snap'} /var/lib/chiark-backup";
+
+       $snapsnap= "$snapbase snap $dev $atf";
+       $snapdrop= "$snapbase drop";
+
+       open SD, ">snap-drop.new" or die $!;
+       print SD $snapdrop,"\n" or die $!;
+       close SD or die $!;
+       rename "snap-drop.new","snap-drop" or die $!;
+
+       pboth("  $snapsnap\n");
+       system $snapsnap; $? and die $?;
+
+       $dev_nosnap= $dev;
+       $atf_nosnap= $atf;
+       $dev= "/var/lib/chiark-backup/snap-device";
+       $atf= "/var/lib/chiark-backup/snap-mount";
+    }
+}
+
+sub finfsys () {
+    if (length $dopt{'snap'}) {
+       system('snap-drop'); $? and die $?;
+    }
+}
+
 sub openlog () {
     unlink 'log';
     $u= umask(007);
index bdf3b38c44e140397b1bc63b5ee1999c62ac5204..36d9c1f23a03917c7f3364f322ddb99e234e775c 100755 (executable)
@@ -37,6 +37,7 @@ echo 'FAILED to start dump script' >this-status
 # both full and incremental backups, according to the ID of the
 # tape in the drive.
 full 2>&1 | tee this-log
+snap-drop 2>&1 | tee this-log
 
 status=`cat this-status 2>/dev/null`
 
diff --git a/backup/examples/chiark/settings.sh b/backup/examples/chiark/settings.sh
new file mode 100755 (executable)
index 0000000..06d5a97
--- /dev/null
@@ -0,0 +1,7 @@
+# shell script fragment setting options
+# defaults for currently implemented parameters are
+#lvm_lv=chiark_backup
+#lvm_lvsize_opts=-L <size of space currently used on fs>
+#lvm_lvtools_opts='-A n'
+#lvm_lvcreate_opts=
+#lvm_lvcreate_args=
index a46726077e414ff1275606931562672a82b4024c..9c603b9affbf80b9cd75b4f1b6cbbd557388d04e 100755 (executable)
@@ -186,6 +186,7 @@ foreach $exc (@excl) {
 for $tf (@fsys) {
     printdate();
     parsefsys();
+    prepfsys();
 
     pipe(FINDOR,FINDOW) or die $!;
     pipe(DUMPOR,DUMPOW) or die $!;
@@ -249,6 +250,8 @@ for $tf (@fsys) {
     push @tapefilesizes, [ $1, $currenttapefilename ];
     $totalrecords += $1;
     pboth("total blocks written so far: $totalrecords\n");
+
+    finfsys();
 }
 
 # The backup should now be complete; verify it
index 57a037dc31cadce80345a60b3cc5395a24a6563e..ac220957edb2d4f0d470fa4235514afae345b091 100755 (executable)
@@ -88,6 +88,7 @@ setstatus "PROBLEMS during incremental dump";
 for $tf (@fsys) {
 
     parsefsys();
+    prepfsys();
     
     $bufir='DUMPOR';
     $ddcmd= "$nasty dd ibs=$softblocksizebytes obs=$blocksizebytes of=$ntape";
@@ -126,6 +127,8 @@ for $tf (@fsys) {
     # advance is a file counter, so it needs to be updated for each 
     # dump we do to tape.
     $advance++;
+
+    finfsys();
 }
 
 # Rewind the tape, and increment the counter of incremental backups.
index 5de4276dcb28d30b13ee6edb7646c9b1de5dac59..39000ee29c74221a4dfa55a15d3b3f14b7ae9a00 100644 (file)
@@ -15,6 +15,9 @@ brought down to do backups. The defaults are fine.
 settings.pl: generic config file: in particular, the name of the tape
 device is set here.
 
+settings.sh: generic config file for shell scripts.  Currently only
+contains some options for the lvm snapshotter.
+
 tape.*: conventionally, each tape you're going to use in the backup
 cycle has a tape number, a name and a config file.  The tape numbers
 in use at Relativity are digit strings like `512'.  The name is a
@@ -69,12 +72,19 @@ volumes, requires device name).  Only `dump' type backups perform
 incremental backups.
 
 <options> is a comma-separated list of <option> or <option>=<value>.
-The only currently support options are gz[i][=<compressionlevel>], to
-indicate that the whole stream should be compressed with gzip.  The
-compression level defaults to 1 if gz is specified by the level isn't.
-gzi appliies only to the incrementals; gz applies to both unless gzi
-is also specified.  compression level 0 means not to run gzip at all
-and is the default if gz[i] is not mentioned.
+Options supported:
+
+  gz[i][=<compressionlevel>]
+    Indicates that the whole stream should be compressed with gzip.
+    The compression level defaults to 1 if gz is specified by the
+    level isn't.  gzi appliies only to the incrementals; gz applies to
+    both unless gzi is also specified.  compression level 0 means not
+    to run gzip at all and is the default if gz[i] is not mentioned.
+
+  snap=<snapkind>
+    Indicates that the filesystem should be frozen before the backup
+    by using /etc/chiark-backup/snap/<snapkind>.  See the head comment
+    in /etc/chiark-backup/snap/lvm for details of how this works.
 
 expected-diffs is a config file to indicate which 
 filesystems should *not* be backed up. The scripts do a config
diff --git a/backup/lvm b/backup/lvm
new file mode 100755 (executable)
index 0000000..3e9cc2b
--- /dev/null
@@ -0,0 +1,84 @@
+#!/bin/sh
+# invoked by backup scripts as
+#    lvm snap $vardir $device $mountpoint
+#              creates and mounts on $vardir/snap-mount
+#              creates $vardir/snap-device -> device
+#    lvm drop $vardir
+
+set -e
+
+nargs=$#
+opmode="$1"
+vardir="$2"
+device="$3"
+mountpoint="$4"
+
+lvm_lv=chiark-backup
+lvm_lvtools_opts='-A n'
+lvm_lvcreate_opts=
+lvm_lvcreate_args=
+
+test ! -f /etc/chiark-backup/settings.sh || . /etc/chiark-backup/settings.sh
+
+case "$nargs.$opmode" in
+4.snap|2.drop)
+       ;;
+*)
+       cat >&2 <<'END'
+usage: .../lvm snap VARDIR DEV MOUNT
+       .../lvm drop VARDIR
+END
+       exit 1
+       ;;
+esac
+
+
+#---------- clean up anything
+
+umount -v "$snmnt" || true
+test ! -d "$snmnt" || rmdir -- "$snmnt"
+
+set +e
+old_lv_dev="$(readlink $vardir/snap-device)"
+rc=$?
+set -e
+
+if [ $rc = 0 ]; then
+       set +e
+       lvchange    $lvm_lvtools_opts -a n $old_lv_dev
+       lvremove -f $lvm_lvtools_opts      $old_lv_dev
+       set -e
+       rm $vardir/snap-device
+fi
+
+if test "$opmode" = drop; then
+       echo 'lvm snap dropped'
+       exit 0
+fi
+
+#---------- create snapshot
+
+fstype="$(mount | sed -n \
+ "s,^$device on $mountpoint type \([a-z0-9][a-z0-9]*\) .*,-t \1 ,p")"
+
+if [ -z "$lvm_lvsize_opts" ]; then
+       df="$(df -k $device)"
+       blocks="$(printf "%s" "$df" |  sed -n '2,$s,^/dev/[^    ]*[     ][      ]*[0-9][0-9]*[  ][      ]*\([0-9][0-9]*\)[      ].*,\1,p')"
+       lvm_lvsize_opts="-L $blocks"K
+fi
+
+lvpath="$(dirname "$device")/$lvm_lv"
+
+ln -s -- "$lvpath" "$vardir"/snap-device
+
+sync
+lvcreate -s \
+       $lvm_lvtools_opts \
+       $lvm_lvsize_opts \
+       -n $lvm_lv \
+       $lvm_lvcreate_opts "$device" $lvm_lvcreate_args
+
+mkdir -- "$snmnt"
+mount -v -r $fstype $lvm_mount_opts "$lvpath" "$snmnt"
+
+echo 'lvm snap activated'
diff --git a/backup/remount b/backup/remount
new file mode 100755 (executable)
index 0000000..ce7a4bb
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+set -e
+
+removes () {
+       rm -f -- "$vardir/snap-mount" "$vardir/snap-device"
+}
+
+vardir="$2"
+
+case "$#.$1" in
+2.drop)
+       fs="$(readlink "$vardir/snap-mount")"
+       removes
+       mount -vo remount,rw "$fs" || true
+       ;;
+4.snap)
+       removes
+       mount -vo remount,ro "$4"
+       ln -s -- "$3" "$vardir/snap-device"
+       ln -s -- "$4" "$vardir/snap-mount"
+       ;;
+*)
+       cat >&2 <<'END'
+usage: .../remount snap VARDIR DEV MOUNT
+       .../remount drop VARDIR
+END
+       exit 1
+       ;;
+esac
diff --git a/backup/snap-drop b/backup/snap-drop
new file mode 100755 (executable)
index 0000000..39deaf1
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+set -e
+vd=/var/lib/chiark-backup
+cd "$vd"
+test -f snap-drop
+sh -x snap-drop || true
+rm snap-drop
index 6a59ebeda0c97b5eee23eaad3b779ac5f0ff310d..4b4ca5c4acd096dfc51c40159c1eae2c9cca8635 100644 (file)
@@ -1,3 +1,9 @@
+chiark-utils (4.0.99.0.1) unstable; urgency=low
+
+  * backup: new lvm/remount-ro snapshotting feature.
+
+ --
+
 chiark-utils (4.0.0) unstable; urgency=medium
 
   New programs and utilities: