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

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

Logfile management in mondo (partly)

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