From 6548c05b2f401d9d712acde8d0aff31388c0db70 Mon Sep 17 00:00:00 2001 From: ianmdlvl Date: Sun, 11 May 2003 17:52:34 +0000 Subject: [PATCH] from lalonde --- TODO | 4 ++++ backup/backuplib.pl | 20 ++++++++++++++---- backup/full | 48 ++++++++++++++++++++++++-------------------- backup/increm | 27 +++++++++++++++++++------ backup/iwjbackup.txt | 18 +++++++++++------ debian/changelog | 4 +++- 6 files changed, 82 insertions(+), 39 deletions(-) diff --git a/TODO b/TODO index 9dc0150..bcf52f9 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,12 @@ BACKUP ====== +devices as well as mountpoints +read/writebuffer buggy ? + would be nice someday --------------------- +gz increms only replace loaded with idformat read/writebuffer setuid --mlock whatsthis no cloneandhack diff --git a/backup/backuplib.pl b/backup/backuplib.pl index 279cbd6..1163b5a 100644 --- a/backup/backuplib.pl +++ b/backup/backuplib.pl @@ -23,6 +23,8 @@ require IO::File; +$nice='nice ' if !defined $nice; + sub printdate () { print scalar(localtime),"\n"; } @@ -141,7 +143,7 @@ sub readfsys ($) { # to be in $tf. sub parsefsys () { my ($dopts,$dopt); - if ($tf =~ m#^(/\S*)\s+(\w+)([,0-9a-z]+)$#) { + if ($tf =~ m#^(/\S*)\s+(\w+)([,=0-9a-z]*)$#) { # Line of form '/file/system dumptype[,options]' $atf= $1; $tm= $2; @@ -150,7 +152,7 @@ sub parsefsys () { stat $atf or die "stat $atf: $!"; -d _ or die "not a dir: $atf"; $rstr= ''; - } elsif ($tf =~ m#^(/\S*)\s+(\w+)([,0-9a-z]+)\s+(\w+)$#) { + } elsif ($tf =~ m#^(/\S*)\s+(\w+)([,=0-9a-z]*)\s+(\w+)$#) { # Line of form '/file/system dumptype[,options] prefix' # (used for remote backups) $atf= $1; @@ -168,10 +170,20 @@ sub parsefsys () { $dopt{$dopt}= 'y'; } elsif ($dopt =~ m/\=/ && grep { $` eq $_ } qw(gz)) { $dopt{$`}= $'; - } else { - die "unknown option $dopt"; + } elsif (length $dopt) { + die "unknown option $dopt (in $dopts $tf)"; } } + + if ($dopt{'gz'} eq 'y') { + $gz= '1'; + } elsif ($dopt{'gz'} =~ m/^\d$/) { + $gz= $dopt{'gz'}; + } elsif (defined $dopt{'gz'}) { + die "$tf bad gz"; + } else { + $gz= 0; + } } sub openlog () { diff --git a/backup/full b/backup/full index 784d302..ddd15ce 100755 --- a/backup/full +++ b/backup/full @@ -167,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 @@ -182,32 +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 $!; + $bufir='TEEOR'; + $ddcmd= "dd ibs=$softblocksizebytes obs=$blocksizebytes of=$ntape"; - if ($dopt{'gz'} eq 'y') { - $gz= '3'; - } elsif ($dopt{'gz'} =~ m/^\d$/) { - $gz= $dopt{'gz'}; - } elsif (defined $dopt{'gz'}) { - die "$tf bad gz"; - } else { - $gz= 0; - } if ($gz) { $bufir='GZOR'; pipe(GZOR,GZOW) or die $!; + $ddcmd .= " conv=sync"; } - pipe(BUFOR,BUFOW) or die $!; - parsefsys(); - # We can back up via dump or cpio or zafio + $dumpin= '&FINDOW',$rstr."find $atf -xdev -noleaf -print0"; $dumpcmd= "cpio -Hustar -o0C$softblocksizebytes"; @@ -218,6 +213,9 @@ 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') { +# fixme have to find device rather than mountpoint (atf is mountpoint) + $dumpcmd= "ntfsimage -vvf --dirty $atf"; } else { die "unknown method $tm for $prefix:$atf\n"; } @@ -225,16 +223,15 @@ for $tf (@fsys) { # to the exit status of all the commands in the pipeline. # It is roughly equivalent to: # md5sum

>this-md5sums - # dump <$dumpin | tee p | writebuffer | dd >/dev/null - startprocess '>this-md5sums','md5sum'; - startprocess $dumpin,'>&DUMPOW',$rstr.$dumpcmd; - startprocess '<&DUMPOR','>&TEEOW','tee p'; + # dump <$dumpin | tee p [| gzip] | writebuffer | dd >/dev/null + startprocess '>this-md5sums',"$nice md5sum"; + startprocess $dumpin,'>&DUMPOW',"$nice ".$rstr.$dumpcmd; + startprocess '<&DUMPOR','>&TEEOW',"$nice tee p"; if ($gz) { - startprocess '<&TEEOR','>&GZOW','gzip -v$gz'; + startprocess '<&TEEOR','>&GZOW',"$nice gzip -v$gz"; } - startprocess "<&$bufir",'>&BUFOW','writebuffer'; - startprocess '<&BUFOR','>/dev/null' - ,"dd ibs=$softblocksizebytes obs=$blocksizebytes of=$ntape"; + startprocess "<&$bufir",'>&BUFOW',"$nasty writebuffer"; + startprocess '<&BUFOR','>/dev/null',"$nasty $ddcmd"; closepipes(); endprocesses(); } @@ -251,9 +248,16 @@ system "mt -f $ntape fsf 1"; $? and die $?; open S,"this-md5sums" or die $!; for $tf (@fsys) { printdate(); + parsefsys(); chomp($orgsum= ); $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 $!; diff --git a/backup/increm b/backup/increm index b3c1f70..e3037e8 100755 --- a/backup/increm +++ b/backup/increm @@ -90,10 +90,23 @@ setstatus "PROBLEMS during incremental dump"; for $tf (@fsys) { + parsefsys(); + + $bufir='DUMPOR'; + $ddcmd= "$nasty dd ibs=$softblocksizebytes obs=$blocksizebytes of=$ntape"; + pipe(DUMPOR,DUMPOW) or die $!; pipe(BUFOR,BUFOW) or die $!; - parsefsys(); - if ($tm ne 'dump') { + + if ($gz) { + $bufir='GZOR'; + pipe(GZOR,GZOW) or die $!; + $ddcmd .= " conv=sync"; + } + + if ($tm eq 'dump') { + $dumpcmd= "dump 1bfu $softblocksizekb - $atf"; + } else { print "Not dumping $atf ($prefix) - not \`dump'.\n" or die $!; print LOG "Not dumping $atf ($prefix) - not \`dump'.\n" or die $!; next; @@ -101,10 +114,12 @@ for $tf (@fsys) { # Same trick as full uses to do a pipeline whilst keeping track # of all exit statuses: # dump /dev/null - startprocess '&DUMPOW',$rstr."dump 1bfu $softblocksizekb - $atf"; - startprocess '<&DUMPOR','>&BUFOW','writebuffer'; - startprocess '<&BUFOR','>/dev/null' - ,"dd ibs=$softblocksizebytes obs=$blocksizebytes of=$ntape"; + startprocess '&DUMPOW',"$nice ".$rstr.$dumpcmd; + if ($gz) { + startprocess '<&DUMPOR','>&GZOW',"$nice gzip -v$gz"; + } + startprocess "<&$bufir",'>&BUFOW',"$nasty writebuffer"; + startprocess '<&BUFOR','>/dev/null',"$nasty $ddcmd"; closepipes(); endprocesses(); # advance is a file counter, so it needs to be updated for each diff --git a/backup/iwjbackup.txt b/backup/iwjbackup.txt index 4ee2354..9c39ab7 100644 --- a/backup/iwjbackup.txt +++ b/backup/iwjbackup.txt @@ -54,18 +54,24 @@ In the fsys.* files: run things on a remote machine: prefix Other lines should be of the form - - for local backups, or - + [:] [,] + for local backups, or + [:] [,] for remote backups. The file (including any included files) must end with the word 'end' on a line of its own. Valid values for are `cpio' (uses cpio to produce tar-format backups), `dump' (uses dump to dump entire filesystems; - should be a mount-point for this), and `zafio' (uses -afio to compress each file as it is backed up). Only `dump' type -backups perform incremental backups. + should be a mount-point for this), `zafio' (uses afio +to compress each file as it is backed up), and `ntfsimage' (for NTFS +volumes, requires device name). Only `dump' type backups perform +incremental backups. + + is a comma-separated list of