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

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

merge -r902:913 $SVN_M/branches/stable

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