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.
27 print scalar(localtime),"\n";
30 # Set status info -- we write the current status to a file
31 # so if we hang or crash the last thing written to the file
32 # will tell us where we were when things went pear-shaped.
34 open S, ">this-status.new" or die $!;
35 print S $_[0],"\n" or die $!;
37 rename "this-status.new","this-status" or die $!;
40 # startprocess, endprocesses, killprocesses are
41 # used to implement the funky pipeline stuff.
42 sub startprocess ($$$) {
44 print LOG " $c\n" or die $!;
45 print " $c\n" or die $!;
46 defined($p= fork) or die $!;
47 if ($p) { $processes{$p}= $c; return; }
48 open STDIN,"$i" or die "$c stdin $i: $!";
49 open STDOUT,"$o" or die "$c stdout $o: $!";
51 exec $c; die "$c: $!";
55 system "mt -f $tape rewind"; $? and die $?;
58 sub readtapeid_raw () {
59 open T, ">>TAPEID" or die $!; close T;
60 unlink 'TAPEID' or die $!;
62 system "mt -f $tape setblk $blocksizebytes"; $? and die $?;
63 system "dd if=$tape bs=${blocksize}b count=10 ".
64 "| tar -b$blocksize -vvxf - TAPEID";
68 open T, ">TAPEID" or die $!;
69 print T "$_[0]\n" or die $!;
72 system "tar -b$blocksize -vvcf TAPEID.tar TAPEID"; $? and die $?;
73 system "dd if=TAPEID.tar of=$ntape bs=${blocksize}b count=10";
78 while (keys %processes) {
79 $p= waitpid(-1,0) or die "wait: $!";
80 if (!exists $processes{$p}) { warn "unknown pid exited: $p, code $?\n"; next; }
82 delete $processes{$p};
83 $? && die "error: command gave code $?: $c\n";
85 print LOG " ok\n" or die $!;
86 print " ok\n" or die $!;
90 for $p (keys %processes) {
91 kill 15,$p or warn "kill process $p: $!";
96 # Read a fsys.foo filesystem group definition file.
97 # Syntax is: empty lines and those beginning with '#' are ignored.
98 # Trailing whitespace is ignored. Lines of the form 'prefix foo bar'
99 # are handled specially, as arex lines 'exclude regexp'; otherwise
100 # we just shove the line into @fsys and let parsefsys deal with it.
102 sub readfsysfile ($) {
105 $fh= new IO::File "$fn", "r" or die "cannot open fsys file $fn ($!).\n";
107 $!=0; $_= <$fh> or die "unexpected EOF in $fn ($!)\n";
112 if (m/^prefix\s+(\w+)\s+(\S.*\S)$/) {
114 } elsif (m/^prefix\-df\s+(\w+)\s+(\S.*\S)$/) {
116 } elsif (m/^excludedir\s+(\S.*\S)$/) {
118 } elsif (m/^exclude\s+(\S.*\S)$/) {
120 } elsif (m/^include\s+(\S.*\S)$/) {
122 $sfn =~ s/^\./fsys./;
123 $sfn = "$etc/$sfn" unless $sfn =~ m,^/,;
135 $fsf= "$etc/fsys.$fsnm";
136 stat $fsf or die "Filesystems $fsnm unknown ($!).\n";
140 # Parse a line from a filesystem definition file. We expect the line
143 if ($tf =~ m,^(/\S*)\s+(\w+)$,) {
144 # Line of form '/file/system dumptype'
148 stat $atf or die "stat $atf: $!";
149 -d _ or die "not a dir: $atf";
151 } elsif ($tf =~ m,^(/\S*)\s+(\w+)\s+(\w+)$,) {
152 # Line of form '/file/system dumptype prefix'
153 # (used for remote backups, I think)
157 defined($prefix{$prefix}) or die "prefix $prefix in $tf ?\n";
158 $rstr= $prefix{$prefix}.' ';
165 open LOG, ">log" or die $!;
167 select(LOG); $|=1; select(STDOUT);
170 $SIG{'__DIE__'}= 'killprocesses';