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

Last change on this file since 1769 was 1769, checked in by Bruno Cornec, 16 years ago

Continue on configuration file items (compression)

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