chiark / gitweb /
chiark-named-conf glueless-serverless works properly.
[chiark-utils.git] / backup / increm
1 #!/usr/bin/perl
2 # increm
3 # Do an incremental backup; ONLY for invocation by full !
4 #
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.
7 #
8 # chiark backup is:
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>
11 #
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.
15 #
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
19 # details.
20 #
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.
24
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).
29
30 BEGIN {
31     $etc= '/etc/chiark-backup';
32     require "$etc/settings.pl";
33     require 'backuplib.pl';
34 }
35
36 $|=1;
37
38 @ARGV==2 or die;
39 ($tapeid,$tapedesc)= @ARGV;
40
41 print "Running incremental onto $tapedesc ...\n" or die $!;
42
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";
46 close T;
47
48 # This is only used for the 'next FULL backup is X' message at the end.
49 open NF,"next-full" or die $!;
50 chomp($next= <NF>);
51 close NF or die $!;
52
53 setstatus "FAILED during incremental";
54
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 $!;
58 chomp($advance= <A>);
59 close A or die $!;
60
61 # better be a decimal number
62 $advance =~ m/^\d+$/ or die "$advance ?";
63
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 $?;
69 if ($advance == 1) {
70     open TI,">TAPEID" or die $!;
71     print TI "$tapeid\n$tapedesc\n" or die $!;
72     close TI or die $!;
73
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 $?;
76 } else {
77     system "mt -f $ntape fsf $advance"; $? and die $?;
78 }
79
80 # Get a list of all filesystems
81 readfsys('all');
82 openlog();
83
84 sub closepipes () {
85     close(DUMPOR); close(BUFOR);
86     close(DUMPOW); close(BUFOW);
87 }
88
89 setstatus "PROBLEMS during incremental dump";
90
91 for $tf (@fsys) {
92
93     pipe(DUMPOR,DUMPOW) or die $!;
94     pipe(BUFOR,BUFOW) or die $!;
95     parsefsys();
96     if ($tm ne 'dump') {
97         print "Not dumping $atf ($prefix) - not \`dump'.\n" or die $!;
98         print LOG "Not dumping $atf ($prefix) - not \`dump'.\n" or die $!;
99         next;
100     }
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";
108     closepipes();
109     endprocesses();
110     # advance is a file counter, so it needs to be updated for each 
111     # dump we do to tape.
112     $advance++;
113 }
114
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 $!;
119 close IAN or die $!;
120 rename 'increm-advance.new','increm-advance' or die $!;
121
122 print LOG "Next FULL dump tape is $next\n" or die $!;
123 print "Next FULL dump tape is $next\n" or die $!;
124
125 setstatus "INCREMENTAL successful: $tapedesc, next full is $next";
126 exit 0;