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

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

log_msg => mr_msg in trunk

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