X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-utils.git;a=blobdiff_plain;f=backup%2Fbackuplib.pl;h=174dc812c9678320c53328e31c0ea0d50a05cfd0;hp=ba1c50be01467958ded1c00873c1753870c5466a;hb=856172213e27f81e1d3a1a3d5585dd21c706bf90;hpb=17fb3a3831ca812a3ad384f4eec3b977432facd9 diff --git a/backup/backuplib.pl b/backup/backuplib.pl index ba1c50b..174dc81 100644 --- a/backup/backuplib.pl +++ b/backup/backuplib.pl @@ -23,6 +23,8 @@ require IO::File; +$nice='nice ' if !defined $nice; + sub printdate () { print scalar(localtime),"\n"; } @@ -51,6 +53,52 @@ sub startprocess ($$$) { exec $c; die "$c: $!"; } +sub rewind_raw () { + runsystem("mt -f $tape rewind"); +} + +sub readtapeid_raw () { + open T, ">>TAPEID" or die $!; close T; + unlink 'TAPEID' or die $!; + rewind_raw(); + system "mt -f $tape setblk $blocksizebytes"; $? and die $?; + system "dd if=$tape bs=${blocksize}b count=10 ". + "| tar -b$blocksize -vvxf - TAPEID"; +} + +sub runsystem ($) { + pboth(" $_[0]\n"); + system $_[0]; + $? and die $?; +} + +sub pboth ($) { + my ($str) = @_; + print LOG $str or die $!; + print $str or die $!; +} + +sub nexttapefile ($) { + my ($what) = @_; + $currenttapefilenumber++; + $currenttapefilename= $what; + pboth(sprintf "writing tape file #%d (mt fsf %d): %s\n", + $currenttapefilenumber, $currenttapefilenumber-1, $what); +} + +sub writetapeid ($$) { + open T, ">TAPEID" or die $!; + print T "$_[0]\n$_[1]\n" or die $!; + close T or die $!; + + $currenttapefilenumber= 0; + nexttapefile('TAPEID'); + + system "tar -b$blocksize -vvcf TAPEID.tar TAPEID"; $? and die $?; + system "dd if=TAPEID.tar of=$ntape bs=${blocksize}b count=10"; + $? and die $?; +} + sub endprocesses () { while (keys %processes) { $p= waitpid(-1,0) or die "wait: $!"; @@ -59,8 +107,7 @@ sub endprocesses () { delete $processes{$p}; $? && die "error: command gave code $?: $c\n"; } - print LOG " ok\n" or die $!; - print " ok\n" or die $!; + pboth(" ok\n"); } sub killprocesses { @@ -117,22 +164,55 @@ sub readfsys ($) { # Parse a line from a filesystem definition file. We expect the line # to be in $tf. sub parsefsys () { - if ($tf =~ m,^(/\S*)\s+(\w+)$,) { - # Line of form '/file/system dumptype' + my ($dopts,$dopt); + if ($tf =~ m#^(/\S*)\s+(\w+)([,=0-9a-z]*)$#) { + # Line of form '[/device:]/file/system dumptype[,options]' $atf= $1; $tm= $2; + $dopts= $3; $prefix= ''; + $pcstr= ''; stat $atf or die "stat $atf: $!"; -d _ or die "not a dir: $atf"; $rstr= ''; - } elsif ($tf =~ m,^(/\S*)\s+(\w+)\s+(\w+)$,) { - # Line of form '/file/system dumptype prefix' - # (used for remote backups, I think) + } elsif ($tf =~ m#^(/\S*)\s+(\w+)([,=0-9a-z]*)\s+(\w+)$#) { + # Line of form '[/device:]/file/system dumptype[,options] prefix' + # (used for remote backups) $atf= $1; $tm= $2; - $prefix= $3; + $dopts= $3; + $prefix= $4; + $pcstr= "$prefix:"; defined($prefix{$prefix}) or die "prefix $prefix in $tf ?\n"; $rstr= $prefix{$prefix}.' '; + } else { + die "fsys $tf ?"; + } + + $dev = $atf =~ s,^(.*)\:,, ? $1 : ''; + + undef %dopt; + foreach $dopt (split /\,/,$dopts) { + if (grep { $dopt eq $_ } qw(gz)) { + $dopt{$dopt}= 'y'; + } elsif ($dopt =~ m/\=/ && grep { $` eq $_ } qw(gz)) { + $dopt{$`}= $'; + } elsif (length $dopt) { + die "unknown option $dopt (in $dopts $tf)"; + } + } + + my ($gzo); + foreach $gzo (qw(gz gzi)) { + if ($dopt{$gzo} eq 'y') { + $$gzo= '1'; + } elsif ($dopt{$gzo} =~ m/^\d$/) { + $$gzo= $dopt{$gzo}; + } elsif (defined $dopt{$gzo}) { + die "$tf bad $gzo"; + } else { + $$gzo= ''; + } } }