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

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

Merge trunk modifications for libmondo-verify.c

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