source: MondoRescue/branches/2.2.9/mondo/src/common/libmondo-verify.c@ 2227

Last change on this file since 2227 was 2227, checked in by Bruno Cornec, 15 years ago

Remove the iamhere function (will hopefully suppress valgrind errors at restore time)

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