chiark / gitweb /
@@ -3,6 +3,7 @@
[chiark-utils.git] / backup / backuplib.pl
index 26a8533d1150e85ee3e2fa7079f742ddf2df5647..50cc70a745f9aa070ed6778f12e3455c3df1303a 100644 (file)
 # with this program; if not, write to the Free Software Foundation, Inc.,
 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 # 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;
+
+$nice='nice ' if !defined $nice;
+
 sub printdate () {
     print scalar(localtime),"\n";
 }
 sub printdate () {
     print scalar(localtime),"\n";
 }
@@ -49,6 +53,29 @@ sub startprocess ($$$) {
     exec $c; die "$c: $!";
 }
 
     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$_[1]\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: $!";
 sub endprocesses () {
     while (keys %processes) {
        $p= waitpid(-1,0) or die "wait: $!";
@@ -93,14 +120,15 @@ sub readfsysfile ($) {
         } elsif (m/^exclude\s+(\S.*\S)$/) {
             push @excl,$1;
        } elsif (m/^include\s+(\S.*\S)$/) {
         } elsif (m/^exclude\s+(\S.*\S)$/) {
             push @excl,$1;
        } elsif (m/^include\s+(\S.*\S)$/) {
+           $sfn = $1;
            $sfn =~ s/^\./fsys./;
            $sfn =~ s/^\./fsys./;
-           $sfn = "$etc/$sfn" if $sfn !~ m,^/,;
+           $sfn = "$etc/$sfn" unless $sfn =~ m,^/,;
            readfsysfile($sfn);
         } else {
            push @fsys,$_;
        }
     }
            readfsysfile($sfn);
         } else {
            push @fsys,$_;
        }
     }
-    close $fn or die $!;
+    close $fh or die $!;
 }
 
 sub readfsys ($) {
 }
 
 sub readfsys ($) {
@@ -114,22 +142,55 @@ sub readfsys ($) {
 # Parse a line from a filesystem definition file. We expect the line
 # to be in $tf.
 sub parsefsys () {
 # 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'
+    my ($dopts,$dopt);
+    if ($tf =~ m#^(/\S*)\s+(\w+)([,=0-9a-z]*)$#) {
+        # Line of form '[/device:]/file/system dumptype[,options]'
        $atf= $1;
        $tm= $2;
        $atf= $1;
        $tm= $2;
+       $dopts= $3;
        $prefix= '<local>';
        $prefix= '<local>';
+       $pcstr= '';
        stat $atf or die "stat $atf: $!";
        -d _ or die "not a dir: $atf";
        $rstr= '';
        stat $atf or die "stat $atf: $!";
        -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)
+    } elsif ($tf =~ m#^(/\S*)\s+(\w+)([,=0-9a-z]*)\s+(\w+)$#) {
+        # Line of form '[/device:]/file/system dumptype[,options] prefix'
+        # (used for remote backups)
        $atf= $1;
        $tm= $2;
        $atf= $1;
        $tm= $2;
-       $prefix= $3;
+       $dopts= $3;
+       $prefix= $4;
+       $pcstr= "$prefix:";
        defined($prefix{$prefix}) or die "prefix $prefix in $tf ?\n";
        $rstr= $prefix{$prefix}.' ';
        defined($prefix{$prefix}) or die "prefix $prefix in $tf ?\n";
        $rstr= $prefix{$prefix}.' ';
+    } else {
+       die "fsys $tf ?";
+    }
+
+    $dev = $atf =~ s,^(.*)\:,, ? $1 : '';
+
+    undef %dopt;
+    foreach $dopt (split /\,/,$dopts) {
+       if (grep { $dopt eq $_ } qw(gz)) {
+           $dopt{$dopt}= 'y';
+       } elsif ($dopt =~ m/\=/ && grep { $` eq $_ } qw(gz)) {
+           $dopt{$`}= $';
+       } elsif (length $dopt) {
+           die "unknown option $dopt (in $dopts $tf)";
+       }
+    }
+
+    my ($gzo);
+    foreach $gzo (qw(gz gzi)) {
+       if ($dopt{$gzo} eq 'y') {
+           $$gzo= '1';
+       } elsif ($dopt{$gzo} =~ m/^\d$/) {
+           $$gzo= $dopt{$gzo};
+       } elsif (defined $dopt{$gzo}) {
+           die "$tf bad $gzo";
+       } else {
+           $$gzo= '';
+       }
     }
 }
 
     }
 }