5 require "$etc/settings.pl";
6 require 'backuplib.pl';
11 print "Configuration check ...\n" or die $!;
12 system 'checkallused'; $? and die $?;
17 system "mt -f $tape setblk $blocksizebytes"; $? and die $?;
18 system "dd if=$tape bs=${blocksize}b count=10 | tar -b$blocksize -vvxf - TAPEID";
20 setstatus "FAILED during startup";
22 if (open T, "TAPEID") {
23 unlink 'really-TAPEID';
24 } elsif (open T, "really-TAPEID") {
30 $tapeid =~ m/[^0-9a-zA-Z]/ and die "Bad TAPEID ($&).\n";
31 $tapeid =~ m/[0-9a-zA-Z]/ or die "Empty TAPEID.\n";
34 setstatus "FAILED at tape identity check";
36 if (open L, "last-tape") {
37 chomp($lasttape= <L>);
43 die "Tape $tapeid same as last time.\n" if $tapeid eq $lasttape;
46 open D, "$etc/tape.$tapeid" or die "Unknown tape $tapeid ($!).\n";
48 $_= <D> or die; chomp; s/\s+$//;
52 if (m/^filesystems (\w+)$/) {
54 } elsif (m/^next (\w+)$/) {
56 } elsif (m/^incremental$/) {
59 die "unknown entry in tape $tapeid at line $.: $_\n";
65 die "incremental tape $tapeid has next or filesystems\n"
66 if defined($next) || defined($fsys);
67 print STDERR "Incremental tape $tapeid.\n\n";
68 setstatus "FAILED during incremental startup";
69 exec "increm $tapeid";
76 $doing= "dump of $fsys to tape $tapeid in drive $tape";
77 print LOG "$doing:\n" or die $!;
79 system "mt -f $tape rewind"; $? and die $?;
80 system "mt -f $tape retension"; $? and die $?;
82 open T, ">TAPEID" or die $!;
83 print T "$tapeid\n" or die $!;
86 system "tar -b$blocksize -vvcf TAPEID.tar TAPEID"; $? and die $?;
87 system "dd if=TAPEID.tar of=$ntape bs=${blocksize}b count=10"; $? and die $?;
89 unlink 'this-md5sums';
91 print "Doing $doing ...\n" or die $!;
94 system 'mknod p p'; $? and die $?;
96 setstatus "FAILED during dump";
99 close(DUMPOR); close(TEEOR); close(BUFOR); close(FINDOR);
100 close(DUMPOW); close(TEEOW); close(BUFOW); close(FINDOW);
105 pipe(FINDOR,FINDOW) or die $!;
106 pipe(DUMPOR,DUMPOW) or die $!;
107 pipe(TEEOR,TEEOW) or die $!;
108 pipe(BUFOR,BUFOW) or die $!;
111 $dumpcmd= "dump 0bfu $softblocksizekb - $atf";
112 $dumpin= '</dev/null';
114 startprocess '</dev/null','>&FINDOW',$rstr."find $atf -xdev -noleaf -print0";
115 $dumpcmd= "cpio -Hustar -o0C$softblocksizebytes";
118 startprocess '<p','>>this-md5sums','md5sum';
119 startprocess $dumpin,'>&DUMPOW',$rstr.$dumpcmd;
120 startprocess '<&DUMPOR','>&TEEOW','tee p';
121 startprocess '<&TEEOR','>&BUFOW','writebuffer';
122 startprocess '<&BUFOR','>/dev/null'
123 ,"dd ibs=$softblocksizebytes obs=$blocksizebytes of=$ntape";
128 setstatus "FAILED during check";
130 system "mt -f $tape rewind"; $? and die $?;
131 system "mt -f $ntape fsf 1"; $? and die $?;
133 open S,"this-md5sums" or die $!;
137 $orgsum =~ m/^[0-9a-fA-F]{32}$/i or die "orgsum \`$orgsum' ?";
138 chomp($csum= `readbuffer <$ntape | md5sum`);
139 $orgsum eq $csum or die "MISMATCH $tf $csum $orgsum\n";
140 print "checksum ok $csum\t$tf\n" or die $!;
141 print LOG "checksum ok $csum\t$tf\n" or die $!;
144 system "mt -f $tape rewind"; $? and die $?;
146 setstatus "FAILED during cleanup";
148 open IAN,">increm-advance.new" or die $!;
149 print IAN "1\n" or die $!;
152 open TN,">next-full.new" or die $!;
153 print TN "$next\n" or die $!;
156 unlink 'last-tape','next-full';
157 rename 'TAPEID','last-tape' or die $!;
158 rename 'this-md5sums',"md5sums.$fsys" or die $!;
159 rename 'log',"log.$fsys" or die $!;
160 rename 'next-full.new',"next-full" or die $!;
161 rename 'increm-advance.new',"increm-advance" or die $!;
163 print "$doing completed.\nNext dump tape is $next.\n" or die $!;
165 setstatus "Successful ($tapeid $fsys, next $next)";