chiark / gitweb /
From Peter Maydell (/u2/pmaydell/iwjbackup/) as per <E156bwm-0005xq-00@watchdragon...
[chiark-utils.git] / backup / backuplib.pl
index d412c9400776e47dc40539cf40628e34e95e9209..70d28b3e3d1c914fedb08f9e8d977af2b4bc7549 100644 (file)
@@ -1,9 +1,14 @@
 #
 
+# Assorted useful functions used by the backup scripts.
+
 sub printdate () {
     print scalar(localtime),"\n";
 }
 
+# Set status info -- we write the current status to a file 
+# so if we hang or crash the last thing written to the file
+# will tell us where we were when things went pear-shaped.
 sub setstatus ($) {
     open S, ">this-status.new" or die $!;
     print S $_[0],"\n" or die $!;
@@ -11,6 +16,8 @@ sub setstatus ($) {
     rename "this-status.new","this-status" or die $!;
 }
 
+# startprocess, endprocesses, killprocesses are 
+# used to implement the funky pipeline stuff.
 sub startprocess ($$$) {
     my ($i,$o,$c) = @_;
     print LOG "  $c\n" or die $!;
@@ -42,28 +49,41 @@ sub killprocesses {
     undef %processes;
 }
 
+# Read a fsys.foo filesystem group definition file.
+# Syntax is: empty lines and those beginning with '#' are ignored.
+# 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";
     for (;;) {
-       $_= <F> or die; chomp; s/\s*$//;
+       $_= <F> or die "unexpected EOF in $etc/fsys.$fsnm\n"; chomp; s/\s*$//;
        last if m/^end$/;
        next unless m/\S/;
        next if m/^\#/;
        if (m/^prefix\s+(\w+)\s+(\S.*\S)$/) {
            $prefix{$1}= $2;
            next;
-       } elsif (m/^prefix\-df\s+(\w+)\s+(\S.*\S)$/) {
-           $prefixdf{$1}= $2;
-           next;
        }
+        if (m/^excludedir\s+(\S.*\S)$/) {
+            push @excldir,$1;
+            next;
+        }
+        if (m/^exclude\s+(\S.*\S)$/) {
+            push @excl,$1;
+            next;
+        }
        push @fsys,$_;
     }
     close F or die $!;
 }
 
+# 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'
        $atf= $1;
        $tm= $2;
        $prefix= '<local>';
@@ -71,6 +91,8 @@ sub parsefsys () {
        -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)
        $atf= $1;
        $tm= $2;
        $prefix= $3;