chiark / gitweb /
@@ -3,6 +3,7 @@
[chiark-utils.git] / backup / full
index 668b5fdaec6fa9216e1ad1c7bcd1fe299261de2a..c25f2d0b96cd47daa1cd65532a32a24ae24c9927 100755 (executable)
@@ -30,12 +30,29 @@ BEGIN {
 
 $|=1;
 
+while (@ARGV) {
+    $_= shift @ARGV;
+    if (m/^\-\-no\-reten$/) {
+       $noreten=1;
+    } elsif (m/^\-\-no\-config\-check$/) {
+       $nocheck=1;
+    } else {
+       die "unknown option/argument \`$_'\n";
+    }
+}
+
 # Check to see whether the tape.nn and fsys.nn files are sane.
 # checkallused checks that all the filesystems mounted are in fact
 # dumped in both full and incremental dumps.
-setstatus "FAILED configuration check";
-print "Configuration check ...\n" or die $!;
-system 'backup-checkallused'; $? and die $?;
+
+if (!$nocheck) {
+    setstatus "FAILED configuration check";
+    print "Configuration check ...\n" or die $!;
+    system 'backup-checkallused'; $? and die $?;
+} else {
+    setstatus "FAILED rewinding";
+    rewind_raw();
+}
 
 printdate();
 
@@ -128,13 +145,15 @@ openlog();
 $doing= "dump of $fsys to tape $tapedesc in drive $tape";
 print LOG "$doing:\n" or die $!;
 
-setstatus "FAILED retensioning";
-system "mt -f $tape reten"; $? and die $?;
+if (!$noreten) {
+    setstatus "FAILED retensioning";
+    system "mt -f $tape reten"; $? and die $?;
+}
 
 setstatus "FAILED writing tape ID";
 # First write the tape ID to this tape.
 
-writetapeid($tapeid);
+writetapeid($tapeid,$tapedesc);
 
 unlink 'this-md5sums';
 
@@ -148,6 +167,7 @@ setstatus "FAILED during dump";
 sub closepipes () {
     close(DUMPOR); close(TEEOR); close(BUFOR); close(FINDOR);
     close(DUMPOW); close(TEEOW); close(BUFOW); close(FINDOW);
+    close(GZOR); close(GZOW);
 }
 
 # work out a find option string that will exclude the required files    
@@ -163,16 +183,26 @@ foreach $exc (@excl) {
 # For each filesystem to be put on this tape:
 for $tf (@fsys) {
     printdate();
+    parsefsys();
+
     pipe(FINDOR,FINDOW) or die $!;
     pipe(DUMPOR,DUMPOW) or die $!;
     pipe(TEEOR,TEEOW) or die $!;
     pipe(BUFOR,BUFOW) or die $!;
-    parsefsys();
+    
+    $bufir='TEEOR';
+    $ddcmd= "dd ibs=$softblocksizebytes obs=$blocksizebytes of=$ntape";
+
+    if ($gz) {
+       $bufir='GZOR';
+       pipe(GZOR,GZOW) or die $!;
+       $ddcmd .= " conv=sync";
+    }
     
     # We can back up via dump or cpio or zafio
+    $dumpin= '</dev/null';
     if ($tm eq 'dump') {
        $dumpcmd= "dump 0bfu $softblocksizekb - $atf";
-       $dumpin= '</dev/null';
     } elsif ($tm eq 'cpio') {
        startprocess '</dev/null','>&FINDOW',$rstr."find $atf -xdev -noleaf -print0";
        $dumpcmd= "cpio -Hustar -o0C$softblocksizebytes";
@@ -183,6 +213,8 @@ for $tf (@fsys) {
         # don't use verbose flag as this generates 2MB report emails :->
         $dumpcmd = "afio -b $softblocksizebytes -Zo -";
         $dumpin = '<&FINDOR';
+    } elsif ($tm eq 'ntfsimage') {
+       $dumpcmd= "ntfsimage -vvf --dirty $dev";
     } else {
        die "unknown method $tm for $prefix:$atf\n";
     }
@@ -190,13 +222,15 @@ for $tf (@fsys) {
     # to the exit status of all the commands in the pipeline.
     # It is roughly equivalent to:
     #    md5sum <p >>this-md5sums
-    #    dump <$dumpin | tee p | writebuffer | dd >/dev/null
-    startprocess '<p','>>this-md5sums','md5sum';
-    startprocess $dumpin,'>&DUMPOW',$rstr.$dumpcmd;
-    startprocess '<&DUMPOR','>&TEEOW','tee p';
-    startprocess '<&TEEOR','>&BUFOW','writebuffer';
-    startprocess '<&BUFOR','>/dev/null'
-       ,"dd ibs=$softblocksizebytes obs=$blocksizebytes of=$ntape";
+    #    dump <$dumpin | tee p [| gzip] | writebuffer | dd >/dev/null
+    startprocess '<p','>>this-md5sums',"$nice md5sum";
+    startprocess $dumpin,'>&DUMPOW',"$nice ".$rstr.$dumpcmd;
+    startprocess '<&DUMPOR','>&TEEOW',"$nice tee p";
+    if ($gz) {
+       startprocess '<&TEEOR','>&GZOW',"$nice gzip -v$gz";
+    }
+    startprocess "<&$bufir",'>&BUFOW',"$nasty writebuffer";
+    startprocess '<&BUFOR','>/dev/null',"$nasty $ddcmd";
     closepipes();
     endprocesses();
 }
@@ -213,9 +247,17 @@ system "mt -f $ntape fsf 1"; $? and die $?;
 open S,"this-md5sums" or die $!;
 for $tf (@fsys) {
     printdate();
-    chomp($orgsum= <S>);
+    parsefsys();
+    chomp($orgsum= <S>); $orgsum =~ s/\ +\-?$//;
     $orgsum =~ m/^[0-9a-fA-F]{32}$/i or die "orgsum \`$orgsum' ?";
-    chomp($csum= `dd if=$ntape ibs=$blocksizebytes | readbuffer | md5sum`);
+    $cmd= "$nasty dd if=$ntape ibs=$blocksizebytes";
+    $cmd .= " | $nasty readbuffer";
+    $cmd .= " | $nice gzip -vd" if $gz;
+    $cmd .= " | $nice md5sum";
+    print LOG "  $cmd\n" or die $!;
+    print "  $cmd\n" or die $!;
+    chomp($csum= `$cmd`);
+    $csum =~ s/\ +\-?$//;
     $orgsum eq $csum or die "MISMATCH $tf $csum $orgsum\n";
     print "checksum ok $csum\t$tf\n" or die $!;
     print LOG "checksum ok $csum\t$tf\n" or die $!;