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

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

r3336@localhost: bruno | 2009-08-11 16:32:36 +0200

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