source: MondoRescue/branches/2.2.10/mondo/src/common/libmondo-verify.c@ 2326

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

r3337@localhost: bruno | 2009-08-11 20:02:18 +0200
bkpinfo->boot_device and bkpinfo->zip_exe are now dynamically allocated

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