Changeset 3193 in MondoRescue for branches/3.2/mondo/src/mondorestore/mondo-rstr-compare.c
- Timestamp:
- Sep 29, 2013, 9:31:34 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mondo/src/mondorestore/mondo-rstr-compare.c
r3185 r3193 43 43 44 44 /** needs malloc *******/ 45 char *checksum_ptr; 46 char *original_cksum_ptr; 47 char *bigfile_fname_ptr; 48 char *tmp_ptr = NULL; 49 char *command_ptr; 50 51 char *checksum, *original_cksum, *bigfile_fname, *tmp, *command; 45 char *checksum = NULL; 46 char *original_cksum = NULL; 47 char *bigfile_fname = NULL; 48 char *tmp = NULL; 49 char *command = NULL; 52 50 53 51 char *p; … … 56 54 57 55 struct s_filename_and_lstat_info biggiestruct; 58 59 malloc_string(checksum);60 malloc_string(original_cksum);61 malloc_string(bigfile_fname);62 malloc_string(tmp);63 malloc_string(command);64 malloc_string(checksum_ptr);65 malloc_string(original_cksum_ptr);66 malloc_string(bigfile_fname_ptr);67 malloc_string(command_ptr);68 56 69 57 /********************************************************************* … … 71 59 *********************************************************************/ 72 60 assert(bkpinfo != NULL); 73 memset(checksum_ptr, '\0', sizeof(checksum));74 memset(original_cksum_ptr, '\0', sizeof(original_cksum));75 memset(bigfile_fname_ptr, '\0', sizeof(bigfile_fname));76 memset(command_ptr, '\0', sizeof(command));77 61 /** end **/ 78 62 … … 81 65 insist_on_this_cd_number((++g_current_media_number)); 82 66 } else { 83 mr_asprintf(tmp_ptr, "No CD's left. No biggiefiles left. No prob, Bob."); 84 log_msg(2, tmp_ptr); 85 paranoid_free(tmp_ptr); 67 log_msg(2, "No CD's left. No biggiefiles left. No prob, Bob."); 86 68 return (0); 87 69 } 88 70 } 89 71 if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) { 90 mr_asprintf(tmp_ptr, "Cannot open bigfile %ld (%s)'s info file", bigfileno + 1, bigfile_fname_ptr); 91 log_to_screen(tmp_ptr); 92 paranoid_free(tmp_ptr); 72 log_to_screen("Cannot open bigfile %ld (NULL)'s info file", bigfileno + 1); 93 73 return (1); 94 74 } … … 98 78 paranoid_fclose(fin); 99 79 100 strcpy(checksum_ptr, biggiestruct.checksum); 101 strcpy(bigfile_fname_ptr, biggiestruct.filename); 102 80 81 mr_asprintf(bigfile_fname, "%s", biggiestruct.filename); 103 82 log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename); 83 mr_asprintf(checksum, "%s", biggiestruct.checksum); 104 84 log_msg(2, "biggiestruct.checksum = %s", biggiestruct.checksum); 105 85 106 86 if (!g_text_mode) { 107 mr_asprintf(tmp _ptr, "Comparing %s", bigfile_fname_ptr);108 newtDrawRootText(0, 22, tmp _ptr);109 paranoid_free(tmp_ptr);87 mr_asprintf(tmp, "Comparing %s", bigfile_fname); 88 newtDrawRootText(0, 22, tmp); 89 mr_free(tmp); 110 90 newtRefresh(); 111 91 } 112 if (!checksum[0]) { 113 log_msg(2, "Warning - %s has no checksum", bigfile_fname_ptr); 114 } 115 if (!strncmp(bigfile_fname_ptr, "/dev/", 5)) { 116 strcpy(original_cksum_ptr, "IGNORE"); 117 } else { 118 sprintf(command_ptr, 119 "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors", 120 MNT_RESTORING, bigfile_fname_ptr); 121 } 122 log_msg(2, command_ptr); 123 mr_asprintf(tmp_ptr, "cat /tmp/errors >> %s 2> /dev/null", MONDO_LOGFILE); 124 paranoid_system(tmp_ptr); 125 paranoid_free(tmp_ptr); 126 127 if (system(command_ptr)) { 92 if (checksum == NULL]) { 93 log_msg(2, "Warning - %s has no checksum", bigfile_fname); 94 } 95 if (!strncmp(bigfile_fname, "/dev/", 5)) { 96 log_msg(2, "IGNORING %s as begining with /dev", bigfile_fname); 97 mr_free(checksum); 98 mr_free(bigfile_fname); 99 return (1); 100 } 101 102 mr_asprintf(command, "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors", MNT_RESTORING, bigfile_fname); 103 log_msg(2, command); 104 i = system(command); 105 mr_free(command); 106 107 mr_asprintf(tmp, "cat /tmp/errors >> %s 2> /dev/null", MONDO_LOGFILE); 108 paranoid_system(tmp); 109 mr_free(tmp); 110 111 if (i) { 128 112 log_OS_error("Warning - command failed"); 129 original_cksum[0] = '\0'; 113 mr_free(checksum); 114 mr_free(bigfile_fname); 130 115 return (1); 131 116 } else { 132 117 if (!(fin = fopen("/tmp/md5sum.txt", "r"))) { 133 log_msg(2, 134 "Unable to open /tmp/md5sum.txt; can't get live checksum");135 original_cksum[0] = '\0';118 log_msg(2, "Unable to open /tmp/md5sum.txt; can't get live checksum"); 119 mr_free(checksum); 120 mr_free(bigfile_fname); 136 121 return (1); 137 122 } else { 138 if (fgets(original_cksum_ptr, MAX_STR_LEN - 1, fin)) { 139 // FIXME 140 } 123 mr_getline(original_cksum, fin); 141 124 paranoid_fclose(fin); 142 for (i = strlen(original_cksum _ptr);125 for (i = strlen(original_cksum); 143 126 i > 0 && original_cksum[i - 1] < 32; i--); 144 127 original_cksum[i] = '\0'; 145 p = (char *) strchr(original_cksum_ptr, ' ');128 p = strchr(original_cksum, ' '); 146 129 if (p) { 147 130 *p = '\0'; … … 149 132 } 150 133 } 151 mr_asprintf(tmp _ptr, "bigfile #%ld ('%s') ", bigfileno + 1, bigfile_fname_ptr);152 if ( !strcmp(checksum_ptr, original_cksum_ptr) != 0) {153 mr_strcat(tmp _ptr, " ... OK");154 } else { 155 mr_strcat(tmp _ptr, "... changed");134 mr_asprintf(tmp, "bigfile #%ld ('%s') ", bigfileno + 1, bigfile_fname); 135 if ((original_cksum != NULL) && (strcmp(checksum, original_cksum) == 0)) { 136 mr_strcat(tmp, " ... OK"); 137 } else { 138 mr_strcat(tmp, "... changed"); 156 139 retval++; 157 140 } 158 log_msg(1, tmp_ptr); 159 paranoid_free(tmp_ptr); 141 mr_free(checksum); 142 mr_free(original_cksum); 143 144 log_msg(1, tmp); 145 mr_free(tmp); 160 146 161 147 if (retval) { … … 163 149 fatal_error("Cannot openout changed.txt"); 164 150 } 165 fprintf(fout, "%s\n", bigfile_fname _ptr);151 fprintf(fout, "%s\n", bigfile_fname); 166 152 paranoid_fclose(fout); 167 153 } 168 169 paranoid_free(original_cksum_ptr); 170 paranoid_free(original_cksum); 171 paranoid_free(bigfile_fname_ptr); 172 paranoid_free(bigfile_fname); 173 paranoid_free(checksum_ptr); 174 paranoid_free(checksum); 175 paranoid_free(command_ptr); 176 paranoid_free(command); 177 paranoid_free(tmp); 154 mr_free(bigfile_fname); 178 155 179 156 return (retval); … … 194 171 int res; 195 172 long noof_biggiefiles, bigfileno = 0; 196 char tmp[MAX_STR_LEN];173 char *tmp = NULL; 197 174 198 175 log_msg(1, "Comparing biggiefiles"); … … 215 192 noof_biggiefiles); 216 193 for (bigfileno = 0; bigfileno < noof_biggiefiles; bigfileno++) { 217 sprintf(tmp, "Comparing big file #%ld", bigfileno + 1);194 mr_asprintf(tmp, "Comparing big file #%ld", bigfileno + 1); 218 195 log_msg(1, tmp); 219 196 update_progress_form(tmp); 197 mr_free(tmp); 198 220 199 res = compare_a_biggiefile(bigfileno); 221 200 retval += res; … … 253 232 254 233 /*** needs malloc *********/ 255 char *command , *tmp, *filelist_name, *logfile,256 *compressor_exe;234 char *command = NULL; 235 char *tmp = NULL; 257 236 char *archiver_exe = NULL; 258 259 malloc_string(command); 260 malloc_string(tmp); 261 malloc_string(filelist_name); 262 malloc_string(logfile); 263 malloc_string(compressor_exe); 237 char *tmp1 = NULL; 238 char *logfile = NULL; 239 char *compressor_exe = NULL; 264 240 265 241 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE; 266 242 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 267 sprintf(logfile, "/tmp/afio.log.%d", current_tarball_number); 268 sprintf(filelist_name, MNT_CDROM "/archives/filelist.%d", 269 current_tarball_number); 243 mr_asprintf(filelist_name, MNT_CDROM "/archives/filelist.%d", current_tarball_number); 270 244 271 245 if (strstr(tarball_fname, ".bz2")) { 272 strcpy(compressor_exe, "bzip2"); 246 mr_asprintf(compressor_exe, "bzip2"); 247 } else if (strstr(tarball_fname, ".lzma")) { 248 mr_asprintf(compressor_exe, "lzma"); 273 249 } else if (strstr(tarball_fname, ".gz")) { 274 strcpy(compressor_exe, "gzip");250 mr_asprintf(compressor_exe, "gzip"); 275 251 } else if (strstr(tarball_fname, ".lzo")) { 276 strcpy(compressor_exe, "lzop"); 277 } else { 278 compressor_exe[0] = '\0'; 252 mr_asprintf(compressor_exe, "lzop"); 279 253 } 280 254 … … 285 259 } 286 260 287 if (compressor_exe [0]) {288 strcpy(tmp, compressor_exe);261 if (compressor_exe) { 262 mr_asprintf(tmp, "%s", compressor_exe); 289 263 if (!find_home_of_exe(tmp)) { 264 mr_free(tmp); 265 mr_free(compressor_exe); 266 mr_free(archiver_exe); 290 267 fatal_error("(compare_a_tarball) Compression program missing"); 291 268 } 292 if (use_star) // star 293 { 269 mr_free(tmp); 270 271 if (use_star) { 294 272 if (!strcmp(compressor_exe, "bzip2")) { 295 273 mr_strcat(archiver_exe, " -bz"); 296 274 } else { 297 fatal_error 298 ("(compare_a_tarball) Please use only bzip2 with star"); 275 mr_free(compressor_exe); 276 mr_free(archiver_exe); 277 fatal_error("(compare_a_tarball) Please use only bzip2 with star"); 299 278 } 300 } else // afio 301 { 302 sprintf(compressor_exe, "-P %s -Z", tmp); 303 } 304 } 305 // star -diff H=star -bz file=.... 279 } else { 280 // afio 281 mr_asprintf(tmp, "%s", compressor_exe); 282 mr_free(compressor_exe); 283 mr_asprintf(compressor_exe, "-P %s -Z", tmp); 284 mr_free(tmp); 285 } 286 } 306 287 307 288 #ifdef __FreeBSD__ … … 310 291 #define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE 311 292 #endif 312 if (use_star) // doesn't use compressor_exe 313 { 314 sprintf(command, 315 "%s -sparse -diff H=exustar file=%s >> %s 2>> %s", 316 archiver_exe, tarball_fname, logfile, logfile); 317 } else { 318 sprintf(command, 319 "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s", 320 archiver_exe, 321 TAPE_BLOCK_SIZE, 322 BUFSIZE, compressor_exe, tarball_fname, logfile, logfile); 323 } 324 paranoid_free(archiver_exe); 293 mr_asprintf(logfile, "/tmp/afio.log.%d", current_tarball_number); 294 295 if (use_star) { 296 // doesn't use compressor_exe 297 mr_asprintf(command, "%s -sparse -diff H=exustar file=%s >> %s 2>> %s", archiver_exe, tarball_fname, logfile, logfile); 298 } else { 299 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); 300 } 301 mr_free(compressor_exe); 302 mr_free(archiver_exe); 325 303 326 304 #undef BUFSIZE … … 330 308 if (res) { 331 309 log_OS_error(command); 332 sprintf(tmp, "Warning - afio returned error = %d", res); 333 log_msg(2, tmp); 334 } 310 log_msg(2, "Warning - afio returned error = %d", res); 311 } 312 mr_free(command); 313 335 314 if (length_of_file(logfile) > 5) { 336 sprintf(command, 337 "sed s/': \\\"'/\\|/ %s | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort -u | grep -vE \"^dev/.*\" >> "MONDO_CACHE"/changed.txt", 338 logfile); 315 mr_asprintf(command, "sed s/': \\\"'/\\|/ %s | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort -u | grep -vE \"^dev/.*\" >> "MONDO_CACHE"/changed.txt", logfile); 339 316 paranoid_system(command); 317 mr_free(command); 318 340 319 archiver_errors = count_lines_in_file(logfile); 341 320 } else { 342 321 archiver_errors = 0; 343 322 } 344 sprintf(tmp, "%ld difference%c in fileset #%d ",345 archiver_errors, (archiver_errors != 1) ? 's' : ' ',346 current_tarball_number);347 323 if (archiver_errors) { 348 sprintf(tmp, 349 "Differences found while processing fileset #%d ", 350 current_tarball_number); 351 log_msg(1, tmp); 324 log_msg(1, "%ld difference%c in fileset #%d ", archiver_errors, (archiver_errors != 1) ? 's' : ' ', current_tarball_number); 352 325 } 353 326 unlink(logfile); 354 paranoid_free(command); 355 paranoid_free(tmp); 356 paranoid_free(filelist_name); 357 paranoid_free(logfile); 358 paranoid_free(compressor_exe); 327 mr_free(logfile); 328 359 329 return (retval); 360 330 } … … 377 347 /** needs malloc **********/ 378 348 379 char *tarball_fname, *progress_str, *tmp; 349 char *tarball_fname = NULL; 350 char *progress_str = NULL; 351 char *tmp = NULL; 380 352 char *mds = NULL; 381 353 long max_val; 382 354 383 malloc_string(tarball_fname);384 malloc_string(progress_str);385 355 malloc_string(tmp); 386 387 356 assert(bkpinfo != NULL); 388 357 mvaddstr_and_log_it(g_currentY, 0, "Comparing archives"); 389 358 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp); 390 391 359 max_val = atol(tmp); 360 paranoid_free(tmp); 361 392 362 mds = media_descriptor_string(bkpinfo->backup_media_type); 393 sprintf(progress_str, "Comparing with %s #%d ", mds, g_current_media_number);363 mr_asprintf(progress_str, "Comparing with %s #%d ", mds, g_current_media_number); 394 364 395 365 open_progress_form("Comparing files", … … 403 373 insist_on_this_cd_number(g_current_media_number); 404 374 update_progress_form(progress_str); 405 sprintf(tarball_fname, 406 MNT_CDROM "/archives/%d.afio.bz2", current_tarball_number); 375 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.bz2", current_tarball_number); 407 376 408 377 if (!does_file_exist(tarball_fname)) { 409 sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.lzo",410 378 mr_free(tarball_fname); 379 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.lzo", current_tarball_number); 411 380 } 412 381 if (!does_file_exist(tarball_fname)) { 413 sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.gz",414 382 mr_free(tarball_fname); 383 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.lzma", current_tarball_number); 415 384 } 416 385 if (!does_file_exist(tarball_fname)) { 417 sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.",418 386 mr_free(tarball_fname); 387 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.gz", current_tarball_number); 419 388 } 420 389 if (!does_file_exist(tarball_fname)) { 421 sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.bz2",422 390 mr_free(tarball_fname); 391 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.", current_tarball_number); 423 392 } 424 393 if (!does_file_exist(tarball_fname)) { 425 sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.", 426 current_tarball_number); 394 mr_free(tarball_fname); 395 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.star.bz2", current_tarball_number); 396 } 397 if (!does_file_exist(tarball_fname)) { 398 mr_free(tarball_fname); 399 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.star.", current_tarball_number); 427 400 } 428 401 if (!does_file_exist(tarball_fname)) { … … 432 405 == 0) { 433 406 log_msg(2, "OK, I think I'm done with tarballs..."); 407 mr_free(tarball_fname); 434 408 break; 435 409 } 436 410 log_msg(2, "OK, I think it's time for another CD..."); 437 411 g_current_media_number++; 438 sprintf(progress_str, "Comparing with %s #%d ", mds, g_current_media_number); 412 413 mr_free(progress_str); 414 mr_asprintf(progress_str, "Comparing with %s #%d ", mds, g_current_media_number); 439 415 log_to_screen(progress_str); 440 416 } else { … … 444 420 current_tarball_number++; 445 421 } 446 } 422 mr_free(tarball_fname); 423 } 424 mr_free(progress_str); 447 425 mr_free(mds); 448 426 … … 453 431 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 454 432 } 455 paranoid_free(tarball_fname);456 paranoid_free(progress_str);457 paranoid_free(tmp);458 433 return (retval); 459 434 } … … 478 453 { 479 454 /** needs malloc *********/ 480 char *tmp, *cwd, *new, *command; 455 char *tmp = NULL; 456 char *cwd, *new; 457 char *command = NULL; 481 458 int resA = 0; 482 459 int resB = 0; … … 486 463 malloc_string(cwd); 487 464 malloc_string(new); 488 malloc_string(command);489 465 490 466 assert(bkpinfo != NULL); … … 509 485 noof_changed_files = count_lines_in_file(MONDO_CACHE"/changed.txt"); 510 486 if (noof_changed_files) { 511 sprintf(tmp, "%ld files do not match the backup ", 512 noof_changed_files); 513 // mvaddstr_and_log_it( g_currentY++, 0, tmp ); 514 log_to_screen(tmp); 515 sprintf(command, "cat "MONDO_CACHE"/changed.txt >> %s", MONDO_LOGFILE); 487 log_to_screen("%ld files do not match the backup ", noof_changed_files); 488 489 mr_asprintf(command, "cat "MONDO_CACHE"/changed.txt >> %s", MONDO_LOGFILE); 516 490 paranoid_system(command); 517 } else { 518 sprintf(tmp, "All files match the backup "); 491 mr_free(command); 492 } else { 493 mr_asprintf(tmp, "All files match the backup "); 519 494 mvaddstr_and_log_it(g_currentY++, 0, tmp); 520 495 log_to_screen(tmp); 521 }522 523 paranoid_free(tmp); 496 mr_free(tmp); 497 } 498 524 499 paranoid_free(cwd); 525 500 paranoid_free(new); 526 paranoid_free(command);527 501 528 502 return (resA + resB); … … 552 526 int res = 0; 553 527 long q; 554 char *tmp ;528 char *tmp = NULL; 555 529 char *new; 556 530 char *cwd; 557 531 558 malloc_string(tmp);559 532 malloc_string(new); 560 533 malloc_string(cwd); … … 630 603 } else { 631 604 q = count_lines_in_file(MONDO_CACHE"/changed.files"); 632 sprintf(tmp, "%ld significant difference%s found.", q, 633 (q != 1) ? "s" : ""); 605 mr_asprintf(tmp, "%ld significant difference%s found.", q, (q != 1) ? "s" : ""); 634 606 mvaddstr_and_log_it(g_currentY++, 0, tmp); 635 607 log_to_screen(tmp); 636 637 strcpy(tmp, 638 608 mr_free(tmp); 609 610 mr_asprintf(tmp, "Type 'less /tmp/changed.files' for a list of non-matching files"); 639 611 mvaddstr_and_log_it(g_currentY++, 0, tmp); 640 612 log_to_screen(tmp); 613 mr_free(tmp); 641 614 642 615 log_msg(2, "calling popup_changelist_from_file()"); … … 663 636 664 637 kill_petris(); 665 paranoid_free(tmp);666 638 paranoid_free(new); 667 639 paranoid_free(cwd); … … 686 658 687 659 /** needs malloc **/ 688 char *dir, *command; 660 char *dir; 661 char *command = NULL; 689 662 690 663 assert(bkpinfo != NULL); 691 664 malloc_string(dir); 692 malloc_string(command);693 665 if (getcwd(dir, MAX_STR_LEN)) { 694 666 // FIXME … … 698 670 } 699 671 700 sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", 701 bkpinfo->restore_path); 672 mr_asprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", bkpinfo->restore_path); 702 673 run_program_and_log_output(command, FALSE); 703 m vaddstr_and_log_it(g_currentY,704 674 mr_free(command); 675 mvaddstr_and_log_it(g_currentY, 0, "Verifying archives against filesystem"); 705 676 706 677 if (bkpinfo->disaster_recovery … … 726 697 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 727 698 paranoid_free(dir); 728 paranoid_free(command);729 699 return (res); 730 700 } … … 749 719 { 750 720 int res; 751 char *dir, *command; 721 char *dir; 722 char *command = NULL; 752 723 753 724 assert(bkpinfo != NULL); 754 725 malloc_string(dir); 755 malloc_string(command);756 726 757 727 if (getcwd(dir, MAX_STR_LEN)) { … … 761 731 // FIXME 762 732 } 763 sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", 764 bkpinfo->restore_path); 733 mr_asprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", bkpinfo->restore_path); 765 734 run_program_and_log_output(command, FALSE); 766 mvaddstr_and_log_it(g_currentY, 767 0, "Verifying archives against filesystem"); 735 mr_free(command); 736 737 mvaddstr_and_log_it(g_currentY, 0, "Verifying archives against filesystem"); 768 738 res = verify_tape_backups(); 769 739 if (chdir(dir)) { … … 776 746 } 777 747 paranoid_free(dir); 778 paranoid_free(command);779 748 return (res); 780 749 }
Note:
See TracChangeset
for help on using the changeset viewer.