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)
# 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: $!";
$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)$/) {
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)";
}
}
+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);
# 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`
--- /dev/null
+# 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=
for $tf (@fsys) {
printdate();
parsefsys();
+ prepfsys();
pipe(FINDOR,FINDOW) or die $!;
pipe(DUMPOR,DUMPOW) or die $!;
push @tapefilesizes, [ $1, $currenttapefilename ];
$totalrecords += $1;
pboth("total blocks written so far: $totalrecords\n");
+
+ finfsys();
}
# The backup should now be complete; verify it
for $tf (@fsys) {
parsefsys();
+ prepfsys();
$bufir='DUMPOR';
$ddcmd= "$nasty dd ibs=$softblocksizebytes obs=$blocksizebytes of=$ntape";
# 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.
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
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
--- /dev/null
+#!/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'
--- /dev/null
+#!/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
--- /dev/null
+#!/bin/sh
+set -e
+vd=/var/lib/chiark-backup
+cd "$vd"
+test -f snap-drop
+sh -x snap-drop || true
+rm snap-drop
+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: