source: MondoRescue/branches/stable/mondo/src/common/libmondo-verify.c@ 1075

Last change on this file since 1075 was 1075, checked in by Bruno Cornec, 17 years ago

Improvements for USB support in mindi when called from mondo
Changelogs in C files removed from common

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