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

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

r3334@localhost: bruno | 2009-08-08 12:17:37 +0200

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