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

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

Patch from Scott Cummings (<rsc_at_usfamily.net>):
No compression for iso backup is probably not a commonly used option (-0),
but I wanted to run a backup and a verify as quickly as possible just to try out mondo. In the
process I also tested the case of a verify with a missing big file in
the filesystem (after the backup). That caused a segfault when it tried
to read the non-existent file.
Attached patch changes make "verify_all_slices_on_CD" actually
verify the uncompressed big file slices (instead of just skipping them).

It also has small message enhancements for -0 compression verify.

  • really verify uncompressed big file slices
  • log 'cat' (0 compression) errors
  • detect if no zip_suffix (in case forget -0 on command line)
  • avoid segfault in fread if bigfile fails to open on filesystem
  • report missing filesystem big file
  • generate hundreds of errors about ntfs filesystem not comparing :)

(does it do this for any change in ntfs partition? maybe something

else was going on.)

Yet to do is make afioballs auto detect if they are uncompressed.

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