3 # Assorted useful functions used by the backup scripts.
6 print scalar(localtime),"\n";
9 # Set status info -- we write the current status to a file
10 # so if we hang or crash the last thing written to the file
11 # will tell us where we were when things went pear-shaped.
13 open S, ">this-status.new" or die $!;
14 print S $_[0],"\n" or die $!;
16 rename "this-status.new","this-status" or die $!;
19 # startprocess, endprocesses, killprocesses are
20 # used to implement the funky pipeline stuff.
21 sub startprocess ($$$) {
23 print LOG " $c\n" or die $!;
24 print " $c\n" or die $!;
25 defined($p= fork) or die $!;
26 if ($p) { $processes{$p}= $c; return; }
27 open STDIN,"$i" or die "$c stdin $i: $!";
28 open STDOUT,"$o" or die "$c stdout $o: $!";
30 exec $c; die "$c: $!";
34 while (keys %processes) {
35 $p= waitpid(-1,0) or die "wait: $!";
36 if (!exists $processes{$p}) { warn "unknown pid exited: $p, code $?\n"; next; }
38 delete $processes{$p};
39 $? && die "error: command gave code $?: $c\n";
41 print LOG " ok\n" or die $!;
42 print " ok\n" or die $!;
46 for $p (keys %processes) {
47 kill 15,$p or warn "kill process $p: $!";
52 # Read a fsys.foo filesystem group definition file.
53 # Syntax is: empty lines and those beginning with '#' are ignored.
54 # Trailing whitespace is ignored. Lines of the form 'prefix foo bar'
55 # are handled specially, as arex lines 'exclude regexp'; otherwise
56 # we just shove the line into @fsys and let parsefsys deal with it.
59 open F, "$etc/fsys.$fsnm" or die "Filesystems $fsnm unknown ($!).\n";
61 $_= <F> or die "unexpected EOF in $etc/fsys.$fsnm\n"; chomp; s/\s*$//;
65 if (m/^prefix\s+(\w+)\s+(\S.*\S)$/) {
67 } elsif (m/^prefix\-df\s+(\w+)\s+(\S.*\S)$/) {
69 } elsif (m/^excludedir\s+(\S.*\S)$/) {
71 } elsif (m/^exclude\s+(\S.*\S)$/) {
80 # Parse a line from a filesystem definition file. We expect the line
83 if ($tf =~ m,^(/\S*)\s+(\w+)$,) {
84 # Line of form '/file/system dumptype'
88 stat $atf or die "stat $atf: $!";
89 -d _ or die "not a dir: $atf";
91 } elsif ($tf =~ m,^(/\S*)\s+(\w+)\s+(\w+)$,) {
92 # Line of form '/file/system dumptype prefix'
93 # (used for remote backups, I think)
97 defined($prefix{$prefix}) or die "prefix $prefix in $tf ?\n";
98 $rstr= $prefix{$prefix}.' ';
105 open LOG, ">log" or die $!;
107 select(LOG); $|=1; select(STDOUT);
110 $SIG{'__DIE__'}= 'killprocesses';