chiark / gitweb /
@@ -3,7 +3,7 @@
[chiark-utils.git] / backup / checkallused
1 #!/usr/bin/perl
2 # checkallused
3 # check that the configuration is sane and backs up everything it should
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 # All filesystems must either be backed up in both full and
26 # incremental dumps or listed as exceptions.
27
28 BEGIN {
29     $etc= '/etc/chiark-backup';
30     require "$etc/settings.pl";
31     require 'backuplib.pl';
32 }
33
34 $|=1;
35
36 open X,'last-tape' or die $!;
37 chomp($tape= <X>);
38 close X or die $!;
39
40 while (!defined $tapedone{$tape}) {
41     open X,"$etc/tape.$tape" or die "$tape $!";
42     $fsg=''; $next='';
43     for (;;) {
44         $_= <X> or die $1; chomp; s/\s*$//;
45         last if m/^end$/;
46         next unless m/\S/;
47         next if m/^\#/;
48         if (m/^filesystems (\w+)$/) { $fsg= $1; }
49         elsif (m/^next (\w+)$/) { $next=$1; }
50         else { die "$tape $_ ?"; }
51     }
52     length $fsg or die "$tape $!";
53     length $next or die "$tape $!";
54     push @{$fsgdone{$fsg}}, $tape;
55     $tapedone{$tape}=1;
56     $tape= $next;
57 }
58
59 for $fsg (sort keys %fsgdone) {
60     print "filesystem group $fsg: ".join(' ',@{$fsgdone{$fsg}}).":\n ";
61     @fsys= ();
62     readfsys($fsg);
63     for $tf (@fsys) {
64         parsefsys();
65         $pstr= $prefix ne '<local>' ? "$prefix:$atf" : $atf;
66         &e("dumped twice ($backed{$pstr}, $fsg): $pstr")
67             if defined $backed{$pstr};
68         $backed{$pstr}= $fsg;
69         print " $pstr";
70     }
71     print "\n";
72 }
73
74 print "incremental group:\n ";
75 @fsys= ();
76 readfsys('all');
77 for $tf (@fsys) {
78     parsefsys();
79     $pstr= $prefix ne '<local>' ? "$prefix:$atf" : $atf;
80     $incrd{$pstr}= $fsg;
81     print " $pstr";
82 }
83 print "\n";
84
85 for $pfx ('', sort keys %prefix) {
86     $rstr= length($pfx) ? $prefix{$pfx}.' ' : '';
87     $dfstr= exists($prefixdf{$pfx}) ? $prefixdf{$pfx} :
88         'df --no-sync -xiso9660 -xnfs -xproc';
89     $cmd= "$rstr $dfstr";
90     open X, "$cmd |" or die $!;
91     $_= <X>; m/^Filesystem/ or die "$cmd => $_ ?";
92     $ppstr= length($pfx) ? $pfx : '<local>';
93     $pstr= length($pfx) ? "$pfx:" : '';
94     print "mount points: $ppstr:";
95     while (<X>) {
96         chomp;
97         next if m,^procfs\s,;
98         m,^/dev/(\S+)\s.*\s(/\S*)\s*$, or die "$_ ?";
99         ($dev,$mp) = ($1,$2);
100         $mounted{"$pstr$mp"}="$pstr$dev"; print " $1-$2";
101         if (defined($backto= $backed{"$pstr$mp"})) {
102             if (m,^/dev/\S+\s+\d+\s+(\d+)\s,) {
103                 $usedkb{$backto} += $1;
104             } else {
105                 $usedkb{$backto} += 0;
106                 $unkkb{$backto} .= " + $pstr$mp";
107             }
108         }
109     }
110     print "\n";
111     $!=0; close(X); $? and die "$? $!";
112 }
113
114 foreach $fsg (keys %usedkb) {
115     print "filesystem group $fsg: $usedkb{$fsg} 1K-blocks$unkkb{$fsg}\n";
116 }
117
118 # We check that all mounted filesystems are dumped and all
119 # filesystems to be dumped are mounted. The expected-diffs
120 # config file allows us to make exceptions.
121 # eg: 
122 # #expect disk2 to be mounted but not dumped
123 # !/disk2
124 # # CD may or may not be mounted but should not be dumped in either case
125 # ?/cdrom
126
127 open Z,"$etc/expected-diffs" or die $!;
128 for (;;) {
129     $_= <Z> or die; chomp; s/\s*$//;
130     last if m/^end$/;
131     next unless m/^\S/;
132     next if m/^\#/;
133     if (s/^\?//) {
134         print "non-permanent filesystem expected not to be dumped: $_\n";
135         if (defined($mounted{$_})) {
136             delete $mounted{$_};
137         }
138     } elsif (s/^\!//) {
139         &e("expected not to be dumped, but not a mount point: $_")
140             unless defined($mounted{$_});
141         print "filesystem expected not to be dumped: $_\n";
142         delete $mounted{$_};
143     } else {
144         &e("non-filesystem expected to be dumped is mounted: $_ on $mounted{$_}")
145             if defined($mounted{$_});
146         $mounted{$_}= 'expected-diffs';
147         print "non-filesystem expected to be dumped: $_\n";
148     }
149 }
150     
151 for $fs (sort keys %backed) { length($mounted{$fs}) || &e("dumped ($backed{$fs}), not a mount point: $fs"); }
152 for $fs (sort keys %incrd) { length($mounted{$fs}) || &e("increm'd ($incrd{$fs}), not a mount point: $fs"); }
153 for $fs (sort keys %mounted) { length($backed{$fs}) || &e("mount point ($mounted{$fs}), not dumped: $fs"); }
154 for $fs (sort keys %mounted) { length($incrd{$fs}) || &e("mount point ($mounted{$fs}), not increm'd: $fs"); }
155
156 $emsg.= "configuration ok\n" unless $e;
157 print STDERR $emsg;
158 exit($e);
159
160 sub e { $emsg.="** @_\n"; $e=1; }