Changeset 3878 in MondoRescue for branches/3.3/mondo/src/common/libmondo-verify.c
- Timestamp:
- Mar 8, 2024, 12:15:10 PM (4 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mondo/src/common/libmondo-verify.c
r3877 r3878 122 122 mr_free(command); 123 123 return (afio_diffs); 124 } 125 126 127 128 129 130 /** 131 * Verify one afioball from the CD. 132 * You should be changed to the root directory (/) for this to work. 133 * @param bkpinfo The backup information structure. Fields used: 134 * - @c bkpinfo->use_lzo 135 * - @c bkpinfo->tmpdir 136 * - @c bkpinfo->zip_exe 137 * - @c bkpinfo->zip_suffix 138 * @param tarball_fname The filename of the afioball to verify. 139 * @return 0, always. 140 */ 141 int verify_a_tarball(char *tarball_fname) 142 { 143 /*@ buffers ********************************************************* */ 144 char *command = NULL; 145 char *outlog = NULL; 146 char *tmp = NULL; 147 148 /*@ pointers ******************************************************* */ 149 FILE *pin; 150 151 /*@ long *********************************************************** */ 152 long diffs = 0; 153 154 assert(bkpinfo != NULL); 155 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 156 157 log_it("Verifying fileset '%s'", tarball_fname); 158 mr_asprintf(outlog, "%s/afio.log", bkpinfo->tmpdir); 159 /* if programmer forgot to say which compression thingy to use then find out */ 160 if (strstr(tarball_fname, ".lzo") && strcmp(bkpinfo->zip_suffix, "lzo")) { 161 log_msg(2, "OK, I'm going to start using lzop."); 162 mr_free(bkpinfo->zip_exe); 163 mr_free(bkpinfo->zip_suffix); 164 mr_asprintf(bkpinfo->zip_exe, "%s", "lzop"); 165 mr_asprintf(bkpinfo->zip_suffix, "%s", "lzo"); 166 bkpinfo->use_lzo = TRUE; 167 bkpinfo->use_gzip = FALSE; 168 bkpinfo->use_lzma = FALSE; 169 } 170 if (strstr(tarball_fname, ".gz") && strcmp(bkpinfo->zip_suffix, "gz")) { 171 log_msg(2, "OK, I'm going to start using gzip."); 172 mr_free(bkpinfo->zip_exe); 173 mr_free(bkpinfo->zip_suffix); 174 mr_asprintf(bkpinfo->zip_exe, "%s", "gzip"); 175 mr_asprintf(bkpinfo->zip_suffix, "%s", "gz"); 176 bkpinfo->use_lzo = FALSE; 177 bkpinfo->use_gzip = TRUE; 178 bkpinfo->use_lzma = FALSE; 179 } 180 if (strstr(tarball_fname, ".bz2") && strcmp(bkpinfo->zip_suffix, "bz2")) { 181 log_msg(2, "OK, I'm going to start using bzip2."); 182 mr_free(bkpinfo->zip_exe); 183 mr_free(bkpinfo->zip_suffix); 184 mr_asprintf(bkpinfo->zip_exe, "%s", "bzip2"); 185 mr_asprintf(bkpinfo->zip_suffix, "%s", "bz2"); 186 bkpinfo->use_lzo = FALSE; 187 bkpinfo->use_gzip = FALSE; 188 bkpinfo->use_lzma = FALSE; 189 } 190 if (strstr(tarball_fname, ".xz") && strcmp(bkpinfo->zip_suffix, "xz")) { 191 log_msg(2, "OK, I'm going to start using lzma."); 192 mr_free(bkpinfo->zip_exe); 193 mr_free(bkpinfo->zip_suffix); 194 mr_asprintf(bkpinfo->zip_exe, "%s", "xz"); 195 mr_asprintf(bkpinfo->zip_suffix, "%s", "xz"); 196 bkpinfo->use_lzo = FALSE; 197 bkpinfo->use_gzip = FALSE; 198 bkpinfo->use_lzma = TRUE; 199 } 200 // As suffix is used even when no compression make it non-NULL 201 if (bkpinfo->zip_suffix == NULL) { 202 mr_asprintf(bkpinfo->zip_suffix, "%s", ""); 203 } 204 unlink(outlog); 205 if (strstr(tarball_fname, ".star")) { 206 bkpinfo->use_star = TRUE; 207 if (strstr(tarball_fname, ".bz2")) 208 mr_asprintf(command, "star -sparse -diff diffopts=mode,size,data file=%s %s >> %s 2>> %s", tarball_fname, (strstr(tarball_fname, ".bz2")) ? "-bz" : " ", outlog, outlog); 209 } else { 210 bkpinfo->use_star = FALSE; 211 /* Here we suppose that there is always a compression program called */ 212 if (bkpinfo->zip_exe) { 213 mr_asprintf(command, "afio -r -P %s -Z %s >> %s 2>> %s", bkpinfo->zip_exe, tarball_fname, outlog, outlog); 214 } else { 215 mr_asprintf(command, "afio -r -Z %s >> %s 2>> %s", tarball_fname, outlog, outlog); 216 } 217 } 218 log_msg(6, "command=%s", command); 219 paranoid_system(command); 220 mr_free(command); 221 222 if (length_of_file(outlog) < 10) { 223 mr_asprintf(command, "cat %s >> %s", outlog, MONDO_LOGFILE); 224 } else { 225 mr_asprintf(command, "cut -d: -f%d %s | sort -u", (bkpinfo->use_star) ? 1 : 2, outlog); 226 pin = popen(command, "r"); 227 if (pin) { 228 for (mr_getline(tmp, pin); !feof(pin); mr_getline(tmp, pin)) { 229 if (bkpinfo->use_star) { 230 if (!strstr(tmp, "diffopts=")) { 231 while (strlen(tmp) > 0 && tmp[strlen(tmp) - 1] < 32) { 232 tmp[strlen(tmp) - 1] = '\0'; 233 } 234 if (strchr(tmp, '/')) { 235 if (!diffs) { 236 log_msg(0, "'%s' - differences found", tarball_fname); 237 } 238 log_msg(0, "star: /%s", strip_afio_output_line(tmp)); 239 diffs++; 240 } 241 } 242 } else { 243 if (!diffs) { 244 log_msg(0, "'%s' - differences found", tarball_fname); 245 } 246 log_msg(0, "afio: /%s", strip_afio_output_line(tmp)); 247 diffs++; 248 } 249 mr_free(tmp); 250 } 251 mr_free(tmp); 252 paranoid_pclose(pin); 253 } else { 254 log_OS_error(command); 255 } 256 } 257 mr_free(command); 258 mr_free(outlog); 259 return (0); 260 } 261 262 263 264 265 266 /** 267 * Verify one afioball from the CD. 268 * Checks for existence (calls fatal_error() if it does not exist) and 269 * then calls verify_an_afioball(). 270 * @param bkpinfo The backup information structure. Passed to verify_an_afioball(). 271 * @param tarball_fname The filename of the afioball to verify. 272 * @return The return value of verify_an_afioball(). 273 * @see verify_an_afioball 274 */ 275 int 276 verify_an_afioball_from_CD(char *tarball_fname) 277 { 278 279 /*@ int ************************************************************* */ 280 int res = 0; 281 282 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 283 284 log_msg(1, "Verifying %s", tarball_fname); 285 if (!does_file_exist(tarball_fname)) { 286 fatal_error("Cannot verify nonexistent afioball"); 287 } 288 res = verify_a_tarball(tarball_fname); 289 return (res); 290 } 291 292 293 /** 294 * Verify one afioball from the opened tape/CD stream. 295 * Copies the file from tape to tmpdir and then calls verify_an_afioball(). 296 * @param bkpinfo The backup information structure. Passed to verify_an_afioball(). 297 * @param orig_fname The original filename of the afioball to verify. 298 * @param size The size of the afioball to verify. 299 * @return The return value of verify_an_afioball(). 300 * @see verify_an_afioball 301 */ 302 int 303 verify_an_afioball_from_stream(char *orig_fname, long long size) 304 { 305 306 /*@ int ************************************************************** */ 307 int retval = 0; 308 int res = 0; 309 310 /*@ buffers ********************************************************** */ 311 char *tmp = NULL; 312 char *tarball_fname = NULL; 313 314 /*@ pointers ********************************************************* */ 315 char *p; 316 317 assert(bkpinfo != NULL); 318 assert_string_is_neither_NULL_nor_zerolength(orig_fname); 319 320 p = strrchr(orig_fname, '/'); 321 if (!p) { 322 p = orig_fname; 323 } else { 324 p++; 325 } 326 mr_asprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir); 327 paranoid_system(tmp); 328 mr_free(tmp); 329 330 mr_asprintf(tarball_fname, "%s/tmpfs/temporary-%s", bkpinfo->tmpdir, p); 331 read_file_from_stream_to_file(tarball_fname, size); 332 res = verify_a_tarball(tarball_fname); 333 if (res) { 334 log_msg(0, "Afioball '%s' no longer matches your live filesystem", p); 335 retval++; 336 } 337 unlink(tarball_fname); 338 mr_free(tarball_fname); 339 return (retval); 340 } 341 342 343 /** 344 * Verify one biggiefile form the opened tape/CD stream. 345 * @param bkpinfo The backup information structure. @c bkpinfo->tmpdir is the only field used. 346 * @param biggie_fname The filename of the biggiefile to verify. 347 * @param size The size in bytes of said biggiefile. 348 * @return 0 for success (even if the file doesn't match); nonzero for a tape error. 349 */ 350 int 351 verify_a_biggiefile_from_stream(char *biggie_fname, long long size) 352 { 353 354 /*@ int ************************************************************* */ 355 int retval = 0; 356 int res = 0; 357 int current_slice_number = 0; 358 int ctrl_chr = '\0'; 359 360 /*@ char ************************************************************ */ 361 char *test_file = NULL; 362 char *biggie_cksum = NULL; 363 char *orig_cksum = NULL; 364 char *tmp = NULL; 365 char *slice_fnam = NULL; 366 367 /*@ pointers ******************************************************** */ 368 char *p; 369 370 /*@ long long ******************************************************* */ 371 long long slice_siz; 372 373 malloc_string(slice_fnam); 374 assert(bkpinfo != NULL); 375 assert_string_is_neither_NULL_nor_zerolength(biggie_fname); 376 377 p = strrchr(biggie_fname, '/'); 378 if (!p) { 379 p = biggie_fname; 380 } else { 381 p++; 382 } 383 mr_asprintf(test_file, "%s/temporary-%s", bkpinfo->tmpdir, p); 384 for (res = 385 read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr); 386 ctrl_chr != BLK_STOP_A_BIGGIE; 387 res = 388 read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr)) { 389 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) { 390 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); 391 } 392 res = read_file_from_stream_to_file(test_file, slice_siz); 393 unlink(test_file); 394 res = 395 read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr); 396 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) { 397 log_msg(2, "test_file = %s", test_file); 398 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr); 399 } 400 current_slice_number++; 401 retval += res; 402 } 403 mr_asprintf(biggie_cksum, "%s", slice_fnam); 404 if (biggie_cksum[0] != '\0') { 405 mr_asprintf(orig_cksum, "%s", calc_checksum_of_file(biggie_fname)); 406 if (strcmp(biggie_cksum, orig_cksum)) { 407 log_msg(2, "orig cksum=%s; curr cksum=%s", biggie_cksum, orig_cksum); 408 log_to_screen("%s has changed on live filesystem", biggie_fname); 409 410 mr_asprintf(tmp, "echo \"%s\" >> %s/biggies.changed", biggie_fname, bkpinfo->tmpdir); 411 paranoid_system(tmp); 412 mr_free(tmp); 413 } 414 mr_free(orig_cksum); 415 } 416 mr_free(biggie_cksum); 417 mr_free(test_file); 418 paranoid_free(slice_fnam); 419 return (retval); 420 } 421 422 423 /** 424 * Verify all afioballs from the opened tape/CD stream. 425 * @param bkpinfo The backup information structure. Fields used: 426 * - @c bkpinfo->tmpdir 427 * 428 * @return 0 for success (even if there are differences); nonzero for a tape error. 429 */ 430 int verify_afioballs_from_stream() 431 { 432 /*@ int ********************************************************** */ 433 int retval = 0; 434 int res = 0; 435 long current_afioball_number = 0; 436 int ctrl_chr = 0; 437 int total_afioballs = 0; 438 439 /*@ buffers ***************************************************** */ 440 char *tmp = NULL; 441 char *fname; 442 char *curr_xattr_list_fname; 443 char *curr_acl_list_fname; 444 445 /*@ long long *************************************************** */ 446 long long size = 0; 447 448 assert(bkpinfo != NULL); 449 malloc_string(fname); 450 malloc_string(curr_xattr_list_fname); 451 malloc_string(curr_acl_list_fname); 452 453 if (g_getfattr) { 454 sprintf(curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ, 455 bkpinfo->tmpdir); 456 } 457 if (g_getfacl) { 458 sprintf(curr_acl_list_fname, ACL_BIGGLST_FNAME_RAW_SZ, 459 bkpinfo->tmpdir); 460 } 461 log_to_screen("Verifying regular archives on tape"); 462 total_afioballs = get_last_filelist_number() + 1; 463 open_progress_form("Verifying filesystem", 464 "I am verifying archives against your live filesystem now.", 465 "Please wait. This may take a couple of hours.", "", 466 total_afioballs); 467 res = read_header_block_from_stream(&size, fname, &ctrl_chr); 468 if (ctrl_chr != BLK_START_AFIOBALLS) { 469 log_it("YOU SHOULD NOT GET HERE"); 470 log_it("Grabbing the EXAT files"); 471 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) { 472 res = read_EXAT_files_from_tape(&size, fname, &ctrl_chr, 473 curr_xattr_list_fname, 474 curr_acl_list_fname); 475 } 476 } 477 if (ctrl_chr != BLK_START_AFIOBALLS) { 478 wrong_marker(BLK_START_AFIOBALLS, ctrl_chr); 479 } 480 481 for (res = read_header_block_from_stream(&size, fname, &ctrl_chr); 482 ctrl_chr != BLK_STOP_AFIOBALLS; 483 res = read_header_block_from_stream(&size, fname, &ctrl_chr)) { 484 if (g_getfattr) { 485 sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, 486 bkpinfo->tmpdir, current_afioball_number); 487 } 488 if (g_getfacl) { 489 sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, 490 bkpinfo->tmpdir, current_afioball_number); 491 } 492 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) { 493 log_it("Reading EXAT files from tape"); 494 res = read_EXAT_files_from_tape(&size, fname, &ctrl_chr, 495 curr_xattr_list_fname, 496 curr_acl_list_fname); 497 } 498 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) { 499 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); 500 } 501 mr_asprintf(tmp, "Verifying fileset #%ld", current_afioball_number); 502 update_progress_form(tmp); 503 mr_free(tmp); 504 505 res = verify_an_afioball_from_stream(fname, size); 506 if (res) { 507 log_to_screen("Afioball %ld differs from live filesystem", current_afioball_number); 508 } 509 retval += res; 510 current_afioball_number++; 511 g_current_progress++; 512 res = read_header_block_from_stream(&size, fname, &ctrl_chr); 513 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) { 514 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr); 515 } 516 } 517 log_msg(1, "All done with afioballs"); 518 close_progress_form(); 519 paranoid_free(fname); 520 paranoid_free(curr_xattr_list_fname); 521 paranoid_free(curr_acl_list_fname); 522 return (retval); 523 } 524 525 /** 526 * Verify all biggiefiles on the opened CD/tape stream. 527 * @param bkpinfo The backup information structure. Fields used: 528 * - @c bkpinfo->restore_path 529 * - @c bkpinfo->tmpdir 530 * 531 * @return 0 for success (even if there are differences); nonzero for a tape error. 532 */ 533 int verify_biggiefiles_from_stream() 534 { 535 536 /*@ int ************************************************************ */ 537 int retval = 0; 538 int res = 0; 539 int ctrl_chr = 0; 540 541 /*@ long *********************************************************** */ 542 long noof_biggiefiles = 0; 543 long current_biggiefile_number = 0; 544 545 /*@ buffers ******************************************************** */ 546 char *orig_fname; 547 char *logical_fname = NULL; 548 char *comment = NULL; 549 char *curr_xattr_list_fname = NULL; 550 char *curr_acl_list_fname = NULL; 551 /*@ pointers ******************************************************* */ 552 char *p; 553 554 /*@ long long size ************************************************* */ 555 long long size = 0; 556 557 assert(bkpinfo != NULL); 558 malloc_string(orig_fname); 559 malloc_string(curr_xattr_list_fname); 560 malloc_string(curr_acl_list_fname); 561 562 if (g_getfattr) { 563 sprintf(curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ, 564 bkpinfo->tmpdir); 565 } 566 if (g_getfacl) { 567 sprintf(curr_acl_list_fname, ACL_BIGGLST_FNAME_RAW_SZ, 568 bkpinfo->tmpdir); 569 } 570 mr_asprintf(comment, "Verifying all bigfiles."); 571 log_to_screen(comment); 572 res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr); 573 if (ctrl_chr != BLK_START_BIGGIEFILES) { 574 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) { 575 log_it("Grabbing the EXAT biggiefiles"); 576 res = read_EXAT_files_from_tape(&size, orig_fname, 577 &ctrl_chr, curr_xattr_list_fname, 578 curr_acl_list_fname); 579 } 580 } 581 if (ctrl_chr != BLK_START_BIGGIEFILES) { 582 wrong_marker(BLK_START_BIGGIEFILES, ctrl_chr); 583 } 584 noof_biggiefiles = (long) size; 585 log_msg(1, "noof_biggiefiles = %ld", noof_biggiefiles); 586 open_progress_form("Verifying big files", comment, 587 "Please wait. This may take some time.", "", 588 noof_biggiefiles); 589 mr_free(comment); 590 591 for (res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr); 592 ctrl_chr != BLK_STOP_BIGGIEFILES; 593 res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr)) 594 { 595 if (ctrl_chr != BLK_START_A_NORMBIGGIE 596 && ctrl_chr != BLK_START_A_PIHBIGGIE) { 597 wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr); 598 } 599 p = strrchr(orig_fname, '/'); 600 if (!p) { 601 p = orig_fname; 602 } else { 603 p++; 604 } 605 mr_asprintf(comment, "Verifying bigfile #%ld (%ld K)", current_biggiefile_number, (long) size >> 10); 606 update_progress_form(comment); 607 mr_free(comment); 608 609 if (bkpinfo->restore_path != NULL) { 610 mr_asprintf(logical_fname, "%s/%s", bkpinfo->restore_path, orig_fname); 611 res = verify_a_biggiefile_from_stream(logical_fname, size); 612 mr_free(logical_fname); 613 retval += res; 614 } else { 615 log_it("Unable to verify bigfile as restore_path is NULL"); 616 } 617 618 current_biggiefile_number++; 619 g_current_progress++; 620 } 621 close_progress_form(); 622 paranoid_free(orig_fname); 623 paranoid_free(curr_xattr_list_fname); 624 paranoid_free(curr_acl_list_fname); 625 return (retval); 124 626 } 125 627 … … 391 893 392 894 393 394 395 396 /**397 * Verify one afioball from the CD.398 * You should be changed to the root directory (/) for this to work.399 * @param bkpinfo The backup information structure. Fields used:400 * - @c bkpinfo->use_lzo401 * - @c bkpinfo->tmpdir402 * - @c bkpinfo->zip_exe403 * - @c bkpinfo->zip_suffix404 * @param tarball_fname The filename of the afioball to verify.405 * @return 0, always.406 */407 int verify_a_tarball(char *tarball_fname)408 {409 /*@ buffers ********************************************************* */410 char *command = NULL;411 char *outlog = NULL;412 char *tmp = NULL;413 414 /*@ pointers ******************************************************* */415 FILE *pin;416 417 /*@ long *********************************************************** */418 long diffs = 0;419 420 assert(bkpinfo != NULL);421 assert_string_is_neither_NULL_nor_zerolength(tarball_fname);422 423 log_it("Verifying fileset '%s'", tarball_fname);424 mr_asprintf(outlog, "%s/afio.log", bkpinfo->tmpdir);425 /* if programmer forgot to say which compression thingy to use then find out */426 if (strstr(tarball_fname, ".lzo") && strcmp(bkpinfo->zip_suffix, "lzo")) {427 log_msg(2, "OK, I'm going to start using lzop.");428 mr_free(bkpinfo->zip_exe);429 mr_free(bkpinfo->zip_suffix);430 mr_asprintf(bkpinfo->zip_exe, "%s", "lzop");431 mr_asprintf(bkpinfo->zip_suffix, "%s", "lzo");432 bkpinfo->use_lzo = TRUE;433 bkpinfo->use_gzip = FALSE;434 bkpinfo->use_lzma = FALSE;435 }436 if (strstr(tarball_fname, ".gz") && strcmp(bkpinfo->zip_suffix, "gz")) {437 log_msg(2, "OK, I'm going to start using gzip.");438 mr_free(bkpinfo->zip_exe);439 mr_free(bkpinfo->zip_suffix);440 mr_asprintf(bkpinfo->zip_exe, "%s", "gzip");441 mr_asprintf(bkpinfo->zip_suffix, "%s", "gz");442 bkpinfo->use_lzo = FALSE;443 bkpinfo->use_gzip = TRUE;444 bkpinfo->use_lzma = FALSE;445 }446 if (strstr(tarball_fname, ".bz2") && strcmp(bkpinfo->zip_suffix, "bz2")) {447 log_msg(2, "OK, I'm going to start using bzip2.");448 mr_free(bkpinfo->zip_exe);449 mr_free(bkpinfo->zip_suffix);450 mr_asprintf(bkpinfo->zip_exe, "%s", "bzip2");451 mr_asprintf(bkpinfo->zip_suffix, "%s", "bz2");452 bkpinfo->use_lzo = FALSE;453 bkpinfo->use_gzip = FALSE;454 bkpinfo->use_lzma = FALSE;455 }456 if (strstr(tarball_fname, ".xz") && strcmp(bkpinfo->zip_suffix, "xz")) {457 log_msg(2, "OK, I'm going to start using lzma.");458 mr_free(bkpinfo->zip_exe);459 mr_free(bkpinfo->zip_suffix);460 mr_asprintf(bkpinfo->zip_exe, "%s", "xz");461 mr_asprintf(bkpinfo->zip_suffix, "%s", "xz");462 bkpinfo->use_lzo = FALSE;463 bkpinfo->use_gzip = FALSE;464 bkpinfo->use_lzma = TRUE;465 }466 // As suffix is used even when no compression make it non-NULL467 if (bkpinfo->zip_suffix == NULL) {468 mr_asprintf(bkpinfo->zip_suffix, "%s", "");469 }470 unlink(outlog);471 if (strstr(tarball_fname, ".star")) {472 bkpinfo->use_star = TRUE;473 if (strstr(tarball_fname, ".bz2"))474 mr_asprintf(command, "star -sparse -diff diffopts=mode,size,data file=%s %s >> %s 2>> %s", tarball_fname, (strstr(tarball_fname, ".bz2")) ? "-bz" : " ", outlog, outlog);475 } else {476 bkpinfo->use_star = FALSE;477 /* Here we suppose that there is always a compression program called */478 if (bkpinfo->zip_exe) {479 mr_asprintf(command, "afio -r -P %s -Z %s >> %s 2>> %s", bkpinfo->zip_exe, tarball_fname, outlog, outlog);480 } else {481 mr_asprintf(command, "afio -r -Z %s >> %s 2>> %s", tarball_fname, outlog, outlog);482 }483 }484 log_msg(6, "command=%s", command);485 paranoid_system(command);486 mr_free(command);487 488 if (length_of_file(outlog) < 10) {489 mr_asprintf(command, "cat %s >> %s", outlog, MONDO_LOGFILE);490 } else {491 mr_asprintf(command, "cut -d: -f%d %s | sort -u", (bkpinfo->use_star) ? 1 : 2, outlog);492 pin = popen(command, "r");493 if (pin) {494 for (mr_getline(tmp, pin); !feof(pin); mr_getline(tmp, pin)) {495 if (bkpinfo->use_star) {496 if (!strstr(tmp, "diffopts=")) {497 while (strlen(tmp) > 0 && tmp[strlen(tmp) - 1] < 32) {498 tmp[strlen(tmp) - 1] = '\0';499 }500 if (strchr(tmp, '/')) {501 if (!diffs) {502 log_msg(0, "'%s' - differences found", tarball_fname);503 }504 log_msg(0, "star: /%s", strip_afio_output_line(tmp));505 diffs++;506 }507 }508 } else {509 if (!diffs) {510 log_msg(0, "'%s' - differences found", tarball_fname);511 }512 log_msg(0, "afio: /%s", strip_afio_output_line(tmp));513 diffs++;514 }515 mr_free(tmp);516 }517 mr_free(tmp);518 paranoid_pclose(pin);519 } else {520 log_OS_error(command);521 }522 }523 mr_free(command);524 mr_free(outlog);525 return (0);526 }527 528 529 530 531 532 533 /**534 * Verify one afioball from the CD.535 * Checks for existence (calls fatal_error() if it does not exist) and536 * then calls verify_an_afioball().537 * @param bkpinfo The backup information structure. Passed to verify_an_afioball().538 * @param tarball_fname The filename of the afioball to verify.539 * @return The return value of verify_an_afioball().540 * @see verify_an_afioball541 */542 int543 verify_an_afioball_from_CD(char *tarball_fname)544 {545 546 /*@ int ************************************************************* */547 int res = 0;548 549 assert_string_is_neither_NULL_nor_zerolength(tarball_fname);550 551 log_msg(1, "Verifying %s", tarball_fname);552 if (!does_file_exist(tarball_fname)) {553 fatal_error("Cannot verify nonexistent afioball");554 }555 res = verify_a_tarball(tarball_fname);556 return (res);557 }558 559 560 /**561 * Verify one afioball from the opened tape/CD stream.562 * Copies the file from tape to tmpdir and then calls verify_an_afioball().563 * @param bkpinfo The backup information structure. Passed to verify_an_afioball().564 * @param orig_fname The original filename of the afioball to verify.565 * @param size The size of the afioball to verify.566 * @return The return value of verify_an_afioball().567 * @see verify_an_afioball568 */569 int570 verify_an_afioball_from_stream(char *orig_fname, long long size)571 {572 573 /*@ int ************************************************************** */574 int retval = 0;575 int res = 0;576 577 /*@ buffers ********************************************************** */578 char *tmp = NULL;579 char *tarball_fname = NULL;580 581 /*@ pointers ********************************************************* */582 char *p;583 584 assert(bkpinfo != NULL);585 assert_string_is_neither_NULL_nor_zerolength(orig_fname);586 587 p = strrchr(orig_fname, '/');588 if (!p) {589 p = orig_fname;590 } else {591 p++;592 }593 mr_asprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);594 paranoid_system(tmp);595 mr_free(tmp);596 597 mr_asprintf(tarball_fname, "%s/tmpfs/temporary-%s", bkpinfo->tmpdir, p);598 read_file_from_stream_to_file(tarball_fname, size);599 res = verify_a_tarball(tarball_fname);600 if (res) {601 log_msg(0, "Afioball '%s' no longer matches your live filesystem", p);602 retval++;603 }604 unlink(tarball_fname);605 mr_free(tarball_fname);606 return (retval);607 }608 609 610 /**611 * Verify one biggiefile form the opened tape/CD stream.612 * @param bkpinfo The backup information structure. @c bkpinfo->tmpdir is the only field used.613 * @param biggie_fname The filename of the biggiefile to verify.614 * @param size The size in bytes of said biggiefile.615 * @return 0 for success (even if the file doesn't match); nonzero for a tape error.616 */617 int618 verify_a_biggiefile_from_stream(char *biggie_fname, long long size)619 {620 621 /*@ int ************************************************************* */622 int retval = 0;623 int res = 0;624 int current_slice_number = 0;625 int ctrl_chr = '\0';626 627 /*@ char ************************************************************ */628 char *test_file = NULL;629 char *biggie_cksum = NULL;630 char *orig_cksum = NULL;631 char *tmp = NULL;632 char *slice_fnam = NULL;633 634 /*@ pointers ******************************************************** */635 char *p;636 637 /*@ long long ******************************************************* */638 long long slice_siz;639 640 malloc_string(slice_fnam);641 assert(bkpinfo != NULL);642 assert_string_is_neither_NULL_nor_zerolength(biggie_fname);643 644 p = strrchr(biggie_fname, '/');645 if (!p) {646 p = biggie_fname;647 } else {648 p++;649 }650 mr_asprintf(test_file, "%s/temporary-%s", bkpinfo->tmpdir, p);651 for (res =652 read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr);653 ctrl_chr != BLK_STOP_A_BIGGIE;654 res =655 read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr)) {656 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {657 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);658 }659 res = read_file_from_stream_to_file(test_file, slice_siz);660 unlink(test_file);661 res =662 read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr);663 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {664 log_msg(2, "test_file = %s", test_file);665 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);666 }667 current_slice_number++;668 retval += res;669 }670 mr_asprintf(biggie_cksum, "%s", slice_fnam);671 if (biggie_cksum[0] != '\0') {672 mr_asprintf(orig_cksum, "%s", calc_checksum_of_file(biggie_fname));673 if (strcmp(biggie_cksum, orig_cksum)) {674 log_msg(2, "orig cksum=%s; curr cksum=%s", biggie_cksum, orig_cksum);675 log_to_screen("%s has changed on live filesystem", biggie_fname);676 677 mr_asprintf(tmp, "echo \"%s\" >> %s/biggies.changed", biggie_fname, bkpinfo->tmpdir);678 paranoid_system(tmp);679 mr_free(tmp);680 }681 mr_free(orig_cksum);682 }683 mr_free(biggie_cksum);684 mr_free(test_file);685 paranoid_free(slice_fnam);686 return (retval);687 }688 689 690 /**691 * Verify all afioballs from the opened tape/CD stream.692 * @param bkpinfo The backup information structure. Fields used:693 * - @c bkpinfo->tmpdir694 *695 * @return 0 for success (even if there are differences); nonzero for a tape error.696 */697 int verify_afioballs_from_stream()698 {699 /*@ int ********************************************************** */700 int retval = 0;701 int res = 0;702 long current_afioball_number = 0;703 int ctrl_chr = 0;704 int total_afioballs = 0;705 706 /*@ buffers ***************************************************** */707 char *tmp = NULL;708 char *fname;709 char *curr_xattr_list_fname;710 char *curr_acl_list_fname;711 712 /*@ long long *************************************************** */713 long long size = 0;714 715 assert(bkpinfo != NULL);716 malloc_string(fname);717 malloc_string(curr_xattr_list_fname);718 malloc_string(curr_acl_list_fname);719 720 if (g_getfattr) {721 sprintf(curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ,722 bkpinfo->tmpdir);723 }724 if (g_getfacl) {725 sprintf(curr_acl_list_fname, ACL_BIGGLST_FNAME_RAW_SZ,726 bkpinfo->tmpdir);727 }728 log_to_screen("Verifying regular archives on tape");729 total_afioballs = get_last_filelist_number() + 1;730 open_progress_form("Verifying filesystem",731 "I am verifying archives against your live filesystem now.",732 "Please wait. This may take a couple of hours.", "",733 total_afioballs);734 res = read_header_block_from_stream(&size, fname, &ctrl_chr);735 if (ctrl_chr != BLK_START_AFIOBALLS) {736 log_it("YOU SHOULD NOT GET HERE");737 log_it("Grabbing the EXAT files");738 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {739 res = read_EXAT_files_from_tape(&size, fname, &ctrl_chr,740 curr_xattr_list_fname,741 curr_acl_list_fname);742 }743 }744 if (ctrl_chr != BLK_START_AFIOBALLS) {745 wrong_marker(BLK_START_AFIOBALLS, ctrl_chr);746 }747 748 for (res = read_header_block_from_stream(&size, fname, &ctrl_chr);749 ctrl_chr != BLK_STOP_AFIOBALLS;750 res = read_header_block_from_stream(&size, fname, &ctrl_chr)) {751 if (g_getfattr) {752 sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,753 bkpinfo->tmpdir, current_afioball_number);754 }755 if (g_getfacl) {756 sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,757 bkpinfo->tmpdir, current_afioball_number);758 }759 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {760 log_it("Reading EXAT files from tape");761 res = read_EXAT_files_from_tape(&size, fname, &ctrl_chr,762 curr_xattr_list_fname,763 curr_acl_list_fname);764 }765 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {766 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);767 }768 mr_asprintf(tmp, "Verifying fileset #%ld", current_afioball_number);769 update_progress_form(tmp);770 mr_free(tmp);771 772 res = verify_an_afioball_from_stream(fname, size);773 if (res) {774 log_to_screen("Afioball %ld differs from live filesystem", current_afioball_number);775 }776 retval += res;777 current_afioball_number++;778 g_current_progress++;779 res = read_header_block_from_stream(&size, fname, &ctrl_chr);780 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {781 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);782 }783 }784 log_msg(1, "All done with afioballs");785 close_progress_form();786 paranoid_free(fname);787 paranoid_free(curr_xattr_list_fname);788 paranoid_free(curr_acl_list_fname);789 return (retval);790 }791 792 /**793 * Verify all biggiefiles on the opened CD/tape stream.794 * @param bkpinfo The backup information structure. Fields used:795 * - @c bkpinfo->restore_path796 * - @c bkpinfo->tmpdir797 *798 * @return 0 for success (even if there are differences); nonzero for a tape error.799 */800 int verify_biggiefiles_from_stream()801 {802 803 /*@ int ************************************************************ */804 int retval = 0;805 int res = 0;806 int ctrl_chr = 0;807 808 /*@ long *********************************************************** */809 long noof_biggiefiles = 0;810 long current_biggiefile_number = 0;811 812 /*@ buffers ******************************************************** */813 char *orig_fname;814 char *logical_fname = NULL;815 char *comment = NULL;816 char *curr_xattr_list_fname = NULL;817 char *curr_acl_list_fname = NULL;818 /*@ pointers ******************************************************* */819 char *p;820 821 /*@ long long size ************************************************* */822 long long size = 0;823 824 assert(bkpinfo != NULL);825 malloc_string(orig_fname);826 malloc_string(curr_xattr_list_fname);827 malloc_string(curr_acl_list_fname);828 829 if (g_getfattr) {830 sprintf(curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ,831 bkpinfo->tmpdir);832 }833 if (g_getfacl) {834 sprintf(curr_acl_list_fname, ACL_BIGGLST_FNAME_RAW_SZ,835 bkpinfo->tmpdir);836 }837 mr_asprintf(comment, "Verifying all bigfiles.");838 log_to_screen(comment);839 res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr);840 if (ctrl_chr != BLK_START_BIGGIEFILES) {841 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {842 log_it("Grabbing the EXAT biggiefiles");843 res = read_EXAT_files_from_tape(&size, orig_fname,844 &ctrl_chr, curr_xattr_list_fname,845 curr_acl_list_fname);846 }847 }848 if (ctrl_chr != BLK_START_BIGGIEFILES) {849 wrong_marker(BLK_START_BIGGIEFILES, ctrl_chr);850 }851 noof_biggiefiles = (long) size;852 log_msg(1, "noof_biggiefiles = %ld", noof_biggiefiles);853 open_progress_form("Verifying big files", comment,854 "Please wait. This may take some time.", "",855 noof_biggiefiles);856 mr_free(comment);857 858 for (res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr);859 ctrl_chr != BLK_STOP_BIGGIEFILES;860 res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr))861 {862 if (ctrl_chr != BLK_START_A_NORMBIGGIE863 && ctrl_chr != BLK_START_A_PIHBIGGIE) {864 wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr);865 }866 p = strrchr(orig_fname, '/');867 if (!p) {868 p = orig_fname;869 } else {870 p++;871 }872 mr_asprintf(comment, "Verifying bigfile #%ld (%ld K)", current_biggiefile_number, (long) size >> 10);873 update_progress_form(comment);874 mr_free(comment);875 876 if (bkpinfo->restore_path != NULL) {877 mr_asprintf(logical_fname, "%s/%s", bkpinfo->restore_path, orig_fname);878 res = verify_a_biggiefile_from_stream(logical_fname, size);879 mr_free(logical_fname);880 retval += res;881 } else {882 log_it("Unable to verify bigfile as restore_path is NULL");883 }884 885 current_biggiefile_number++;886 g_current_progress++;887 }888 close_progress_form();889 paranoid_free(orig_fname);890 paranoid_free(curr_xattr_list_fname);891 paranoid_free(curr_acl_list_fname);892 return (retval);893 }894 895 895 /* @} - end of LLverifyGroup */ 896 896
Note:
See TracChangeset
for help on using the changeset viewer.