X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-utils.git;a=blobdiff_plain;f=backup%2Fbackuplib.pl;h=cbbe6f4619b5612f248eb86cc70289ed6ab773dc;hp=1c6b64c4ceb62c4d59e5d869cdf264eea62cc08f;hb=refs%2Fheads%2Fwip.with-lock-ex-t;hpb=7d4185f54b99fef18f8661ea1d5974171f997f1e diff --git a/backup/backuplib.pl b/backup/backuplib.pl index 1c6b64c..cbbe6f4 100644 --- a/backup/backuplib.pl +++ b/backup/backuplib.pl @@ -5,12 +5,13 @@ # other UN*X-compatible machines, as used on chiark.greenend.org.uk. # # chiark backup is: -# Copyright (C) 1997-1998,2000-2001 Ian Jackson +# Copyright (C) 1997-1998,2000-2001,2007 +# Ian Jackson # Copyright (C) 1999 Peter Maydell # # This is free software; you can redistribute it and/or modify it under the # terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2, or (at your option) any later version. +# Foundation; either version 3, or (at your option) any later version. # # This is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS @@ -18,8 +19,8 @@ # details. # # You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# with this program; if not, consult the Free Software Foundation's +# website at www.fsf.org, or the GNU Project website at www.gnu.org. require IO::File; @@ -173,8 +174,6 @@ sub parsefsys () { $dopts= $3; $prefix= ''; $pcstr= ''; - stat $atf or die "stat $atf: $!"; - -d _ or die "not a dir: $atf"; $rstr= ''; } elsif ($tf =~ m#^(/\S*)\s+(\w+)([,=0-9a-z]*)\s+(\w+)$#) { # Line of form '[/device:]/file/system dumptype[,options] prefix' @@ -190,13 +189,23 @@ sub parsefsys () { die "fsys $tf ?"; } + $fsidstr= $pcstr.$atf; + $fsidstr =~ s/[,+]/+$&/g; + $fsidstr =~ s#/#,#g; + $fsidfile= "/var/lib/chiark-backup/incstamp,$fsidstr"; + $dev = $atf =~ s,^(.*)\:,, ? $1 : ''; + if (!length $pcstr) { + stat $atf or die "stat $atf: $!"; + -d _ or die "not a dir: $atf"; + } + undef %dopt; foreach $dopt (split /\,/,$dopts) { - if (grep { $dopt eq $_ } qw(gz)) { + if (grep { $dopt eq $_ } qw(gz noinc)) { $dopt{$dopt}= 'y'; - if (grep { $dopt eq $_ } qw(snap)) { + } elsif (grep { $dopt eq $_ } qw(snap)) { $dopt{$dopt}= $dopt; } elsif ($dopt =~ m/\=/ && grep { $` eq $_ } qw(gz snap)) { $dopt{$`}= $'; @@ -217,25 +226,38 @@ sub parsefsys () { $$gzo= ''; } } + + if (length $dopt{'snap'}) { + length $dev or die "$pcstr:$atf no device but needed for snap"; + } +} + +sub execute ($) { + pboth(" $_[0]\n"); + system $_[0]; $? and die "$_[0] $?"; } sub prepfsys () { + $dev_print= $dev; + $atf_print= $atf; + if (length $dopt{'snap'}) { + system('snap-drop'); $? and die $?; $snapscripts= '/etc/chiark-backup/snap'; - $snapbase= "$pcstr $snapscripts/$dopt{'snap'} /var/lib/chiark-backup"; + $snapbase= "$rstr $snapscripts/$dopt{'snap'}"; + $snapargs= "/var/lib/chiark-backup"; - $snapsnap= "$snapbase snap $dev $atf"; - $snapdrop= "$snapbase drop"; + $snapsnap= "$snapbase snap $snapargs $dev $atf"; + $snapdrop= "$snapbase drop $snapargs"; 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 $?; + execute($snapsnap); $dev_nosnap= $dev; $atf_nosnap= $atf;