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

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

Suppress lib-common-externs.h useless

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