Changeset 2296 in MondoRescue for branches/2.2.10/mondo/src/mondorestore/mondo-rstr-compare.c
- Timestamp:
- Jul 23, 2009, 2:53:30 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.10/mondo/src/mondorestore/mondo-rstr-compare.c
r2291 r2296 47 47 char *bigfile_fname_ptr; 48 48 char *tmp_ptr = NULL; 49 char *command_ptr ;49 char *command_ptr = NULL; 50 50 51 51 char *checksum, *original_cksum, *bigfile_fname, *tmp, *command; … … 65 65 malloc_string(original_cksum_ptr); 66 66 malloc_string(bigfile_fname_ptr); 67 malloc_string(command_ptr);68 67 69 68 /********************************************************************* … … 74 73 memset(original_cksum_ptr, '\0', sizeof(original_cksum)); 75 74 memset(bigfile_fname_ptr, '\0', sizeof(bigfile_fname)); 76 memset(command_ptr, '\0', sizeof(command));77 75 /** end **/ 78 76 … … 113 111 if (!strncmp(bigfile_fname_ptr, "/dev/", 5)) { 114 112 strcpy(original_cksum_ptr, "IGNORE"); 115 } else {116 sprintf(command_ptr,117 "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors",118 MNT_RESTORING, bigfile_fname_ptr); 119 }113 log_msg(2, "IGNORING %s as begining with /dev", bigfile_fname_ptr); 114 return (1); 115 } 116 117 mr_asprintf(&command_ptr, "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors", MNT_RESTORING, bigfile_fname_ptr); 120 118 log_msg(2, command_ptr); 119 i = system(command_ptr); 120 mr_free(command_ptr); 121 121 122 mr_asprintf(&tmp_ptr, "cat /tmp/errors >> %s 2> /dev/null", MONDO_LOGFILE); 122 123 paranoid_system(tmp_ptr); 123 124 paranoid_free(tmp_ptr); 124 125 125 if ( system(command_ptr)) {126 if (i) { 126 127 log_OS_error("Warning - command failed"); 127 128 original_cksum[0] = '\0'; … … 169 170 paranoid_free(checksum_ptr); 170 171 paranoid_free(checksum); 171 paranoid_free(command_ptr);172 172 paranoid_free(command); 173 173 paranoid_free(tmp); … … 190 190 int res; 191 191 long noof_biggiefiles, bigfileno = 0; 192 char tmp[MAX_STR_LEN];192 char *tmp = NULL; 193 193 194 194 log_msg(1, "Comparing biggiefiles"); … … 211 211 noof_biggiefiles); 212 212 for (bigfileno = 0; bigfileno < noof_biggiefiles; bigfileno++) { 213 sprintf(tmp, "Comparing big file #%ld", bigfileno + 1);213 mr_asprintf(&tmp, "Comparing big file #%ld", bigfileno + 1); 214 214 log_msg(1, tmp); 215 215 update_progress_form(tmp); 216 mr_free(tmp); 217 216 218 res = compare_a_biggiefile(bigfileno); 217 219 retval += res; … … 250 252 251 253 /*** needs malloc *********/ 252 char *command , *tmp, *filelist_name, *logfile,253 *compressor_exe;254 char *command = NULL; 255 char *tmp = NULL; 254 256 char *archiver_exe = NULL; 255 256 malloc_string(command); 257 malloc_string(tmp); 258 malloc_string(filelist_name); 259 malloc_string(logfile); 260 malloc_string(compressor_exe); 257 char *filelist_name = NULL; 258 char *logfile = NULL; 259 char *compressor_exe = NULL; 261 260 262 261 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE; 263 262 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 264 sprintf(logfile, "/tmp/afio.log.%d", current_tarball_number); 265 sprintf(filelist_name, MNT_CDROM "/archives/filelist.%d", 266 current_tarball_number); 267 263 mr_asprintf(&filelist_name, MNT_CDROM "/archives/filelist.%d", current_tarball_number); 268 264 noof_lines = count_lines_in_file(filelist_name); 265 mr_free(filelist_name); 269 266 270 267 if (strstr(tarball_fname, ".bz2")) { 271 strcpy(compressor_exe, "bzip2");268 mr_asprintf(&compressor_exe, "bzip2"); 272 269 } else if (strstr(tarball_fname, ".gz")) { 273 strcpy(compressor_exe, "gzip");270 mr_asprintf(&compressor_exe, "gzip"); 274 271 } else if (strstr(tarball_fname, ".lzo")) { 275 strcpy(compressor_exe, "lzop"); 276 } else { 277 compressor_exe[0] = '\0'; 272 mr_asprintf(&compressor_exe, "lzop"); 278 273 } 279 274 … … 284 279 } 285 280 286 if (compressor_exe[0]) { 287 strcpy(tmp, compressor_exe); 288 if (!find_home_of_exe(tmp)) { 281 if (compressor_exe) { 282 if (!find_home_of_exe(compressor_exe)) { 283 mr_free(compressor_exe); 284 mr_free(archiver_exe); 289 285 fatal_error("(compare_a_tarball) Compression program missing"); 290 286 } 291 if (use_star) // star 292 { 287 if (use_star) { 293 288 if (!strcmp(compressor_exe, "bzip2")) { 294 289 mr_strcat(archiver_exe, " -bz"); 295 290 } else { 296 fatal_error 297 ("(compare_a_tarball) Please use only bzip2 with star"); 291 mr_free(compressor_exe); 292 mr_free(archiver_exe); 293 fatal_error("(compare_a_tarball) Please use only bzip2 with star"); 298 294 } 299 } else // afio 300 { 301 sprintf(compressor_exe, "-P %s -Z", tmp); 302 } 303 } 304 // star -diff H=star -bz file=.... 295 } else { 296 // afio 297 mr_free(compressor_exe); 298 mr_asprintf(&tmp, "%s", compressor_exe); 299 mr_asprintf(&compressor_exe, "-P %s -Z", tmp); 300 mr_free(tmp); 301 } 302 } 305 303 306 304 #ifdef __FreeBSD__ … … 309 307 #define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE 310 308 #endif 311 if (use_star) // doesn't use compressor_exe 312 { 313 sprintf(command, 314 "%s -diff H=star file=%s >> %s 2>> %s", 315 archiver_exe, tarball_fname, logfile, logfile); 316 } else { 317 sprintf(command, 318 "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s", 319 archiver_exe, 320 TAPE_BLOCK_SIZE, 321 BUFSIZE, compressor_exe, tarball_fname, logfile, logfile); 322 } 309 mr_asprintf(&logfile, "/tmp/afio.log.%d", current_tarball_number); 310 311 if (use_star) { 312 // doesn't use compressor_exe 313 mr_asprintf(&command, "%s -diff H=star file=%s >> %s 2>> %s", archiver_exe, tarball_fname, logfile, logfile); 314 } else { 315 mr_asprintf(&command, "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s", archiver_exe, TAPE_BLOCK_SIZE, BUFSIZE, compressor_exe, tarball_fname, logfile, logfile); 316 } 317 mr_free(compressor_exe); 323 318 paranoid_free(archiver_exe); 324 319 … … 329 324 if (res) { 330 325 log_OS_error(command); 331 sprintf(tmp, "Warning - afio returned error = %d", res); 332 log_msg(2, tmp); 333 } 326 log_msg(2, "Warning - afio returned error = %d", res); 327 } 328 mr_free(command); 329 334 330 if (length_of_file(logfile) > 5) { 335 sprintf(command, 336 "sed s/': \\\"'/\\|/ %s | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort -u | grep -vE \"^dev/.*\" >> "MONDO_CACHE"/changed.txt", 337 logfile); 331 mr_asprintf(&command, "sed s/': \\\"'/\\|/ %s | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort -u | grep -vE \"^dev/.*\" >> "MONDO_CACHE"/changed.txt", logfile); 338 332 system(command); 333 mr_free(command); 334 339 335 archiver_errors = count_lines_in_file(logfile); 340 336 } else { 341 337 archiver_errors = 0; 342 338 } 343 sprintf(tmp, "%ld difference%c in fileset #%d ",344 archiver_errors, (archiver_errors != 1) ? 's' : ' ',345 current_tarball_number);346 339 if (archiver_errors) { 347 sprintf(tmp, 348 "Differences found while processing fileset #%d ", 349 current_tarball_number); 350 log_msg(1, tmp); 340 log_msg(1, "%ld difference%c in fileset #%d ", archiver_errors, (archiver_errors != 1) ? 's' : ' ', current_tarball_number); 351 341 } 352 342 unlink(logfile); 353 paranoid_free(command); 354 paranoid_free(tmp); 355 paranoid_free(filelist_name); 356 paranoid_free(logfile); 357 paranoid_free(compressor_exe); 343 mr_free(logfile); 344 358 345 return (retval); 359 346 } … … 377 364 /** needs malloc **********/ 378 365 379 char *tarball_fname, *progress_str, *tmp; 366 char *tarball_fname = NULL; 367 char *progress_str = NULL; 368 char *tmp = NULL; 380 369 char *mds = NULL; 381 370 long max_val; 382 371 383 malloc_string(tarball_fname);384 malloc_string(progress_str);385 malloc_string(tmp);386 372 387 373 assert(bkpinfo != NULL); 388 374 mvaddstr_and_log_it(g_currentY, 0, "Comparing archives"); 375 376 malloc_string(tmp); 389 377 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp); 390 391 378 max_val = atol(tmp); 379 paranoid_free(tmp); 380 392 381 mds = media_descriptor_string(bkpinfo->backup_media_type); 393 sprintf(progress_str, "Comparing with %s #%d ", mds, g_current_media_number);382 mr_asprintf(&progress_str, "Comparing with %s #%d ", mds, g_current_media_number); 394 383 395 384 open_progress_form("Comparing files", … … 403 392 insist_on_this_cd_number(g_current_media_number); 404 393 update_progress_form(progress_str); 405 sprintf(tarball_fname, 406 MNT_CDROM "/archives/%d.afio.bz2", current_tarball_number); 394 mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%d.afio.bz2", current_tarball_number); 407 395 408 396 if (!does_file_exist(tarball_fname)) { 409 sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.lzo",410 397 mr_free(tarball_fname); 398 mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%d.afio.lzo", current_tarball_number); 411 399 } 412 400 if (!does_file_exist(tarball_fname)) { 413 sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.gz",414 401 mr_free(tarball_fname); 402 mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%d.afio.gz", current_tarball_number); 415 403 } 416 404 if (!does_file_exist(tarball_fname)) { 417 sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.",418 405 mr_free(tarball_fname); 406 mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%d.afio.", current_tarball_number); 419 407 } 420 408 if (!does_file_exist(tarball_fname)) { 421 sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.bz2",422 409 mr_free(tarball_fname); 410 mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%d.star.bz2", current_tarball_number); 423 411 } 424 412 if (!does_file_exist(tarball_fname)) { 425 sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.",426 413 mr_free(tarball_fname); 414 mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%d.star.", current_tarball_number); 427 415 } 428 416 if (!does_file_exist(tarball_fname)) { … … 432 420 == 0) { 433 421 log_msg(2, "OK, I think I'm done with tarballs..."); 422 mr_free(tarball_fname); 434 423 break; 435 424 } 436 425 log_msg(2, "OK, I think it's time for another CD..."); 437 426 g_current_media_number++; 438 sprintf(progress_str, "Comparing with %s #%d ", mds, g_current_media_number); 427 428 mr_free(progress_str); 429 mr_asprintf(&progress_str, "Comparing with %s #%d ", mds, g_current_media_number); 439 430 log_to_screen(progress_str); 440 431 } else { … … 444 435 current_tarball_number++; 445 436 } 446 } 437 mr_free(tarball_fname); 438 } 439 mr_free(progress_str); 447 440 mr_free(mds); 448 441 … … 453 446 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 454 447 } 455 paranoid_free(tarball_fname);456 paranoid_free(progress_str);457 paranoid_free(tmp);458 448 return (retval); 459 449 } … … 478 468 { 479 469 /** needs malloc *********/ 480 char *tmp, *cwd, *new, *command; 470 char *tmp = NULL; 471 char *cwd, *new; 472 char *command = NULL; 481 473 int resA = 0; 482 474 int resB = 0; 483 475 long noof_changed_files; 484 476 485 malloc_string(tmp);486 477 malloc_string(cwd); 487 478 malloc_string(new); 488 malloc_string(command);489 479 490 480 assert(bkpinfo != NULL); … … 501 491 noof_changed_files = count_lines_in_file(MONDO_CACHE"/changed.txt"); 502 492 if (noof_changed_files) { 503 sprintf(tmp, "%ld files do not match the backup ", 504 noof_changed_files); 505 // mvaddstr_and_log_it( g_currentY++, 0, tmp ); 493 mr_asprintf(&tmp, "%ld files do not match the backup ", noof_changed_files); 506 494 log_to_screen(tmp); 507 sprintf(command, "cat "MONDO_CACHE"/changed.txt >> %s", MONDO_LOGFILE); 495 mr_free(tmp); 496 497 mr_asprintf(&command, "cat "MONDO_CACHE"/changed.txt >> %s", MONDO_LOGFILE); 508 498 paranoid_system(command); 509 } else { 510 sprintf(tmp, "All files match the backup "); 499 mr_free(command); 500 } else { 501 mr_asprintf(&tmp, "All files match the backup "); 511 502 mvaddstr_and_log_it(g_currentY++, 0, tmp); 512 503 log_to_screen(tmp); 513 }514 515 paranoid_free(tmp); 504 mr_free(tmp); 505 } 506 516 507 paranoid_free(cwd); 517 508 paranoid_free(new); 518 paranoid_free(command);519 509 520 510 return (resA + resB); … … 544 534 int res = 0; 545 535 long q; 546 char *tmp ;536 char *tmp = NULL; 547 537 char *new; 548 538 char *cwd; 549 539 550 malloc_string(tmp);551 540 malloc_string(new); 552 541 malloc_string(cwd); … … 575 564 if (g_text_mode) { 576 565 save_mountlist_to_disk(mountlist, g_mountlist_fname); 577 sprintf(tmp, "%s %s", find_my_editor(), g_mountlist_fname);566 mr_asprintf(&tmp, "%s %s", find_my_editor(), g_mountlist_fname); 578 567 res = system(tmp); 568 mr_free(tmp); 569 579 570 load_mountlist(mountlist, g_mountlist_fname); 580 571 } else { … … 622 613 } else { 623 614 q = count_lines_in_file(MONDO_CACHE"/changed.files"); 624 sprintf(tmp, "%ld significant difference%s found.", q, 625 (q != 1) ? "s" : ""); 615 mr_asprintf(&tmp, "%ld significant difference%s found.", q, (q != 1) ? "s" : ""); 626 616 mvaddstr_and_log_it(g_currentY++, 0, tmp); 627 617 log_to_screen(tmp); 628 629 strcpy(tmp, 630 618 mr_free(tmp); 619 620 mr_asprintf(&tmp, "Type 'less /tmp/changed.files' for a list of non-matching files"); 631 621 mvaddstr_and_log_it(g_currentY++, 0, tmp); 632 622 log_to_screen(tmp); 623 mr_free(tmp); 633 624 634 625 log_msg(2, "calling popup_changelist_from_file()"); … … 647 638 648 639 kill_petris(); 649 paranoid_free(tmp);650 640 paranoid_free(new); 651 641 paranoid_free(cwd); … … 670 660 671 661 /** needs malloc **/ 672 char *dir, *command; 662 char *dir; 663 char *command = NULL; 673 664 674 665 assert(bkpinfo != NULL); 675 666 malloc_string(dir); 676 malloc_string(command);677 667 getcwd(dir, MAX_STR_LEN); 678 668 chdir(bkpinfo->restore_path); 679 669 680 sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", 681 bkpinfo->restore_path); 670 mr_asprintf(&command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", bkpinfo->restore_path); 682 671 run_program_and_log_output(command, FALSE); 672 mr_free(command); 673 683 674 mvaddstr_and_log_it(g_currentY, 684 675 0, "Verifying archives against filesystem"); … … 704 695 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 705 696 paranoid_free(dir); 706 paranoid_free(command);707 697 return (res); 708 698 } … … 727 717 { 728 718 int res; 729 char *dir, *command; 719 char *dir; 720 char *command = NULL; 730 721 731 722 assert(bkpinfo != NULL); 732 723 malloc_string(dir); 733 malloc_string(command);734 724 735 725 getcwd(dir, MAX_STR_LEN); 736 726 chdir(bkpinfo->restore_path); 737 sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", 738 bkpinfo->restore_path); 727 mr_asprintf(&command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", bkpinfo->restore_path); 739 728 run_program_and_log_output(command, FALSE); 729 mr_free(command); 730 740 731 mvaddstr_and_log_it(g_currentY, 741 732 0, "Verifying archives against filesystem"); … … 748 739 } 749 740 paranoid_free(dir); 750 paranoid_free(command);751 741 return (res); 752 742 }
Note:
See TracChangeset
for help on using the changeset viewer.