annotate archivecheck.pl @ 20:79c6618e8dfa

small fixes
author casties
date Tue, 20 Sep 2005 19:30:34 +0200
parents 320c4b93bf39
children 24d9dd63ae93
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
30497c6a3eca Initial revision
casties
parents:
diff changeset
1 #!/usr/local/bin/perl -w
30497c6a3eca Initial revision
casties
parents:
diff changeset
2
30497c6a3eca Initial revision
casties
parents:
diff changeset
3 use strict;
30497c6a3eca Initial revision
casties
parents:
diff changeset
4
30497c6a3eca Initial revision
casties
parents:
diff changeset
5 use XML::LibXML;
30497c6a3eca Initial revision
casties
parents:
diff changeset
6
30497c6a3eca Initial revision
casties
parents:
diff changeset
7 # MPIWG libraries
30497c6a3eca Initial revision
casties
parents:
diff changeset
8 use lib '/usr/local/mpiwg/archive';
30497c6a3eca Initial revision
casties
parents:
diff changeset
9 use MPIWGStor;
30497c6a3eca Initial revision
casties
parents:
diff changeset
10
30497c6a3eca Initial revision
casties
parents:
diff changeset
11 # make output unbuffered
30497c6a3eca Initial revision
casties
parents:
diff changeset
12 $|=1;
30497c6a3eca Initial revision
casties
parents:
diff changeset
13
30497c6a3eca Initial revision
casties
parents:
diff changeset
14 #######################################################
30497c6a3eca Initial revision
casties
parents:
diff changeset
15 # internal parameters
30497c6a3eca Initial revision
casties
parents:
diff changeset
16 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
17
30497c6a3eca Initial revision
casties
parents:
diff changeset
18 # program version
11
b19df18aa19a updated command line option parsing and logging
casties
parents: 9
diff changeset
19 my $version = "0.4.1 (15.2.2005)";
0
30497c6a3eca Initial revision
casties
parents:
diff changeset
20
30497c6a3eca Initial revision
casties
parents:
diff changeset
21 # read command line parameters
30497c6a3eca Initial revision
casties
parents:
diff changeset
22 my $args = parseargs;
30497c6a3eca Initial revision
casties
parents:
diff changeset
23
30497c6a3eca Initial revision
casties
parents:
diff changeset
24 # debug level
30497c6a3eca Initial revision
casties
parents:
diff changeset
25 $debug = (exists $$args{'debug'}) ? $$args{'debug'} : 0;
30497c6a3eca Initial revision
casties
parents:
diff changeset
26
30497c6a3eca Initial revision
casties
parents:
diff changeset
27 # XML namespace (not really implemented!)
30497c6a3eca Initial revision
casties
parents:
diff changeset
28 my $namespace = "";
30497c6a3eca Initial revision
casties
parents:
diff changeset
29
30497c6a3eca Initial revision
casties
parents:
diff changeset
30 # archive name (archive-path element, usually == $docdir)
30497c6a3eca Initial revision
casties
parents:
diff changeset
31 my $archname;
30497c6a3eca Initial revision
casties
parents:
diff changeset
32 # archive storage date
30497c6a3eca Initial revision
casties
parents:
diff changeset
33 my $archdate;
30497c6a3eca Initial revision
casties
parents:
diff changeset
34
30497c6a3eca Initial revision
casties
parents:
diff changeset
35
30497c6a3eca Initial revision
casties
parents:
diff changeset
36 #######################################################
30497c6a3eca Initial revision
casties
parents:
diff changeset
37 # external programs
30497c6a3eca Initial revision
casties
parents:
diff changeset
38 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
39 my $archprog = "/opt/tivoli/tsm/client/ba/bin/dsmc";
30497c6a3eca Initial revision
casties
parents:
diff changeset
40 if (! -x $archprog) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
41 logger("ABORT", "TSM client program '$archprog' missing!!");
30497c6a3eca Initial revision
casties
parents:
diff changeset
42 exit 1;
30497c6a3eca Initial revision
casties
parents:
diff changeset
43 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
44 # my $checkprog = "/usr/local/mpiwg/archive/metacheck";
30497c6a3eca Initial revision
casties
parents:
diff changeset
45 # if (! -x $checkprog) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
46 # logge("ABORT", "meta data checking program '$checkprog' missing!!");
30497c6a3eca Initial revision
casties
parents:
diff changeset
47 # exit 1;
30497c6a3eca Initial revision
casties
parents:
diff changeset
48 # }
30497c6a3eca Initial revision
casties
parents:
diff changeset
49 # log file for archiver
30497c6a3eca Initial revision
casties
parents:
diff changeset
50 my $log_file = "/var/tmp/archivecheck.log";
30497c6a3eca Initial revision
casties
parents:
diff changeset
51 if (! open LOG, ">>$log_file") {
30497c6a3eca Initial revision
casties
parents:
diff changeset
52 logger("ABORT", "unable to write log file '$log_file'!!");
30497c6a3eca Initial revision
casties
parents:
diff changeset
53 exit 1;
30497c6a3eca Initial revision
casties
parents:
diff changeset
54 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
55
30497c6a3eca Initial revision
casties
parents:
diff changeset
56 #######################################################
30497c6a3eca Initial revision
casties
parents:
diff changeset
57 # check parameters that were passed to the program
30497c6a3eca Initial revision
casties
parents:
diff changeset
58 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
59 my $docdir = $$args{'path'};
30497c6a3eca Initial revision
casties
parents:
diff changeset
60 if (! $docdir) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
61 print "ABORT: no document directory given!\n";
30497c6a3eca Initial revision
casties
parents:
diff changeset
62 exit 1;
30497c6a3eca Initial revision
casties
parents:
diff changeset
63 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
64 # strip trailing slashes
30497c6a3eca Initial revision
casties
parents:
diff changeset
65 $docdir =~ s/\/$//;
30497c6a3eca Initial revision
casties
parents:
diff changeset
66 if (! -d $docdir) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
67 print "ABORT: document directory \'$docdir\' doesn't exist!\n";
30497c6a3eca Initial revision
casties
parents:
diff changeset
68 exit 1;
30497c6a3eca Initial revision
casties
parents:
diff changeset
69 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
70
30497c6a3eca Initial revision
casties
parents:
diff changeset
71 my $metafile = "$docdir/index.meta";
30497c6a3eca Initial revision
casties
parents:
diff changeset
72 if (! -f $metafile) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
73 print "ABORT: metadata index file \'$metafile\' doesn't exist!\n";
30497c6a3eca Initial revision
casties
parents:
diff changeset
74 exit 1;
30497c6a3eca Initial revision
casties
parents:
diff changeset
75 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
76
30497c6a3eca Initial revision
casties
parents:
diff changeset
77 #######################################################
30497c6a3eca Initial revision
casties
parents:
diff changeset
78 # internal variables
30497c6a3eca Initial revision
casties
parents:
diff changeset
79 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
80
30497c6a3eca Initial revision
casties
parents:
diff changeset
81 # number of errors
30497c6a3eca Initial revision
casties
parents:
diff changeset
82 my $errcnt = 0;
30497c6a3eca Initial revision
casties
parents:
diff changeset
83 # number of warnings
30497c6a3eca Initial revision
casties
parents:
diff changeset
84 my $warncnt = 0;
30497c6a3eca Initial revision
casties
parents:
diff changeset
85
30497c6a3eca Initial revision
casties
parents:
diff changeset
86 #######################################################
30497c6a3eca Initial revision
casties
parents:
diff changeset
87 # subroutines
30497c6a3eca Initial revision
casties
parents:
diff changeset
88 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
89
30497c6a3eca Initial revision
casties
parents:
diff changeset
90
30497c6a3eca Initial revision
casties
parents:
diff changeset
91 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
92 # $files = read_resource_meta($rootnode)
30497c6a3eca Initial revision
casties
parents:
diff changeset
93 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
94 # checks general resource meta information and reads the list of files
30497c6a3eca Initial revision
casties
parents:
diff changeset
95 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
96 sub read_resource_meta {
30497c6a3eca Initial revision
casties
parents:
diff changeset
97 my ($rootnode) = @_;
30497c6a3eca Initial revision
casties
parents:
diff changeset
98 my %files;
30497c6a3eca Initial revision
casties
parents:
diff changeset
99 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
100 # archive path
30497c6a3eca Initial revision
casties
parents:
diff changeset
101 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
102 # get archive-path
30497c6a3eca Initial revision
casties
parents:
diff changeset
103 $archname = sstrip($rootnode->findvalue('child::archive-path'));
30497c6a3eca Initial revision
casties
parents:
diff changeset
104 if (! $archname) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
105 logger("ABORT", "archive-name element missing!!");
30497c6a3eca Initial revision
casties
parents:
diff changeset
106 exit 1;
30497c6a3eca Initial revision
casties
parents:
diff changeset
107 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
108
30497c6a3eca Initial revision
casties
parents:
diff changeset
109 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
110 # files
30497c6a3eca Initial revision
casties
parents:
diff changeset
111 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
112 my @filenodes = $rootnode->findnodes('child::file');
30497c6a3eca Initial revision
casties
parents:
diff changeset
113 foreach my $fn (@filenodes) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
114 my $name = sstrip($fn->findvalue('child::name'));
30497c6a3eca Initial revision
casties
parents:
diff changeset
115 my $path = sstrip($fn->findvalue('child::path'));
30497c6a3eca Initial revision
casties
parents:
diff changeset
116 logger("DEBUG", "FILE: ($path)$name");
30497c6a3eca Initial revision
casties
parents:
diff changeset
117 my $f = ($path) ? "$path/$name" : "$name";
30497c6a3eca Initial revision
casties
parents:
diff changeset
118 $files{$f} = [$name];
30497c6a3eca Initial revision
casties
parents:
diff changeset
119 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
120
30497c6a3eca Initial revision
casties
parents:
diff changeset
121 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
122 # dirs
30497c6a3eca Initial revision
casties
parents:
diff changeset
123 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
124 my @dirnodes = $rootnode->findnodes('child::dir');
30497c6a3eca Initial revision
casties
parents:
diff changeset
125 foreach my $fn (@dirnodes) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
126 my $name = sstrip($fn->findvalue('child::name'));
30497c6a3eca Initial revision
casties
parents:
diff changeset
127 my $path = sstrip($fn->findvalue('child::path'));
30497c6a3eca Initial revision
casties
parents:
diff changeset
128 logger("DEBUG", "DIR: ($path)$name");
30497c6a3eca Initial revision
casties
parents:
diff changeset
129 my $f = ($path) ? "$path/$name" : "$name";
30497c6a3eca Initial revision
casties
parents:
diff changeset
130 $files{$f} = [$name];
30497c6a3eca Initial revision
casties
parents:
diff changeset
131 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
132
30497c6a3eca Initial revision
casties
parents:
diff changeset
133 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
134 # archive-storage-date
30497c6a3eca Initial revision
casties
parents:
diff changeset
135 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
136 my $archdate = $rootnode->find('child::archive-storage-date');
30497c6a3eca Initial revision
casties
parents:
diff changeset
137 if ($archdate) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
138 logger("INFO", "archive storage date: $archdate");
30497c6a3eca Initial revision
casties
parents:
diff changeset
139 } else {
30497c6a3eca Initial revision
casties
parents:
diff changeset
140 logger("ERROR", "archive storage date missing!");
30497c6a3eca Initial revision
casties
parents:
diff changeset
141 $errcnt++;
30497c6a3eca Initial revision
casties
parents:
diff changeset
142 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
143 return \%files;
30497c6a3eca Initial revision
casties
parents:
diff changeset
144 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
145
30497c6a3eca Initial revision
casties
parents:
diff changeset
146
30497c6a3eca Initial revision
casties
parents:
diff changeset
147 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
148 # fs_read_files($realdir, $docdir, \%files, \%dirs)
30497c6a3eca Initial revision
casties
parents:
diff changeset
149 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
150 # reads all files and directories below $realdir and puts the
30497c6a3eca Initial revision
casties
parents:
diff changeset
151 # files in %files and directories in %dirs
30497c6a3eca Initial revision
casties
parents:
diff changeset
152 # $docdir is only for recursion, it should be empty when called
30497c6a3eca Initial revision
casties
parents:
diff changeset
153 # from outside
30497c6a3eca Initial revision
casties
parents:
diff changeset
154 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
155 sub fs_read_files {
30497c6a3eca Initial revision
casties
parents:
diff changeset
156 my ($directory, $docdir, $files, $dirs) = @_;
30497c6a3eca Initial revision
casties
parents:
diff changeset
157 my $cnt = 0;
30497c6a3eca Initial revision
casties
parents:
diff changeset
158
30497c6a3eca Initial revision
casties
parents:
diff changeset
159 if (! opendir DIR, $directory) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
160 return 0;
30497c6a3eca Initial revision
casties
parents:
diff changeset
161 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
162 my @dirfiles = readdir DIR;
30497c6a3eca Initial revision
casties
parents:
diff changeset
163 foreach my $fn (@dirfiles) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
164 # ignore names starting with a dot
30497c6a3eca Initial revision
casties
parents:
diff changeset
165 next if ($fn =~ /^\./);
30497c6a3eca Initial revision
casties
parents:
diff changeset
166 # ignore other silly files
30497c6a3eca Initial revision
casties
parents:
diff changeset
167 next if ($junk_files{$fn});
30497c6a3eca Initial revision
casties
parents:
diff changeset
168
30497c6a3eca Initial revision
casties
parents:
diff changeset
169 $cnt++;
30497c6a3eca Initial revision
casties
parents:
diff changeset
170 my $f = "$directory/$fn";
30497c6a3eca Initial revision
casties
parents:
diff changeset
171 my $docf = ($docdir) ? "$docdir/$fn" : $fn;
30497c6a3eca Initial revision
casties
parents:
diff changeset
172 #print "fs_file: \"$f\"\n";
30497c6a3eca Initial revision
casties
parents:
diff changeset
173 if (-f $f) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
174 #print " is file\n";
30497c6a3eca Initial revision
casties
parents:
diff changeset
175 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
30497c6a3eca Initial revision
casties
parents:
diff changeset
176 $atime,$mtime,$ctime,$blksize,$blocks)
30497c6a3eca Initial revision
casties
parents:
diff changeset
177 = stat(_);
30497c6a3eca Initial revision
casties
parents:
diff changeset
178 $$files{$docf} = [$fn, $size, stime($mtime)];
30497c6a3eca Initial revision
casties
parents:
diff changeset
179 #logger("TEST", "fn $fn, size $size, mtime $mtime");
30497c6a3eca Initial revision
casties
parents:
diff changeset
180 } elsif (-d _) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
181 #print " is dir\n";
30497c6a3eca Initial revision
casties
parents:
diff changeset
182 $$dirs{$docf} = $fn;
30497c6a3eca Initial revision
casties
parents:
diff changeset
183 # recurse into directory
30497c6a3eca Initial revision
casties
parents:
diff changeset
184 $cnt += fs_read_files($f, $docf, $files, $dirs);
30497c6a3eca Initial revision
casties
parents:
diff changeset
185 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
186 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
187 return $cnt;
30497c6a3eca Initial revision
casties
parents:
diff changeset
188 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
189
30497c6a3eca Initial revision
casties
parents:
diff changeset
190
30497c6a3eca Initial revision
casties
parents:
diff changeset
191 #
9
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
192 # $archcnt = run_query($dirquery, \%files)
0
30497c6a3eca Initial revision
casties
parents:
diff changeset
193 #
9
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
194 # runs the archiver program on $dirquery and adds to the hash of archived files
0
30497c6a3eca Initial revision
casties
parents:
diff changeset
195 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
196 # Sample output:
30497c6a3eca Initial revision
casties
parents:
diff changeset
197 # 20,345 B 08/06/03 17:17:02 /mpiwg/archive/data/proyectohumboldt/webb_histo_fr_01_1839/index.meta Never /mpiwg/archive/data/proyectohumboldt/webb_histo_fr_01_1839
30497c6a3eca Initial revision
casties
parents:
diff changeset
198 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
199 sub run_query {
9
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
200 my ($dirquery, $files) = @_;
0
30497c6a3eca Initial revision
casties
parents:
diff changeset
201 print LOG "START checkarchive $version ", scalar localtime, "\n";
30497c6a3eca Initial revision
casties
parents:
diff changeset
202 my $archcmd = $archprog;
30497c6a3eca Initial revision
casties
parents:
diff changeset
203 $archcmd .= " query archive -subdir=yes";
30497c6a3eca Initial revision
casties
parents:
diff changeset
204 $archcmd .= " -description='$archname'";
9
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
205 $archcmd .= " '$dirquery'";
0
30497c6a3eca Initial revision
casties
parents:
diff changeset
206
30497c6a3eca Initial revision
casties
parents:
diff changeset
207 my $archcnt = 0;
30497c6a3eca Initial revision
casties
parents:
diff changeset
208 print LOG "CMD: $archcmd\n";
30497c6a3eca Initial revision
casties
parents:
diff changeset
209 if (open ARCH, "$archcmd 2>&1 |") {
30497c6a3eca Initial revision
casties
parents:
diff changeset
210 while (<ARCH>) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
211 chomp;
30497c6a3eca Initial revision
casties
parents:
diff changeset
212 print LOG "ARCH: $_\n";
30497c6a3eca Initial revision
casties
parents:
diff changeset
213 if (/
30497c6a3eca Initial revision
casties
parents:
diff changeset
214 \s*([\d,]+) # size
30497c6a3eca Initial revision
casties
parents:
diff changeset
215 \s+(\w+) # unit of size
30497c6a3eca Initial revision
casties
parents:
diff changeset
216 \s+([\d\/]+) # date mm\/dd\/yy
30497c6a3eca Initial revision
casties
parents:
diff changeset
217 \s+([\d:]+) # time
30497c6a3eca Initial revision
casties
parents:
diff changeset
218 \s+(\S+) # file name
30497c6a3eca Initial revision
casties
parents:
diff changeset
219 \s+(\w+) # expiry
30497c6a3eca Initial revision
casties
parents:
diff changeset
220 \s+(\S+) # archive label
30497c6a3eca Initial revision
casties
parents:
diff changeset
221 /x) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
222 my $size = $1;
30497c6a3eca Initial revision
casties
parents:
diff changeset
223 my $sunit = $2;
30497c6a3eca Initial revision
casties
parents:
diff changeset
224 my $date = $3;
30497c6a3eca Initial revision
casties
parents:
diff changeset
225 my $time = $4;
30497c6a3eca Initial revision
casties
parents:
diff changeset
226 my $file = $5;
30497c6a3eca Initial revision
casties
parents:
diff changeset
227 my $exp = $6;
30497c6a3eca Initial revision
casties
parents:
diff changeset
228 my $label = $7;
30497c6a3eca Initial revision
casties
parents:
diff changeset
229 $size =~ s/,//g;
30497c6a3eca Initial revision
casties
parents:
diff changeset
230 $date = ymd_date($date);
30497c6a3eca Initial revision
casties
parents:
diff changeset
231 logger("DEBUG", " QUERY: file '$file'");
30497c6a3eca Initial revision
casties
parents:
diff changeset
232 $archcnt++;
9
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
233 if ($$files{$file}) {
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
234 logger("DEBUG", "file $file seems to be archived multiple times: $time $date");
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
235 #$warncnt++;
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
236 }
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
237 if (length $file <= length $docdir) {
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
238 logger("DEBUG", "not below document dir: $file");
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
239 next;
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
240 }
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
241 $$files{$file} = [$size, "$date $time"];
0
30497c6a3eca Initial revision
casties
parents:
diff changeset
242 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
243 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
244 } else {
30497c6a3eca Initial revision
casties
parents:
diff changeset
245 logger("ABORT", "unable to start archive command '$archcmd'!!");
30497c6a3eca Initial revision
casties
parents:
diff changeset
246 exit 1;
30497c6a3eca Initial revision
casties
parents:
diff changeset
247 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
248
9
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
249 return $archcnt;
0
30497c6a3eca Initial revision
casties
parents:
diff changeset
250 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
251
30497c6a3eca Initial revision
casties
parents:
diff changeset
252
30497c6a3eca Initial revision
casties
parents:
diff changeset
253 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
254 # check_files(\%files_to_archive, \%archived_files)
30497c6a3eca Initial revision
casties
parents:
diff changeset
255 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
256 # compares the list of archived and to be archived files
30497c6a3eca Initial revision
casties
parents:
diff changeset
257 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
258 sub check_files {
30497c6a3eca Initial revision
casties
parents:
diff changeset
259 my ($to_archive, $archived) = @_;
30497c6a3eca Initial revision
casties
parents:
diff changeset
260
30497c6a3eca Initial revision
casties
parents:
diff changeset
261 my $nt = scalar keys %$to_archive;
30497c6a3eca Initial revision
casties
parents:
diff changeset
262 my $na = scalar keys %$archived;
30497c6a3eca Initial revision
casties
parents:
diff changeset
263
30497c6a3eca Initial revision
casties
parents:
diff changeset
264 foreach my $ft (sort keys %$to_archive) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
265 my $fp = "$docdir/$ft";
30497c6a3eca Initial revision
casties
parents:
diff changeset
266 #logger("DEBUG", " fp: $fp");
30497c6a3eca Initial revision
casties
parents:
diff changeset
267 if ($$archived{$fp}) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
268 logger("DEBUG", "$ft archived OK");
30497c6a3eca Initial revision
casties
parents:
diff changeset
269 $$archived{$fp}->[2] = "OK";
30497c6a3eca Initial revision
casties
parents:
diff changeset
270 } else {
30497c6a3eca Initial revision
casties
parents:
diff changeset
271 logger("ERROR", "file entry '$ft' missing from archive!");
30497c6a3eca Initial revision
casties
parents:
diff changeset
272 $errcnt++;
30497c6a3eca Initial revision
casties
parents:
diff changeset
273 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
274 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
275
30497c6a3eca Initial revision
casties
parents:
diff changeset
276 foreach my $fa (sort keys %$archived) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
277 if (! $$archived{$fa}->[2]) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
278 my ($fn, $fp) = split_file_path($fa);
30497c6a3eca Initial revision
casties
parents:
diff changeset
279 if ($index_files{$fn}) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
280 logger("DEBUG", "$fa ignored");
30497c6a3eca Initial revision
casties
parents:
diff changeset
281 $na--;
30497c6a3eca Initial revision
casties
parents:
diff changeset
282 } else {
30497c6a3eca Initial revision
casties
parents:
diff changeset
283 logger("WARNING", "$fa archived but not in list!");
30497c6a3eca Initial revision
casties
parents:
diff changeset
284 $warncnt++;
30497c6a3eca Initial revision
casties
parents:
diff changeset
285 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
286 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
287 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
288
30497c6a3eca Initial revision
casties
parents:
diff changeset
289 if ($nt > $na) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
290 logger("WARNING", "less files were archived ($na vs. $nt)!");
30497c6a3eca Initial revision
casties
parents:
diff changeset
291 $warncnt++;
30497c6a3eca Initial revision
casties
parents:
diff changeset
292 } elsif ($na > $nt) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
293 logger("WARNING", "more files were archived ($na vs. $nt)!");
30497c6a3eca Initial revision
casties
parents:
diff changeset
294 $warncnt++;
30497c6a3eca Initial revision
casties
parents:
diff changeset
295 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
296
30497c6a3eca Initial revision
casties
parents:
diff changeset
297 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
298
30497c6a3eca Initial revision
casties
parents:
diff changeset
299 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
300 # compare_files(\%files_on_disk, \%archived_files)
30497c6a3eca Initial revision
casties
parents:
diff changeset
301 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
302 # compares the list of archived files and files on disk
30497c6a3eca Initial revision
casties
parents:
diff changeset
303 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
304 sub compare_files {
30497c6a3eca Initial revision
casties
parents:
diff changeset
305 my ($fs_files, $archived) = @_;
30497c6a3eca Initial revision
casties
parents:
diff changeset
306
30497c6a3eca Initial revision
casties
parents:
diff changeset
307 foreach my $ft (sort keys %$fs_files) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
308 next if ($index_files{$ft});
30497c6a3eca Initial revision
casties
parents:
diff changeset
309 my $fp = "$docdir/$ft";
30497c6a3eca Initial revision
casties
parents:
diff changeset
310 #logger("DEBUG", " fp: $fp");
30497c6a3eca Initial revision
casties
parents:
diff changeset
311 if ($$archived{$fp}) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
312 next if ($index_files{$ft});
30497c6a3eca Initial revision
casties
parents:
diff changeset
313
30497c6a3eca Initial revision
casties
parents:
diff changeset
314 my $asize = $$archived{$fp}[0];
30497c6a3eca Initial revision
casties
parents:
diff changeset
315 my $atime = $$archived{$fp}[1];
30497c6a3eca Initial revision
casties
parents:
diff changeset
316 my $fsize = $$fs_files{$ft}[1];
30497c6a3eca Initial revision
casties
parents:
diff changeset
317 my $ftime = $$fs_files{$ft}[2];
30497c6a3eca Initial revision
casties
parents:
diff changeset
318 if ($asize != $fsize) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
319 logger("ERROR", "archived $ft ($asize) and file on disk ($fsize) have different size!");
30497c6a3eca Initial revision
casties
parents:
diff changeset
320 $errcnt++;
30497c6a3eca Initial revision
casties
parents:
diff changeset
321 } elsif ($atime lt $ftime) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
322 logger("ERROR", "archived $ft ($atime) is older than file on disk ($ftime)!");
30497c6a3eca Initial revision
casties
parents:
diff changeset
323 $errcnt++;
30497c6a3eca Initial revision
casties
parents:
diff changeset
324 } else {
11
b19df18aa19a updated command line option parsing and logging
casties
parents: 9
diff changeset
325 logger("WARNING", "archived file $ft still on disk");
b19df18aa19a updated command line option parsing and logging
casties
parents: 9
diff changeset
326 $warncnt++;
0
30497c6a3eca Initial revision
casties
parents:
diff changeset
327 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
328 } else {
9
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
329 logger("ERROR", "file on disk '$ft' is not in archive!");
0
30497c6a3eca Initial revision
casties
parents:
diff changeset
330 $errcnt++;
30497c6a3eca Initial revision
casties
parents:
diff changeset
331 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
332 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
333 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
334
30497c6a3eca Initial revision
casties
parents:
diff changeset
335
30497c6a3eca Initial revision
casties
parents:
diff changeset
336
30497c6a3eca Initial revision
casties
parents:
diff changeset
337 #######################################################
30497c6a3eca Initial revision
casties
parents:
diff changeset
338 # main
30497c6a3eca Initial revision
casties
parents:
diff changeset
339 #
30497c6a3eca Initial revision
casties
parents:
diff changeset
340
30497c6a3eca Initial revision
casties
parents:
diff changeset
341 logger("INFO", "archivecheck $version");
30497c6a3eca Initial revision
casties
parents:
diff changeset
342
30497c6a3eca Initial revision
casties
parents:
diff changeset
343 # make shure the right user is running this program
30497c6a3eca Initial revision
casties
parents:
diff changeset
344 my $user = getlogin;
19
320c4b93bf39 *** empty log message ***
casties
parents: 11
diff changeset
345 if (not (($user eq "archive")||($user eq "root"))) {
0
30497c6a3eca Initial revision
casties
parents:
diff changeset
346 logger("ABORT", "you must be archive or root user to run this program!");
30497c6a3eca Initial revision
casties
parents:
diff changeset
347 exit 1;
30497c6a3eca Initial revision
casties
parents:
diff changeset
348 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
349
30497c6a3eca Initial revision
casties
parents:
diff changeset
350 # read index.meta file
30497c6a3eca Initial revision
casties
parents:
diff changeset
351 my ($document, $rootnode) = read_xml($metafile);
30497c6a3eca Initial revision
casties
parents:
diff changeset
352
30497c6a3eca Initial revision
casties
parents:
diff changeset
353 # check file and add archive date
30497c6a3eca Initial revision
casties
parents:
diff changeset
354 my $files_to_archive = read_resource_meta($rootnode);
30497c6a3eca Initial revision
casties
parents:
diff changeset
355
30497c6a3eca Initial revision
casties
parents:
diff changeset
356 # check for .archived file
30497c6a3eca Initial revision
casties
parents:
diff changeset
357 if (-f "$docdir/.archived") {
30497c6a3eca Initial revision
casties
parents:
diff changeset
358 logger("INFO", ".archived file exists.");
30497c6a3eca Initial revision
casties
parents:
diff changeset
359 } else {
30497c6a3eca Initial revision
casties
parents:
diff changeset
360 logger("WARNING", "no .archived file!");
30497c6a3eca Initial revision
casties
parents:
diff changeset
361 $warncnt++;
30497c6a3eca Initial revision
casties
parents:
diff changeset
362 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
363
30497c6a3eca Initial revision
casties
parents:
diff changeset
364 # check archive
9
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
365 my %archived_files = ();
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
366 my $archcnt = 0;
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
367 if ($docdir =~ /\/mpiwg\/archive\/data\/(.*)/) {
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
368 # TSM needs two different paths because of historical mount points :-(
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
369 my $docdir1 = "/mpiwg/archive/data/";
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
370 $archcnt += run_query($docdir1, \%archived_files);
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
371 my $docdir2 = "/mpiwg/archive/";
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
372 $archcnt += run_query($docdir2, \%archived_files);
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
373 } else {
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
374 $archcnt += run_query("$docdir/", \%archived_files);
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
375 }
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
376 logger("INFO", "$archcnt archives of " . (scalar keys %archived_files) . " files.");
0
30497c6a3eca Initial revision
casties
parents:
diff changeset
377
9
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
378 my $num_arch_files = (scalar keys %archived_files);
0
30497c6a3eca Initial revision
casties
parents:
diff changeset
379 if ($num_arch_files == 0) {
30497c6a3eca Initial revision
casties
parents:
diff changeset
380 logger("ABORT", "no archive of this directory!!");
30497c6a3eca Initial revision
casties
parents:
diff changeset
381 exit 1;
30497c6a3eca Initial revision
casties
parents:
diff changeset
382 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
383 logger("INFO", "$num_arch_files files archived");
30497c6a3eca Initial revision
casties
parents:
diff changeset
384
30497c6a3eca Initial revision
casties
parents:
diff changeset
385 # check list of archived files
9
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
386 check_files($files_to_archive, \%archived_files);
0
30497c6a3eca Initial revision
casties
parents:
diff changeset
387
30497c6a3eca Initial revision
casties
parents:
diff changeset
388 # read files from filesystem
30497c6a3eca Initial revision
casties
parents:
diff changeset
389 my %fsfiles;
30497c6a3eca Initial revision
casties
parents:
diff changeset
390 my %fsdirs;
30497c6a3eca Initial revision
casties
parents:
diff changeset
391 my $num_fs_files = fs_read_files($docdir, "", \%fsfiles, \%fsdirs);
30497c6a3eca Initial revision
casties
parents:
diff changeset
392
30497c6a3eca Initial revision
casties
parents:
diff changeset
393 logger("INFO", "$num_fs_files files still on disk!");
30497c6a3eca Initial revision
casties
parents:
diff changeset
394 if ($num_fs_files > 0) {
9
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
395 compare_files(\%fsfiles, \%archived_files);
0
30497c6a3eca Initial revision
casties
parents:
diff changeset
396 }
30497c6a3eca Initial revision
casties
parents:
diff changeset
397
30497c6a3eca Initial revision
casties
parents:
diff changeset
398 logger("INFO", "$warncnt warnings");
30497c6a3eca Initial revision
casties
parents:
diff changeset
399 logger("INFO", "$errcnt errors");
30497c6a3eca Initial revision
casties
parents:
diff changeset
400 if ($errcnt == 0) {
9
9c61f624d802 fixed dsmc to work with different mount points (try a few...)
casties
parents: 0
diff changeset
401 logger("DONE", "" . (scalar keys %archived_files) . " archived files OK");
11
b19df18aa19a updated command line option parsing and logging
casties
parents: 9
diff changeset
402 exit 0;
0
30497c6a3eca Initial revision
casties
parents:
diff changeset
403 } else {
30497c6a3eca Initial revision
casties
parents:
diff changeset
404 logger("ABORT", "there were $errcnt errors!!");
30497c6a3eca Initial revision
casties
parents:
diff changeset
405 exit 1;
30497c6a3eca Initial revision
casties
parents:
diff changeset
406 }