source: MondoRescue/branches/stable/mondo/src/common/libmondo-verify.c@ 1127

Last change on this file since 1127 was 1123, checked in by Bruno Cornec, 17 years ago

Again linker fixes (hopefully last time for now)

  • Property svn:keywords set to Id
File size: 32.5 KB
Line 
1/*
2 * $Id: libmondo-verify.c 1123 2007-02-09 22:41:03Z bruno $
3*/
4
5/**
6 * @file
7 * Functions for verifying backups (booted from hard drive, not CD).
8 */
9
10#include "my-stuff.h"
11#include "mr_mem.h"
12#include "mr_msg.h"
13#include "mondostructures.h"
14#include "libmondo-verify.h"
15#include "libmondo-gui-EXT.h"
16#include "libmondo-files-EXT.h"
17#include "libmondo-fork-EXT.h"
18#include "libmondo-stream-EXT.h"
19#include "libmondo-string-EXT.h"
20#include "libmondo-devices-EXT.h"
21#include "libmondo-tools-EXT.h"
22
23/*@unused@*/
24//static char cvsid[] = "$Id: libmondo-verify.c 1123 2007-02-09 22:41:03Z bruno $";
25
26char *vfy_tball_fname(struct s_bkpinfo *, char *, int);
27
28
29/**
30 * The number of the most recently verified afioball.
31 * @ingroup globalGroup
32 */
33int g_last_afioball_number = -1;
34
35extern char *g_getfacl;
36extern char *g_getfattr;
37
38/**
39 * Generate a list of the files that have changed, based on @c afio @c -r
40 * messages.
41 * @param changedfiles_fname Filename of the place to put a list of afio's reported changed.
42 * @param ignorefiles_fname Filename of a list of files to ignore (use "" if none).
43 * @param stderr_fname File containing afio's stderr output.
44 * @return The number of differences found (0 for a perfect backup).
45 * @bug This function seems orphaned.
46 * @ingroup utilityGroup
47 */
48long
49generate_list_of_changed_files(char *changedfiles_fname,
50 char *ignorefiles_fname, char *stderr_fname)
51{
52 /*@ buffer ********************************************************** */
53 char *command;
54 char *afio_found_changes;
55
56 /*@ int ************************************************************* */
57 int res = 0;
58
59 /*@ long ************************************************************ */
60 long afio_diffs = 0;
61
62 command = mr_malloc(2000);
63 afio_found_changes = mr_malloc(500);
64 assert_string_is_neither_NULL_nor_zerolength(changedfiles_fname);
65 assert_string_is_neither_NULL_nor_zerolength(ignorefiles_fname);
66 assert_string_is_neither_NULL_nor_zerolength(stderr_fname);
67
68 sprintf(afio_found_changes, "%s.afio", ignorefiles_fname);
69 paranoid_system("sync");
70
71/* sprintf (command,
72 "grep \"afio: \" %s | awk '{j=substr($0,8); i=index(j,\": \");printf \"/%%s\\n\",substr(j,1,i-2);}' | sort -u | grep -v \"incheckentry.*xwait\" | grep -vx \"/afio:.*\" | grep -vx \"/dev/.*\" > %s",
73 stderr_fname, afio_found_changes);
74*/
75
76 mr_msg(1, "Now scanning log file for 'afio: ' stuff");
77 sprintf(command,
78 "grep \"afio: \" %s | sed 's/afio: //' | grep -vE '^/dev/.*$' >> %s",
79 stderr_fname, afio_found_changes);
80 mr_msg(2, command);
81 res = system(command);
82 if (res) {
83 mr_msg(2, "Warning - failed to think");
84 }
85
86 mr_msg(1, "Now scanning log file for 'star: ' stuff");
87 sprintf(command,
88 "grep \"star: \" %s | sed 's/star: //' | grep -vE '^/dev/.*$' >> %s",
89 stderr_fname, afio_found_changes);
90 mr_msg(2, command);
91 res = system(command);
92 if (res) {
93 mr_msg(2, "Warning - failed to think");
94 }
95// exclude_nonexistent_files (afio_found_changes);
96 afio_diffs = count_lines_in_file(afio_found_changes);
97 sprintf(command,
98 "sort %s %s %s | uniq -c | awk '{ if ($1==\"2\") {print $2;};}' | grep -v \"incheckentry xwait()\" > %s",
99 ignorefiles_fname, afio_found_changes, afio_found_changes,
100 changedfiles_fname);
101 mr_msg(2, command);
102 paranoid_system(command);
103 mr_free(command);
104 mr_free(afio_found_changes);
105 return (afio_diffs);
106}
107
108
109/**
110 * @addtogroup LLverifyGroup
111 * @{
112 */
113/**
114 * Verify all afioballs stored on the inserted CD (or an ISO image).
115 * @param bkpinfo The backup information structure. @c bkpinfo->backup_media_type
116 * is used in this function, and the structure is also passed to verify_an_afioball_from_CD().
117 * @param mountpoint The location the CD/DVD/ISO is mounted on.
118 * @return The number of sets containing differences (0 for success).
119 */
120int verify_afioballs_on_CD(struct s_bkpinfo *bkpinfo, char *mountpoint)
121{
122
123 /*@ buffers ********************************************************* */
124 char *tmp;
125
126 /*@ int ************************************************************* */
127 int set_number = 0;
128 int retval = 0;
129 int total_sets = 0;
130 int percentage = 0;
131
132 assert_string_is_neither_NULL_nor_zerolength(mountpoint);
133 assert(bkpinfo != NULL);
134 malloc_string(tmp);
135
136 for (set_number = 0;
137 set_number < 9999
138 &&
139 !does_file_exist(vfy_tball_fname
140 (bkpinfo, mountpoint, set_number));
141 set_number++);
142 if (!does_file_exist(vfy_tball_fname(bkpinfo, mountpoint, set_number))) {
143 return (0);
144 }
145
146 if (g_last_afioball_number != set_number - 1) {
147 if (set_number == 0) {
148 mr_msg(1,
149 "Weird error in verify_afioballs_on_CD() but it's really a cosmetic error, nothing more");
150 } else {
151 retval++;
152 sprintf(tmp, "Warning - missing set(s) between %d and %d\n",
153 g_last_afioball_number, set_number - 1);
154 log_to_screen(tmp);
155 }
156 }
157 sprintf(tmp, "Verifying %s #%d's tarballs",
158 media_descriptor_string(bkpinfo->backup_media_type),
159 g_current_media_number);
160 open_evalcall_form(tmp);
161
162 for (total_sets = set_number;
163 does_file_exist(vfy_tball_fname(bkpinfo, mountpoint, total_sets));
164 total_sets++) {
165 mr_msg(1, "total_sets = %d", total_sets);
166 }
167 for (;
168 does_file_exist(vfy_tball_fname(bkpinfo, mountpoint, set_number));
169 set_number++) {
170 percentage =
171 (set_number - g_last_afioball_number) * 100 / (total_sets -
172 g_last_afioball_number);
173 update_evalcall_form(percentage);
174 mr_msg(1, "set = %d", set_number);
175 retval +=
176 verify_an_afioball_from_CD(bkpinfo,
177 vfy_tball_fname(bkpinfo, mountpoint,
178 set_number));
179 }
180 g_last_afioball_number = set_number - 1;
181 close_evalcall_form();
182 mr_free(tmp);
183 return (retval);
184}
185
186/**
187 * Verify all slices stored on the inserted CD (or a mounted ISO image).
188 * @param bkpinfo The backup information structure. Fields used:
189 * - @c compression_level
190 * - @c restore_path
191 * - @c use_lzo
192 * - @c zip_exe
193 * - @c zip_suffix
194 * @param mtpt The mountpoint the CD/DVD/ISO is mounted on.
195 * @return The number of differences (0 for perfect biggiefiles).
196 */
197int verify_all_slices_on_CD(struct s_bkpinfo *bkpinfo, char *mtpt)
198{
199
200 /*@ buffer ********************************************************** */
201 char *tmp;
202 char *mountpoint;
203// char ca, cb;
204 char *command;
205 char *sz_exe;
206 static char *bufblkA = NULL;
207 static char *bufblkB = NULL;
208 const long maxbufsize = 65536L;
209 long currsizA = 0;
210 long currsizB = 0;
211 long j;
212
213 /*@ long ************************************************************ */
214 long bigfile_num = 0;
215 long slice_num = -1;
216 int res;
217
218 static FILE *forig = NULL;
219 static struct s_filename_and_lstat_info biggiestruct;
220 static long last_bigfile_num = -1;
221 static long last_slice_num = -1;
222 FILE *pin;
223 FILE *fin;
224 int retval = 0;
225// long long outlen;
226
227 malloc_string(tmp);
228 malloc_string(mountpoint);
229 malloc_string(command);
230 malloc_string(sz_exe);
231 if (!bufblkA) {
232 bufblkA = mr_malloc(maxbufsize);
233 }
234 if (!bufblkB) {
235 bufblkB = mr_malloc(maxbufsize);
236 }
237
238 assert(bkpinfo != NULL);
239 assert_string_is_neither_NULL_nor_zerolength(mtpt);
240
241 if (bkpinfo->compression_level > 0) {
242 if (bkpinfo->use_lzo) {
243 strcpy(sz_exe, "lzop");
244 } else if (bkpinfo->use_gzip) {
245 strcpy(sz_exe, "gzip");
246 } else {
247 strcpy(sz_exe, "bzip2");
248 }
249 } else {
250 sz_exe[0] = '\0';
251 }
252
253 iamhere("before vsbf");
254 sprintf(tmp, "Verifying %s#%d's big files",
255 media_descriptor_string(bkpinfo->backup_media_type),
256 g_current_media_number);
257 open_evalcall_form(tmp);
258 iamhere("after vsbf");
259 sprintf(mountpoint, "%s/archives", mtpt);
260 if (last_bigfile_num == -1) {
261 bigfile_num = 0;
262 slice_num = 0;
263 } else if (slice_num == 0) {
264 bigfile_num = last_bigfile_num + 1;
265 slice_num = 0;
266 } else {
267 bigfile_num = last_bigfile_num;
268 slice_num = last_slice_num + 1;
269 }
270 while (does_file_exist
271 (slice_fname
272 (bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix))
273 ||
274 does_file_exist(slice_fname
275 (bigfile_num, slice_num, mountpoint, ""))) {
276// handle slices until end of CD
277 if (slice_num == 0) {
278 mr_msg(2, "ISO=%d bigfile=%ld --START--",
279 g_current_media_number, bigfile_num);
280 if (!
281 (fin =
282 fopen(slice_fname(bigfile_num, slice_num, mountpoint, ""),
283 "r"))) {
284 mr_msg(2, "Cannot open bigfile's info file");
285 } else {
286 if (fread
287 ((void *) &biggiestruct, 1, sizeof(biggiestruct),
288 fin) < sizeof(biggiestruct)) {
289 mr_msg(2, "Unable to get biggiestruct");
290 }
291 paranoid_fclose(fin);
292 }
293 sprintf(tmp, "%s/%s", bkpinfo->restore_path,
294 biggiestruct.filename);
295 mr_msg(2, "Opening biggiefile #%ld - '%s'", bigfile_num, tmp);
296 if (!(forig = fopen(tmp, "r"))) {
297 mr_msg(2, "Failed to open bigfile. Darn.");
298 retval++;
299 }
300 slice_num++;
301 } else if (does_file_exist
302 (slice_fname(bigfile_num, slice_num, mountpoint, ""))) {
303 mr_msg(2, "ISO=%d bigfile=%ld ---END---",
304 g_current_media_number, bigfile_num);
305 bigfile_num++;
306 paranoid_fclose(forig);
307 slice_num = 0;
308 } else {
309 mr_msg(2, "ISO=%d bigfile=%ld slice=%ld \r",
310 g_current_media_number, bigfile_num, slice_num);
311 if (bkpinfo->compression_level > 0) {
312 sprintf(command, "%s -dc %s 2>> %s",
313 sz_exe,
314 slice_fname(bigfile_num, slice_num, mountpoint,
315 bkpinfo->zip_suffix),
316 MONDO_LOGFILE);
317 } else {
318 sprintf(command, "cat %s",
319 slice_fname(bigfile_num, slice_num, mountpoint,
320 bkpinfo->zip_suffix));
321 }
322 if ((pin = popen(command, "r"))) {
323 res = 0;
324 while (!feof(pin)) {
325 currsizA = fread(bufblkA, 1, maxbufsize, pin);
326 if (currsizA <= 0) {
327 break;
328 }
329 currsizB = fread(bufblkB, 1, currsizA, forig);
330 if (currsizA != currsizB) {
331 res++;
332 } else {
333 for (j = 0;
334 j < currsizA && bufblkA[j] == bufblkB[j];
335 j++);
336 if (j < currsizA) {
337 res++;
338 }
339 }
340 }
341 paranoid_pclose(pin);
342 if (res && !strncmp(biggiestruct.filename, " /dev/", 5)) {
343 mr_msg(3,
344 "Ignoring differences between %s and live filesystem because it's a device and therefore the archives are stored via ntfsclone, not dd.",
345 biggiestruct.filename);
346 mr_msg(3,
347 "If you really want verification for %s, please contact the devteam and offer an incentive.",
348 biggiestruct.filename);
349 res = 0;
350 }
351 if (res) {
352 mr_msg(0,
353 "afio: \"%s\": Corrupt biggie file, says libmondo-archive.c",
354 biggiestruct.filename);
355 retval++;
356 }
357 }
358 slice_num++;
359 }
360 }
361 last_bigfile_num = bigfile_num;
362 last_slice_num = slice_num - 1;
363 if (last_slice_num < 0) {
364 last_bigfile_num--;
365 }
366 close_evalcall_form();
367 if (bufblkA) {
368 mr_free(bufblkA);
369 }
370 if (bufblkB) {
371 mr_free(bufblkB);
372 }
373 mr_free(tmp);
374 mr_free(command);
375 mr_free(sz_exe);
376 mr_free(mountpoint);
377 return (0);
378}
379
380
381
382
383
384
385/**
386 * Verify one afioball from the CD.
387 * You should be changed to the root directory (/) for this to work.
388 * @param bkpinfo The backup information structure. Fields used:
389 * - @c bkpinfo->use_lzo
390 * - @c bkpinfo->tmpdir
391 * - @c bkpinfo->zip_exe
392 * - @c bkpinfo->zip_suffix
393 * @param tarball_fname The filename of the afioball to verify.
394 * @return 0, always.
395 */
396int verify_a_tarball(struct s_bkpinfo *bkpinfo, char *tarball_fname)
397{
398 /*@ buffers ********************************************************* */
399 char *command;
400 char *outlog;
401 char *tmp;
402 // char *p;
403
404 /*@ pointers ******************************************************* */
405 FILE *pin;
406
407 /*@ long *********************************************************** */
408 long diffs = 0;
409 /* getcwd(old_pwd,MAX_STR_LEN-1); */
410
411
412 command = mr_malloc(2000);
413 malloc_string(outlog);
414 malloc_string(tmp);
415 assert(bkpinfo != NULL);
416 assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
417
418 log_it("Verifying fileset '%s'", tarball_fname);
419 /* chdir("/"); */
420 sprintf(outlog, "%s/afio.log", bkpinfo->tmpdir);
421/* if programmer forgot to say which compression thingy to use then find out */
422 if (strstr(tarball_fname, ".lzo")
423 && strcmp(bkpinfo->zip_suffix, "lzo")) {
424 mr_msg(2, "OK, I'm going to start using lzop.");
425 strcpy(bkpinfo->zip_exe, "lzop");
426 strcpy(bkpinfo->zip_suffix, "lzo");
427 bkpinfo->use_lzo = TRUE;
428 bkpinfo->use_gzip = FALSE;
429 }
430 if (strstr(tarball_fname, ".gz")
431 && strcmp(bkpinfo->zip_suffix, "gz")) {
432 mr_msg(2, "OK, I'm going to start using gzip.");
433 strcpy(bkpinfo->zip_exe, "gzip");
434 strcpy(bkpinfo->zip_suffix, "gz");
435 bkpinfo->use_lzo = FALSE;
436 bkpinfo->use_gzip = TRUE;
437 }
438 if (strstr(tarball_fname, ".bz2")
439 && strcmp(bkpinfo->zip_suffix, "bz2")) {
440 mr_msg(2, "OK, I'm going to start using bzip2.");
441 strcpy(bkpinfo->zip_exe, "bzip2");
442 strcpy(bkpinfo->zip_suffix, "bz2");
443 bkpinfo->use_lzo = FALSE;
444 bkpinfo->use_gzip = FALSE;
445 }
446 unlink(outlog);
447 if (strstr(tarball_fname, ".star")) {
448 bkpinfo->use_star = TRUE;
449 if (strstr(tarball_fname, ".bz2"))
450 sprintf(command,
451 "star -diff diffopts=mode,size,data file=%s %s >> %s 2>> %s",
452 tarball_fname,
453 (strstr(tarball_fname, ".bz2")) ? "-bz" : " ", outlog,
454 outlog);
455 } else {
456 bkpinfo->use_star = FALSE;
457 sprintf(command, "afio -r -P %s -Z %s >> %s 2>> %s",
458 bkpinfo->zip_exe, tarball_fname, outlog, outlog);
459 }
460 mr_msg(6, "command=%s", command);
461 paranoid_system(command);
462 if (length_of_file(outlog) < 10) {
463 sprintf(command, "cat %s >> %s", outlog, MONDO_LOGFILE);
464 } else {
465 sprintf(command, "cut -d: -f%d %s | sort -u",
466 (bkpinfo->use_star) ? 1 : 2, outlog);
467 pin = popen(command, "r");
468 if (pin) {
469 for (fgets(tmp, MAX_STR_LEN, pin); !feof(pin);
470 fgets(tmp, MAX_STR_LEN, pin)) {
471 if (bkpinfo->use_star) {
472 if (!strstr(tmp, "diffopts=")) {
473 while (strlen(tmp) > 0
474 && tmp[strlen(tmp) - 1] < 32) {
475 tmp[strlen(tmp) - 1] = '\0';
476 }
477 if (strchr(tmp, '/')) {
478 if (!diffs) {
479 mr_msg(0, "'%s' - differences found",
480 tarball_fname);
481 }
482 mr_msg(0, "star: /%s",
483 strip_afio_output_line(tmp));
484 diffs++;
485 }
486 }
487 } else {
488 if (!diffs) {
489 mr_msg(0, "'%s' - differences found",
490 tarball_fname);
491 }
492 mr_msg(0, "afio: /%s", strip_afio_output_line(tmp));
493 diffs++;
494 }
495 }
496 paranoid_pclose(pin);
497 } else {
498 log_OS_error(command);
499 }
500 }
501 /* chdir(old_pwd); */
502 // sprintf (tmp, "uniq -u %s >> %s", "/tmp/mondo-verify.err", MONDO_LOGFILE);
503 // paranoid_system (tmp);
504 // unlink ("/tmp/mondo-verify.err");
505 mr_free(command);
506 mr_free(outlog);
507 mr_free(tmp);
508 return (0);
509}
510
511
512
513
514
515
516/**
517 * Verify one afioball from the CD.
518 * Checks for existence (calls fatal_error() if it does not exist) and
519 * then calls verify_an_afioball().
520 * @param bkpinfo The backup information structure. Passed to verify_an_afioball().
521 * @param tarball_fname The filename of the afioball to verify.
522 * @return The return value of verify_an_afioball().
523 * @see verify_an_afioball
524 */
525int
526verify_an_afioball_from_CD(struct s_bkpinfo *bkpinfo, char *tarball_fname)
527{
528
529 /*@ int ************************************************************* */
530 int res = 0;
531
532 assert(bkpinfo != NULL);
533 assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
534
535 mr_msg(1, "Verifying %s", tarball_fname);
536 if (!does_file_exist(tarball_fname)) {
537 fatal_error("Cannot verify nonexistent afioball");
538 }
539 res = verify_a_tarball(bkpinfo, tarball_fname);
540 return (res);
541}
542
543
544/**
545 * Verify one afioball from the opened tape/CD stream.
546 * Copies the file from tape to tmpdir and then calls verify_an_afioball().
547 * @param bkpinfo The backup information structure. Passed to verify_an_afioball().
548 * @param orig_fname The original filename of the afioball to verify.
549 * @param size The size of the afioball to verify.
550 * @return The return value of verify_an_afioball().
551 * @see verify_an_afioball
552 */
553int
554verify_an_afioball_from_stream(struct s_bkpinfo *bkpinfo, char *orig_fname,
555 long long size)
556{
557
558 /*@ int ************************************************************** */
559 int retval = 0;
560 int res = 0;
561
562 /*@ buffers ********************************************************** */
563 char *tmp;
564 char *tarball_fname;
565
566 /*@ pointers ********************************************************* */
567 char *p;
568
569 malloc_string(tmp);
570 malloc_string(tarball_fname);
571 assert(bkpinfo != NULL);
572 assert_string_is_neither_NULL_nor_zerolength(orig_fname);
573
574 p = strrchr(orig_fname, '/');
575 if (!p) {
576 p = orig_fname;
577 } else {
578 p++;
579 }
580 sprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
581 paranoid_system(tmp);
582 sprintf(tarball_fname, "%s/tmpfs/temporary-%s", bkpinfo->tmpdir, p);
583 sprintf(tmp, "Temporarily copying file from tape to '%s'",
584 tarball_fname);
585/* log_it(tmp); */
586 read_file_from_stream_to_file(bkpinfo, tarball_fname, size);
587 res = verify_a_tarball(bkpinfo, tarball_fname);
588 if (res) {
589 sprintf(tmp,
590 "Afioball '%s' no longer matches your live filesystem", p);
591 mr_msg(0, tmp);
592 retval++;
593 }
594 unlink(tarball_fname);
595 mr_free(tmp);
596 mr_free(tarball_fname);
597 return (retval);
598}
599
600
601/**
602 * Verify one biggiefile form the opened tape/CD stream.
603 * @param bkpinfo The backup information structure. @c bkpinfo->tmpdir is the only field used.
604 * @param biggie_fname The filename of the biggiefile to verify.
605 * @param size The size in bytes of said biggiefile.
606 * @return 0 for success (even if the file doesn't match); nonzero for a tape error.
607 */
608int
609verify_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo,
610 char *biggie_fname, long long size)
611{
612
613 /*@ int ************************************************************* */
614 int retval = 0;
615 int res = 0;
616 int current_slice_number = 0;
617 int ctrl_chr = '\0';
618
619 /*@ char ************************************************************ */
620 char *test_file;
621 char *biggie_cksum;
622 char *orig_cksum;
623 char *tmp;
624 char *slice_fnam;
625
626 /*@ pointers ******************************************************** */
627 char *p;
628
629 /*@ long long ******************************************************* */
630 long long slice_siz;
631
632 malloc_string(test_file);
633 malloc_string(biggie_cksum);
634 malloc_string(orig_cksum);
635 malloc_string(tmp);
636 malloc_string(slice_fnam);
637 assert(bkpinfo != NULL);
638 assert_string_is_neither_NULL_nor_zerolength(biggie_fname);
639
640 p = strrchr(biggie_fname, '/');
641 if (!p) {
642 p = biggie_fname;
643 } else {
644 p++;
645 }
646 sprintf(test_file, "%s/temporary-%s", bkpinfo->tmpdir, p);
647 sprintf(tmp,
648 "Temporarily copying biggiefile %s's slices from tape to '%s'",
649 p, test_file);
650/* log_it(tmp); */
651 for (res =
652 read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr);
653 ctrl_chr != BLK_STOP_A_BIGGIE;
654 res =
655 read_header_block_from_stream(&slice_siz, slice_fnam,
656 &ctrl_chr)) {
657 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
658 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
659 }
660 res = read_file_from_stream_to_file(bkpinfo, test_file, slice_siz);
661 unlink(test_file);
662 res =
663 read_header_block_from_stream(&slice_siz, slice_fnam,
664 &ctrl_chr);
665 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
666 mr_msg(2, "test_file = %s", test_file);
667 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
668 }
669 current_slice_number++;
670 retval += res;
671 }
672 strcpy(biggie_cksum, slice_fnam);
673 if (biggie_cksum[0] != '\0') {
674 strcpy(orig_cksum, calc_checksum_of_file(biggie_fname));
675 if (strcmp(biggie_cksum, orig_cksum)) {
676 sprintf(tmp, "orig cksum=%s; curr cksum=%s", biggie_cksum,
677 orig_cksum);
678 mr_msg(2, tmp);
679 sprintf(tmp, "%s has changed on live filesystem",
680 biggie_fname);
681 log_to_screen(tmp);
682 sprintf(tmp, "echo \"%s\" >> /tmp/biggies.changed",
683 biggie_fname);
684 system(tmp);
685 }
686 }
687 mr_free(test_file);
688 mr_free(biggie_cksum);
689 mr_free(orig_cksum);
690 mr_free(tmp);
691 mr_free(slice_fnam);
692 return (retval);
693}
694
695
696/**
697 * Verify all afioballs from the opened tape/CD stream.
698 * @param bkpinfo The backup information structure. Fields used:
699 * - @c bkpinfo->restore_path
700 * - @c bkpinfo->tmpdir
701 *
702 * @return 0 for success (even if there are differences); nonzero for a tape error.
703 */
704int verify_afioballs_from_stream(struct s_bkpinfo *bkpinfo)
705{
706 /*@ int ********************************************************** */
707 int retval = 0;
708 int res = 0;
709 long current_afioball_number = 0;
710 int ctrl_chr = 0;
711 int total_afioballs = 0;
712
713 /*@ buffers ***************************************************** */
714 char *tmp;
715 char *fname;
716 char *curr_xattr_list_fname;
717 char *curr_acl_list_fname;
718
719 /*@ long long *************************************************** */
720 long long size = 0;
721
722 assert(bkpinfo != NULL);
723 malloc_string(tmp);
724 malloc_string(fname);
725 malloc_string(curr_xattr_list_fname);
726 malloc_string(curr_acl_list_fname);
727
728 if (g_getfattr) {
729 sprintf(curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ,
730 bkpinfo->tmpdir);
731 }
732 if (g_getfacl) {
733 sprintf(curr_acl_list_fname, ACL_BIGGLST_FNAME_RAW_SZ,
734 bkpinfo->tmpdir);
735 }
736 log_to_screen("Verifying regular archives on tape");
737 total_afioballs = get_last_filelist_number(bkpinfo) + 1;
738 open_progress_form("Verifying filesystem",
739 "I am verifying archives against your live filesystem now.",
740 "Please wait. This may take a couple of hours.", "",
741 total_afioballs);
742 res = read_header_block_from_stream(&size, fname, &ctrl_chr);
743 if (ctrl_chr != BLK_START_AFIOBALLS) {
744 iamhere("YOU SHOULD NOT GET HERE");
745 iamhere("Grabbing the EXAT files");
746 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
747 res =
748 read_EXAT_files_from_tape(bkpinfo, &size, fname, &ctrl_chr,
749 curr_xattr_list_fname,
750 curr_acl_list_fname);
751 }
752 }
753 if (ctrl_chr != BLK_START_AFIOBALLS) {
754 wrong_marker(BLK_START_AFIOBALLS, ctrl_chr);
755 }
756
757 for (res = read_header_block_from_stream(&size, fname, &ctrl_chr);
758 ctrl_chr != BLK_STOP_AFIOBALLS;
759 res = read_header_block_from_stream(&size, fname, &ctrl_chr)) {
760 if (g_getfattr) {
761 sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
762 bkpinfo->tmpdir, current_afioball_number);
763 }
764 if (g_getfacl) {
765 sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
766 bkpinfo->tmpdir, current_afioball_number);
767 }
768 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
769 iamhere("Reading EXAT files from tape");
770 res =
771 read_EXAT_files_from_tape(bkpinfo, &size, fname, &ctrl_chr,
772 curr_xattr_list_fname,
773 curr_acl_list_fname);
774 }
775 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
776 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
777 }
778 sprintf(tmp, "Verifying fileset #%ld", current_afioball_number);
779 /*log_it(tmp); */
780 update_progress_form(tmp);
781 res = verify_an_afioball_from_stream(bkpinfo, fname, size);
782 if (res) {
783 sprintf(tmp, "Afioball %ld differs from live filesystem",
784 current_afioball_number);
785 log_to_screen(tmp);
786 }
787 retval += res;
788 current_afioball_number++;
789 g_current_progress++;
790 res = read_header_block_from_stream(&size, fname, &ctrl_chr);
791 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
792 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
793 }
794 }
795 mr_msg(1, "All done with afioballs");
796 close_progress_form();
797 mr_free(tmp);
798 mr_free(fname);
799 mr_free(curr_xattr_list_fname);
800 mr_free(curr_acl_list_fname);
801 return (retval);
802}
803
804/**
805 * Verify all biggiefiles on the opened CD/tape stream.
806 * @param bkpinfo The backup information structure. Fields used:
807 * - @c bkpinfo->restore_path
808 * - @c bkpinfo->tmpdir
809 *
810 * @return 0 for success (even if there are differences); nonzero for a tape error.
811 */
812int verify_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo)
813{
814
815 /*@ int ************************************************************ */
816 int retval = 0;
817 int res = 0;
818 int ctrl_chr = 0;
819
820 /*@ long *********************************************************** */
821 long noof_biggiefiles = 0;
822 long current_biggiefile_number = 0;
823
824 /*@ buffers ******************************************************** */
825 char *tmp;
826 char *orig_fname, *logical_fname;
827 char *comment;
828 char *curr_xattr_list_fname;
829 char *curr_acl_list_fname;
830 /*@ pointers ******************************************************* */
831 char *p;
832
833 /*@ long long size ************************************************* */
834 long long size = 0;
835
836 assert(bkpinfo != NULL);
837 malloc_string(tmp);
838 malloc_string(orig_fname);
839 malloc_string(logical_fname);
840 malloc_string(comment);
841 malloc_string(curr_xattr_list_fname);
842 malloc_string(curr_acl_list_fname);
843
844 if (g_getfattr) {
845 sprintf(curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ,
846 bkpinfo->tmpdir);
847 }
848 if (g_getfacl) {
849 sprintf(curr_acl_list_fname, ACL_BIGGLST_FNAME_RAW_SZ,
850 bkpinfo->tmpdir);
851 }
852 sprintf(comment, "Verifying all bigfiles.");
853 log_to_screen(comment);
854 sprintf(tmp, "%s/biggielist.txt", bkpinfo->tmpdir);
855// noof_biggiefiles = count_lines_in_file (tmp); // pointless
856 res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr);
857 if (ctrl_chr != BLK_START_BIGGIEFILES) {
858 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
859 iamhere("Grabbing the EXAT biggiefiles");
860 res =
861 read_EXAT_files_from_tape(bkpinfo, &size, orig_fname,
862 &ctrl_chr, curr_xattr_list_fname,
863 curr_acl_list_fname);
864 }
865 }
866 if (ctrl_chr != BLK_START_BIGGIEFILES) {
867 wrong_marker(BLK_START_BIGGIEFILES, ctrl_chr);
868 }
869 noof_biggiefiles = (long) size;
870 mr_msg(1, "noof_biggiefiles = %ld", noof_biggiefiles);
871 open_progress_form("Verifying big files", comment,
872 "Please wait. This may take some time.", "",
873 noof_biggiefiles);
874 for (res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr);
875 ctrl_chr != BLK_STOP_BIGGIEFILES;
876 res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr))
877 {
878 if (ctrl_chr != BLK_START_A_NORMBIGGIE
879 && ctrl_chr != BLK_START_A_PIHBIGGIE) {
880 wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr);
881 }
882 p = strrchr(orig_fname, '/');
883 if (!p) {
884 p = orig_fname;
885 } else {
886 p++;
887 }
888 sprintf(comment, "Verifying bigfile #%ld (%ld K)",
889 current_biggiefile_number, (long) size >> 10);
890 update_progress_form(comment);
891 sprintf(logical_fname, "%s/%s", bkpinfo->restore_path, orig_fname);
892 res =
893 verify_a_biggiefile_from_stream(bkpinfo, logical_fname, size);
894 retval += res;
895 current_biggiefile_number++;
896 g_current_progress++;
897 }
898 close_progress_form();
899 mr_free(orig_fname);
900 mr_free(logical_fname);
901 mr_free(curr_xattr_list_fname);
902 mr_free(curr_acl_list_fname);
903 mr_free(comment);
904 mr_free(tmp);
905 return (retval);
906}
907
908/* @} - end of LLverifyGroup */
909
910
911/**
912 * Verify the CD indicated by @c g_current_media_number.
913 * @param bkpinfo The backup information structure. Fields used:
914 * - @c bkpinfo->isodir
915 * - @c bkpinfo->prefix
916 * - @c bkpinfo->manual_cd_tray
917 * - @c bkpinfo->media_device
918 * - @c bkpinfo->nfs_remote_dir
919 * - @c bkpinfo->tmpdir
920 * - @c bkpinfo->verify_data
921 *
922 * @return 0 for success (even if differences are found), nonzero for failure.
923 * @ingroup verifyGroup
924 */
925int verify_cd_image(struct s_bkpinfo *bkpinfo)
926{
927
928 /*@ int ************************************************************ */
929 int retval = 0;
930
931 /*@ buffers ******************************************************** */
932 char *mountpoint;
933 char *command;
934 char *tmp;
935 char *fname;
936#ifdef __FreeBSD__
937 char mdd[32];
938 char *mddevice = mdd;
939 int ret = 0;
940 int vndev = 2;
941#else
942//skip
943#endif
944
945 command = mr_malloc(2000);
946 malloc_string(mountpoint);
947 malloc_string(tmp);
948 malloc_string(fname);
949
950 assert(bkpinfo != NULL);
951
952 sprintf(mountpoint, "%s/cdrom", bkpinfo->tmpdir);
953 sprintf(fname, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->nfs_remote_dir,
954 bkpinfo->prefix, g_current_media_number);
955
956 mkdir(mountpoint, 1777);
957 sync();
958 if (!does_file_exist(fname)) {
959 sprintf(tmp,
960 "%s not found; assuming you backed up to CD; verifying CD...",
961 fname);
962 mr_msg(2, tmp);
963 if (bkpinfo->manual_cd_tray) {
964 popup_and_OK("Please push CD tray closed.");
965 }
966 if (find_and_mount_actual_cd(bkpinfo, mountpoint)) {
967 log_to_screen("failed to mount actual CD");
968 return (1);
969 }
970 } else {
971 sprintf(tmp, "%s found; verifying ISO...", fname);
972#ifdef __FreeBSD__
973 ret = 0;
974 vndev = 2;
975 mddevice = make_vn(fname);
976 if (ret) {
977 sprintf(tmp, "make_vn of %s failed; unable to verify ISO\n",
978 fname);
979 log_to_screen(tmp);
980 return (1);
981 }
982 sprintf(command, "mount_cd9660 %s %s", mddevice, mountpoint);
983#else
984 sprintf(command, "mount -o loop,ro -t iso9660 %s %s", fname,
985 mountpoint);
986#endif
987 if (run_program_and_log_output(command, FALSE)) {
988 sprintf(tmp, "%s failed; unable to mount ISO image\n",
989 command);
990 log_to_screen(tmp);
991 return (1);
992 }
993 }
994 mr_msg(2, "OK, I've mounted the ISO/CD\n");
995 sprintf(tmp, "%s/archives/NOT-THE-LAST", mountpoint);
996 if (!does_file_exist(tmp)) {
997 mr_msg
998 (2,
999 "This is the last CD. I am therefore setting bkpinfo->verify_data to FALSE.");
1000 bkpinfo->verify_data = FALSE;
1001/*
1002 (a) It's an easy way to tell the calling subroutine that we've finished &
1003 there are no more CD's to be verified; (b) It stops the post-backup verifier
1004 from running after the per-CD verifier has run too.
1005*/
1006 }
1007 verify_afioballs_on_CD(bkpinfo, mountpoint);
1008 iamhere("before verify_all_slices");
1009 verify_all_slices_on_CD(bkpinfo, mountpoint);
1010
1011#ifdef __FreeBSD__
1012 ret = 0;
1013 sprintf(command, "umount %s", mountpoint);
1014 ret += system(command);
1015 ret += kick_vn(mddevice);
1016 if (ret)
1017#else
1018 sprintf(command, "umount %s", mountpoint);
1019 if (system(command))
1020#endif
1021 {
1022 sprintf(tmp, "%s failed; unable to unmount ISO image\n", command);
1023 log_to_screen(tmp);
1024 retval++;
1025 } else {
1026 mr_msg(2, "OK, I've unmounted the ISO file\n");
1027 }
1028 if (!does_file_exist(fname)) {
1029 sprintf(command, "umount %s", bkpinfo->media_device);
1030 run_program_and_log_output(command, 2);
1031 if (!bkpinfo->please_dont_eject
1032 && eject_device(bkpinfo->media_device)) {
1033 mr_msg(2, "Failed to eject CD-ROM drive");
1034 }
1035 }
1036 mr_free(command);
1037 mr_free(mountpoint);
1038 mr_free(tmp);
1039 mr_free(fname);
1040 return (retval);
1041}
1042
1043/**
1044 * Verify all backups on tape.
1045 * This should be done after the backup process has already closed the tape.
1046 * @param bkpinfo The backup information structure. Passed to various helper functions.
1047 * @return 0 for success (even if thee were differences), nonzero for failure.
1048 * @ingroup verifyGroup
1049 */
1050int verify_tape_backups(struct s_bkpinfo *bkpinfo)
1051{
1052
1053 /*@ int ************************************************************ */
1054 int retval = 0;
1055
1056 /*@ buffers ******************************************************** */
1057 char tmp[MAX_STR_LEN];
1058 char changed_files_fname[MAX_STR_LEN];
1059
1060 /*@ long *********************************************************** */
1061 long diffs = 0;
1062
1063 assert(bkpinfo != NULL);
1064
1065 mr_msg(3, "verify_tape_backups --- starting");
1066 log_to_screen("Verifying backups");
1067 openin_tape(bkpinfo);
1068/* verify archives themselves */
1069 retval += verify_afioballs_from_stream(bkpinfo);
1070 retval += verify_biggiefiles_from_stream(bkpinfo);
1071/* find the final blocks */
1072 paranoid_system("sync");
1073 sleep(2);
1074 closein_tape(bkpinfo);
1075/* close tape; exit */
1076// fclose(g_tape_stream); <-- not needed; is handled by closein_tape()
1077 paranoid_system
1078 ("rm -f /tmp/biggies.changed /tmp/changed.files.[0-9]* 2> /dev/null");
1079 sprintf(changed_files_fname, "/tmp/changed.files.%d",
1080 (int) (random() % 32767));
1081 sprintf(tmp,
1082 "grep -E '^%s:.*$' %s | cut -d'\"' -f2 | sort -u | awk '{print \"/\"$0;};' | tr -s '/' '/' | grep -v \"(total of\" | grep -v \"incheckentry.*xwait\" | grep -vE '^/afio:.*$' | grep -vE '^dev/.*$' > %s",
1083 (bkpinfo->use_star) ? "star" : "afio", MONDO_LOGFILE,
1084 changed_files_fname);
1085 mr_msg(2, "Running command to derive list of changed files");
1086 mr_msg(2, tmp);
1087 if (system(tmp)) {
1088 if (does_file_exist(changed_files_fname)
1089 && length_of_file(changed_files_fname) > 2) {
1090 log_to_screen
1091 ("Warning - unable to check logfile to derive list of changed files");
1092 } else {
1093 log_to_screen
1094 ("No differences found. Therefore, no 'changed.files' text file.");
1095 }
1096 }
1097 sprintf(tmp, "cat /tmp/biggies.changed >> %s", changed_files_fname);
1098 paranoid_system(tmp);
1099
1100 diffs = count_lines_in_file(changed_files_fname);
1101 if (diffs > 0) {
1102 sprintf(tmp, "cp -f %s %s", changed_files_fname,
1103 "/tmp/changed.files");
1104 run_program_and_log_output(tmp, FALSE);
1105 sprintf(tmp,
1106 "%ld files differed from live filesystem; type less %s or less %s to see",
1107 diffs, changed_files_fname, "/tmp/changed.files");
1108 mr_msg(0, tmp);
1109 log_to_screen
1110 ("See /tmp/changed.files for a list of nonmatching files.");
1111 log_to_screen
1112 ("The files probably changed on filesystem, not on backup media.");
1113 // retval++;
1114 }
1115 return (retval);
1116}
1117
1118
1119
1120/**
1121 * Generate the filename of a tarball to verify.
1122 * @param bkpinfo The backup information structure. @c bkpinfo->zip_suffix is the only field used.
1123 * @param mountpoint The directory where the CD/DVD/ISO is mounted.
1124 * @param setno The afioball number to get the location of.
1125 * @return The absolute path to the afioball.
1126 * @note The returned string points to static data that will be overwritten with each call.
1127 * @ingroup stringGroup
1128 */
1129char *vfy_tball_fname(struct s_bkpinfo *bkpinfo, char *mountpoint,
1130 int setno)
1131{
1132 /*@ buffers ******************************************************* */
1133 static char output[MAX_STR_LEN];
1134
1135 assert(bkpinfo != NULL);
1136 assert_string_is_neither_NULL_nor_zerolength(mountpoint);
1137 sprintf(output, "%s/archives/%d.star.%s", mountpoint, setno,
1138 bkpinfo->zip_suffix);
1139 if (!does_file_exist(output)) {
1140 sprintf(output, "%s/archives/%d.afio.%s", mountpoint, setno,
1141 bkpinfo->zip_suffix);
1142 }
1143 return (output);
1144}
Note: See TracBrowser for help on using the repository browser.