3 # Do an incremental backup; ONLY for invocation by full !
5 # This file is part of chiark backup, a system for backing up GNU/Linux and
6 # other UN*X-compatible machines, as used on chiark.greenend.org.uk.
9 # Copyright (C) 1997-1998,2000-2001 Ian Jackson <ian@chiark.greenend.org.uk>
10 # Copyright (C) 1999 Peter Maydell <pmaydell@chiark.greenend.org.uk>
12 # This is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2, or (at your option) any later version.
16 # This is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 # You should have received a copy of the GNU General Public License along
22 # with this program; if not, write to the Free Software Foundation, Inc.,
23 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 # We are invoked by full if the tape description file says that it is
26 # for an incremental backup. We expect two commandline argument which
27 # is the ID string of the tape to use, and the description (which
28 # includes ID and function).
31 $etc= '/etc/chiark-backup';
32 require "$etc/settings.pl";
33 require 'backuplib.pl';
39 ($tapeid,$tapedesc)= @ARGV;
41 print "Running incremental onto $tapedesc ...\n" or die $!;
43 # Just check that we weren't passed a bogus ID (the tape description
44 # file for incrementals is just 'incremental\nend\n')
45 open T,"$etc/tape.$tapeid" or die "Tape $tapeid not found: $!\n";
48 # This is only used for the 'next FULL backup is X' message at the end.
49 open NF,"next-full" or die $!;
53 setstatus "FAILED during incremental";
55 # Read the number of the incremental involved
56 # (ie, (how many files are already on the tape) - 1)
57 open A,"increm-advance" or die $!;
61 # better be a decimal number
62 $advance =~ m/^\d+$/ or die "$advance ?";
64 # Get a list of all filesystems
68 # Rewind the tape and if we are the first incremental on the tape then
69 # write the TAPEID record, otherwise skip forward to the correct point.
70 # (full will already have checked that this is the right tape before
71 # it invoked us, so no need to read the existing TAPEID record first.)
72 runsystem("mt -f $ntape rewind");
74 writetapeid($tapeid,$tapedesc);
76 runsystem("mt -f $ntape fsf $advance");
77 $currenttapefilenumber= $advance;
81 close(DUMPOR); close(BUFOR);
82 close(DUMPOW); close(BUFOW);
83 close(GZOR); close(GZOW);
86 setstatus "PROBLEMS during incremental dump";
93 $ddcmd= "$nasty dd ibs=$softblocksizebytes obs=$blocksizebytes of=$ntape";
95 pipe(DUMPOR,DUMPOW) or die $!;
96 pipe(BUFOR,BUFOW) or die $!;
98 $gz= $gzi if length $gzi;
101 pipe(GZOR,GZOW) or die $!;
102 $ddcmd .= " conv=sync";
106 $dumpcmd= "dump 1bfu $softblocksizekb - $atf";
108 print "Not dumping $atf ($prefix) - not \`dump'.\n" or die $!;
109 print LOG "Not dumping $atf ($prefix) - not \`dump'.\n" or die $!;
113 nexttapefile("inc $prefix:$atf");
115 # Same trick as full uses to do a pipeline whilst keeping track
116 # of all exit statuses:
117 # dump </dev/null | writebuffer | dd >/dev/null
118 startprocess '</dev/null','>&DUMPOW',"$nice ".$rstr.$dumpcmd;
120 startprocess '<&DUMPOR','>&GZOW',"$nice gzip -v$gz";
122 startprocess "<&$bufir",'>&BUFOW',"$nasty writebuffer";
123 startprocess '<&BUFOR','>/dev/null',"$nasty $ddcmd";
126 # advance is a file counter, so it needs to be updated for each
127 # dump we do to tape.
131 # Rewind the tape, and increment the counter of incremental backups.
132 runsystem("mt -f $tape rewind");
133 open IAN,">increm-advance.new" or die $!;
134 print IAN "$advance\n" or die $!;
136 rename 'increm-advance.new','increm-advance' or die $!;
138 print LOG "Next FULL dump tape is $next\n" or die $!;
139 print "Next FULL dump tape is $next\n" or die $!;
141 setstatus "INCREMENTAL successful: $tapedesc, next full is $next";