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

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