X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=backup%2Fbackuplib.pl;h=e80f779ca0a6d77d8988d5ce85800c589a1a1626;hb=3358df8cd92a7f958b9918ad0e2ce9350edbb823;hp=37b3d7936f6c8bf3568739f77e5b56bcc315c6fd;hpb=d906fbd72072c6953922e0627bbcf3d4c62ce7c0;p=chiark-utils.git diff --git a/backup/backuplib.pl b/backup/backuplib.pl index 37b3d79..e80f779 100644 --- a/backup/backuplib.pl +++ b/backup/backuplib.pl @@ -21,6 +21,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +require IO::File; + sub printdate () { print scalar(localtime),"\n"; } @@ -49,6 +51,29 @@ sub startprocess ($$$) { exec $c; die "$c: $!"; } +sub rewind_raw () { + system "mt -f $tape rewind"; $? and die $?; +} + +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 writetapeid ($) { + open T, ">TAPEID" or die $!; + print T "$_[0]\n" or die $!; + close T or die $!; + + 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: $!"; @@ -73,11 +98,14 @@ sub killprocesses { # Trailing whitespace is ignored. Lines of the form 'prefix foo bar' # are handled specially, as arex lines 'exclude regexp'; otherwise # we just shove the line into @fsys and let parsefsys deal with it. -sub readfsys ($) { - my ($fsnm) = @_; - open F, "$etc/fsys.$fsnm" or die "Filesystems $fsnm unknown ($!).\n"; + +sub readfsysfile ($) { + my ($fn) = @_; + my ($fh,$sfn); + $fh= new IO::File "$fn", "r" or die "cannot open fsys file $fn ($!).\n"; for (;;) { - $_= or die "unexpected EOF in $etc/fsys.$fsnm\n"; chomp; s/\s*$//; + $!=0; $_= <$fh> or die "unexpected EOF in $fn ($!)\n"; + chomp; s/\s*$//; last if m/^end$/; next unless m/\S/; next if m/^\#/; @@ -89,11 +117,24 @@ sub readfsys ($) { push @excldir,$1; } elsif (m/^exclude\s+(\S.*\S)$/) { push @excl,$1; + } elsif (m/^include\s+(\S.*\S)$/) { + $sfn = $1; + $sfn =~ s/^\./fsys./; + $sfn = "$etc/$sfn" unless $sfn =~ m,^/,; + readfsysfile($sfn); } else { push @fsys,$_; } } - close F or die $!; + close $fh or die $!; +} + +sub readfsys ($) { + my ($fsnm) = @_; + my ($fsf); + $fsf= "$etc/fsys.$fsnm"; + stat $fsf or die "Filesystems $fsnm unknown ($!).\n"; + readfsysfile($fsf); } # Parse a line from a filesystem definition file. We expect the line