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

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

merge -r1045:1078 £SVN_M/branches/stable

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