4 # This file is part of chiark backup, a system for backing up GNU/Linux and
5 # other UN*X-compatible machines, as used on chiark.greenend.org.uk.
8 # Copyright (C) 1997-1998,2000-2001 Ian Jackson <ian@chiark.greenend.org.uk>
9 # Copyright (C) 1999 Peter Maydell <pmaydell@chiark.greenend.org.uk>
11 # This is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2, or (at your option) any later version.
15 # This is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20 # You should have received a copy of the GNU General Public License along
21 # with this program; if not, write to the Free Software Foundation, Inc.,
22 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 $nice='nice ' if !defined $nice;
29 print scalar(localtime),"\n";
32 # Set status info -- we write the current status to a file
33 # so if we hang or crash the last thing written to the file
34 # will tell us where we were when things went pear-shaped.
36 open S, ">this-status.new" or die $!;
37 print S $_[0],"\n" or die $!;
39 rename "this-status.new","this-status" or die $!;
42 # startprocess, endprocesses, killprocesses are
43 # used to implement the funky pipeline stuff.
44 sub startprocess ($$$) {
46 print LOG " $c\n" or die $!;
47 print " $c\n" or die $!;
48 defined($p= fork) or die $!;
49 if ($p) { $processes{$p}= $c; return; }
50 open STDIN,"$i" or die "$c stdin $i: $!";
51 open STDOUT,"$o" or die "$c stdout $o: $!";
53 exec $c; die "$c: $!";
57 runsystem("mt -f $tape rewind");
60 sub readtapeid_raw () {
61 open T, ">>TAPEID" or die $!; close T;
62 unlink 'TAPEID' or die $!;
64 system "mt -f $tape setblk $blocksizebytes"; $? and die $?;
65 system "dd if=$tape bs=${blocksize}b count=10 ".
66 "| tar -b$blocksize -vvxf - TAPEID";
77 print LOG $str or die $!;
81 sub nexttapefile ($) {
83 $currenttapefilenumber++;
84 $currenttapefilename= $what;
85 pboth(sprintf "writing tape file #%d (mt fsf %d): %s\n",
86 $currenttapefilenumber, $currenttapefilenumber-1, $what);
89 sub writetapeid ($$) {
90 open T, ">TAPEID" or die $!;
91 print T "$_[0]\n$_[1]\n" or die $!;
94 $currenttapefilenumber= 0;
95 nexttapefile('TAPEID');
97 system "tar -b$blocksize -vvcf TAPEID.tar TAPEID"; $? and die $?;
98 system "dd if=TAPEID.tar of=$ntape bs=${blocksize}b count=10";
102 sub endprocesses () {
103 while (keys %processes) {
104 $p= waitpid(-1,0) or die "wait: $!";
105 if (!exists $processes{$p}) { warn "unknown pid exited: $p, code $?\n"; next; }
107 delete $processes{$p};
108 $? && die "error: command gave code $?: $c\n";
114 for $p (keys %processes) {
115 kill 15,$p or warn "kill process $p: $!";
120 # Read a fsys.foo filesystem group definition file.
121 # Syntax is: empty lines and those beginning with '#' are ignored.
122 # Trailing whitespace is ignored. Lines of the form 'prefix foo bar'
123 # are handled specially, as arex lines 'exclude regexp'; otherwise
124 # we just shove the line into @fsys and let parsefsys deal with it.
126 sub readfsysfile ($) {
129 $fh= new IO::File "$fn", "r" or die "cannot open fsys file $fn ($!).\n";
131 $!=0; $_= <$fh> or die "unexpected EOF in $fn ($!)\n";
136 if (m/^prefix\s+(\w+)\s+(\S.*\S)$/) {
138 } elsif (m/^prefix\-df\s+(\w+)\s+(\S.*\S)$/) {
140 } elsif (m/^excludedir\s+(\S.*\S)$/) {
142 } elsif (m/^exclude\s+(\S.*\S)$/) {
144 } elsif (m/^include\s+(\S.*\S)$/) {
146 $sfn =~ s/^\./fsys./;
147 $sfn = "$etc/$sfn" unless $sfn =~ m,^/,;
159 $fsf= "$etc/fsys.$fsnm";
160 stat $fsf or die "Filesystems $fsnm unknown ($!).\n";
164 # Parse a line from a filesystem definition file. We expect the line
168 if ($tf =~ m#^(/\S*)\s+(\w+)([,=0-9a-z]*)$#) {
169 # Line of form '[/device:]/file/system dumptype[,options]'
175 stat $atf or die "stat $atf: $!";
176 -d _ or die "not a dir: $atf";
178 } elsif ($tf =~ m#^(/\S*)\s+(\w+)([,=0-9a-z]*)\s+(\w+)$#) {
179 # Line of form '[/device:]/file/system dumptype[,options] prefix'
180 # (used for remote backups)
186 defined($prefix{$prefix}) or die "prefix $prefix in $tf ?\n";
187 $rstr= $prefix{$prefix}.' ';
192 $dev = $atf =~ s,^(.*)\:,, ? $1 : '';
195 foreach $dopt (split /\,/,$dopts) {
196 if (grep { $dopt eq $_ } qw(gz)) {
198 } elsif ($dopt =~ m/\=/ && grep { $` eq $_ } qw(gz)) {
200 } elsif (length $dopt) {
201 die "unknown option $dopt (in $dopts $tf)";
206 foreach $gzo (qw(gz gzi)) {
207 if ($dopt{$gzo} eq 'y') {
209 } elsif ($dopt{$gzo} =~ m/^\d$/) {
211 } elsif (defined $dopt{$gzo}) {
222 open LOG, ">log" or die $!;
224 select(LOG); $|=1; select(STDOUT);
227 $SIG{'__DIE__'}= 'killprocesses';