source: MondoRescue/trunk/mondo/src/common/libmondo-verify.c@ 1043

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

merge -r978:1042 $SVN_M/branches/stable

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