source: MondoRescue/trunk/mondo/mondo/common/libmondo-verify.c@ 485

Last change on this file since 485 was 485, checked in by andree, 18 years ago

Fixed verify for NFS by swapping nfs_remote_dir and prefix when
assembling name for image file to verify.

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