chiark / gitweb /
@@ -1,3 +1,9 @@
[chiark-utils.git] / backup / full
index ddd15ce215a2ff69e4c1ac4204b8c7efbec0bd3b..9c603b9affbf80b9cd75b4f1b6cbbd557388d04e 100755 (executable)
@@ -45,6 +45,8 @@ while (@ARGV) {
 # checkallused checks that all the filesystems mounted are in fact
 # dumped in both full and incremental dumps.
 
+openlog();
+
 if (!$nocheck) {
     setstatus "FAILED configuration check";
     print "Configuration check ...\n" or die $!;
@@ -140,14 +142,13 @@ if ($incremental) {
 
 # Read the filesystem group definition (file fsys.nnn)
 readfsys("$fsys");
-openlog();
 
 $doing= "dump of $fsys to tape $tapedesc in drive $tape";
 print LOG "$doing:\n" or die $!;
 
 if (!$noreten) {
     setstatus "FAILED retensioning";
-    system "mt -f $tape reten"; $? and die $?;
+    runsystem("mt -f $tape reten");
 }
 
 setstatus "FAILED writing tape ID";
@@ -168,6 +169,7 @@ sub closepipes () {
     close(DUMPOR); close(TEEOR); close(BUFOR); close(FINDOR);
     close(DUMPOW); close(TEEOW); close(BUFOW); close(FINDOW);
     close(GZOR); close(GZOW);
+    close(DDERRR); close(DDERRW);
 }
 
 # work out a find option string that will exclude the required files    
@@ -184,14 +186,17 @@ foreach $exc (@excl) {
 for $tf (@fsys) {
     printdate();
     parsefsys();
+    prepfsys();
 
     pipe(FINDOR,FINDOW) or die $!;
     pipe(DUMPOR,DUMPOW) or die $!;
     pipe(TEEOR,TEEOW) or die $!;
+    pipe(TEEOR,TEEOW) or die $!;
     pipe(BUFOR,BUFOW) or die $!;
+    pipe(DDERRR,DDERRW) or die $!;
     
     $bufir='TEEOR';
-    $ddcmd= "dd ibs=$softblocksizebytes obs=$blocksizebytes of=$ntape";
+    $ddcmd= "dd ibs=$softblocksizebytes obs=$blocksizebytes of=$ntape 2>&1";
 
     if ($gz) {
        $bufir='GZOR';
@@ -199,6 +204,8 @@ for $tf (@fsys) {
        $ddcmd .= " conv=sync";
     }
     
+    nexttapefile("full $prefix:$atf");
+
     # We can back up via dump or cpio or zafio
     $dumpin= '</dev/null';
     if ($tm eq 'dump') {
@@ -214,8 +221,7 @@ for $tf (@fsys) {
         $dumpcmd = "afio -b $softblocksizebytes -Zo -";
         $dumpin = '<&FINDOR';
     } elsif ($tm eq 'ntfsimage') {
-# fixme have to find device rather than mountpoint (atf is mountpoint)
-       $dumpcmd= "ntfsimage -vvf --dirty $atf";
+       $dumpcmd= "ntfsimage -svvf --dirty $dev";
     } else {
        die "unknown method $tm for $prefix:$atf\n";
     }
@@ -224,6 +230,7 @@ for $tf (@fsys) {
     # It is roughly equivalent to:
     #    md5sum <p >>this-md5sums
     #    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";
@@ -231,9 +238,20 @@ for $tf (@fsys) {
        startprocess '<&TEEOR','>&GZOW',"$nice gzip -v$gz";
     }
     startprocess "<&$bufir",'>&BUFOW',"$nasty writebuffer";
-    startprocess '<&BUFOR','>/dev/null',"$nasty $ddcmd";
+    startprocess '<&DDERRR','>/dev/null',"$nice tee dderr >&2";
+    startprocess '<&BUFOR','>&DDERRW',"$nasty $ddcmd";
     closepipes();
     endprocesses();
+
+    open DDERR, "dderr" or die $!;
+    defined(read DDERR,$_,1023) or die $!;
+    close DDERR;
+    m/\n(\d+)\+0 records out\n/ or die ">$dderr< ?";
+    push @tapefilesizes, [ $1, $currenttapefilename ];
+    $totalrecords += $1;
+    pboth("total blocks written so far: $totalrecords\n");
+
+    finfsys();
 }
 
 # The backup should now be complete; verify it
@@ -241,8 +259,8 @@ for $tf (@fsys) {
 setstatus "FAILED during check";
 
 # Rewind the tape and skip the TAPEID record
-system "mt -f $tape rewind"; $? and die $?;
-system "mt -f $ntape fsf 1"; $? and die $?;
+runsystem("mt -f $tape rewind");
+runsystem("mt -f $ntape fsf 1");
 
 # Check the md5sums match for each filesystem on the tape
 open S,"this-md5sums" or die $!;
@@ -255,8 +273,7 @@ for $tf (@fsys) {
     $cmd .= " | $nasty readbuffer";
     $cmd .= " | $nice gzip -vd" if $gz;
     $cmd .= " | $nice md5sum";
-    print LOG "  $cmd\n" or die $!;
-    print "  $cmd\n" or die $!;
+    pboth("  $cmd\n");
     chomp($csum= `$cmd`);
     $csum =~ s/\ +\-?$//;
     $orgsum eq $csum or die "MISMATCH $tf $csum $orgsum\n";
@@ -264,10 +281,26 @@ for $tf (@fsys) {
     print LOG "checksum ok $csum\t$tf\n" or die $!;
 }
 printdate();
-system "mt -f $tape rewind"; $? and die $?;
+runsystem("mt -f $tape rewind");
 
 setstatus "FAILED during cleanup";
 
+$summary= '';
+foreach $tfs (@tapefilesizes) {
+    $summary .= sprintf "    %10d blocks for %s\n", $tfs->[0], $tfs->[1]
+}
+$summary .=
+    sprintf "    %10d blocks total (of %d bytes) plus TAPEID and headers\n",
+    $totalrecords, $blocksizebytes;
+
+pboth("size-summary:\n");
+pboth($summary);
+
+open SS, ">size-summary..new" or die $!;
+print SS $summary or die $!;
+close SS or die $!;
+rename 'size-summary..new',"size-summary.$fsys" or die $!;
+
 # Write to some status files to indicate what the backup system
 # ought to do when next invoked.
 # reset incremental backup count to 1.