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 # Rewind the tape and if we are the first incremental on the tape then
65 # write the TAPEID record, otherwise skip forward to the correct point.
66 # (full will already have checked that this is the right tape before
67 # it invoked us, so no need to read the existing TAPEID record first.)
68 system "mt -f $ntape rewind"; $? and die $?;
70 open TI,">TAPEID" or die $!;
71 print TI "$tapeid\n$tapedesc\n" or die $!;
74 system "tar -b$blocksize -vvcf TAPEID.tar TAPEID"; $? and die $?;
75 system "dd if=TAPEID.tar of=$ntape bs=${blocksize}b count=10"; $? and die $?;
77 system "mt -f $ntape fsf $advance"; $? and die $?;
80 # Get a list of all filesystems
85 close(DUMPOR); close(BUFOR);
86 close(DUMPOW); close(BUFOW);
89 setstatus "PROBLEMS during incremental dump";
93 pipe(DUMPOR,DUMPOW) or die $!;
94 pipe(BUFOR,BUFOW) or die $!;
97 print "Not dumping $atf ($prefix) - not \`dump'.\n" or die $!;
98 print LOG "Not dumping $atf ($prefix) - not \`dump'.\n" or die $!;
101 # Same trick as full uses to do a pipeline whilst keeping track
102 # of all exit statuses:
103 # dump </dev/null | writebuffer | dd >/dev/null
104 startprocess '</dev/null','>&DUMPOW',$rstr."dump 1bfu $softblocksizekb - $atf";
105 startprocess '<&DUMPOR','>&BUFOW','writebuffer';
106 startprocess '<&BUFOR','>/dev/null'
107 ,"dd ibs=$softblocksizebytes obs=$blocksizebytes of=$ntape";
110 # advance is a file counter, so it needs to be updated for each
111 # dump we do to tape.
115 # Rewind the tape, and increment the counter of incremental backups.
116 system "mt -f $tape rewind"; $? and die $?;
117 open IAN,">increm-advance.new" or die $!;
118 print IAN "$advance\n" or die $!;
120 rename 'increm-advance.new','increm-advance' or die $!;
122 print LOG "Next FULL dump tape is $next\n" or die $!;
123 print "Next FULL dump tape is $next\n" or die $!;
125 setstatus "INCREMENTAL successful: $tapedesc, next full is $next";