Changeset 59 in MondoRescue for trunk/mondo/mondo/mondorestore/mondo-rstr-compare.c
- Timestamp:
- Oct 11, 2005, 1:34:31 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/mondo/mondorestore/mondo-rstr-compare.c
r30 r59 5 5 copyright : (C) 2000 by Hugo Rabson 6 6 email : Hugo Rabson <hugorabson@msn.com> 7 cvsid : $Id : mondo-rstr-compare.c,v 1.1 2004/06/10 15:29:13 hugo Exp$7 cvsid : $Id$ 8 8 ***************************************************************************/ 9 9 … … 65 65 #include "mondo-rstr-tools-EXT.h" 66 66 67 //static char cvsid[] = "$Id : mondo-rstr-compare.c,v 1.1 2004/06/10 15:29:13 hugo Exp$";68 69 void popup_changelist_from_file(char *);67 //static char cvsid[] = "$Id$"; 68 69 void popup_changelist_from_file(char *); 70 70 71 71 … … 80 80 * @note This function uses an MD5 checksum. 81 81 */ 82 int 83 compare_a_biggiefile(struct s_bkpinfo *bkpinfo, long bigfileno) 82 int compare_a_biggiefile(struct s_bkpinfo *bkpinfo, long bigfileno) 84 83 { 85 84 86 87 85 FILE *fin; 86 FILE *fout; 88 87 89 88 /** needs malloc *******/ 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 89 char *checksum_ptr; 90 char *original_cksum_ptr; 91 char *bigfile_fname_ptr; 92 char *tmp_ptr; 93 char *command_ptr; 94 95 char *checksum, *original_cksum, *bigfile_fname, *tmp, *command; 96 97 char *p; 98 int i; 99 int retval = 0; 100 101 struct s_filename_and_lstat_info biggiestruct; 102 103 malloc_string(checksum); 104 malloc_string(original_cksum); 105 malloc_string(bigfile_fname); 106 malloc_string(tmp); 107 malloc_string(command); 108 malloc_string(checksum_ptr); 109 malloc_string(original_cksum_ptr); 110 malloc_string(bigfile_fname_ptr); 111 malloc_string(command_ptr); 112 malloc_string(tmp_ptr); 113 115 114 /********************************************************************* 116 115 * allocate memory clear test sab 16 feb 2003 * 117 116 *********************************************************************/ 118 assert(bkpinfo!=NULL);119 memset(checksum_ptr, '\0', sizeof(checksum));120 memset (original_cksum_ptr, '\0', sizeof(original_cksum));121 memset(bigfile_fname_ptr, '\0', sizeof(bigfile_fname));122 memset(tmp_ptr, '\0', sizeof(tmp));123 memset ( command_ptr, '\0', sizeof( command ));117 assert(bkpinfo != NULL); 118 memset(checksum_ptr, '\0', sizeof(checksum)); 119 memset(original_cksum_ptr, '\0', sizeof(original_cksum)); 120 memset(bigfile_fname_ptr, '\0', sizeof(bigfile_fname)); 121 memset(tmp_ptr, '\0', sizeof(tmp)); 122 memset(command_ptr, '\0', sizeof(command)); 124 123 /** end **/ 125 124 126 if ( !does_file_exist( slice_fname(bigfileno, 0, ARCHIVES_PATH, "" ) ) ) 127 { 128 if ( does_file_exist( MNT_CDROM"/archives/NOT-THE-LAST" ) ) 129 { 130 insist_on_this_cd_number(bkpinfo, ( ++g_current_media_number ) ); 131 } 132 else 133 { 134 sprintf(tmp_ptr, "No CD's left. No biggiefiles left. No prob, Bob." ); 135 log_msg(2, tmp_ptr ); 136 return( 0 ); 137 } 138 } 139 if ( !( fin = fopen(slice_fname( bigfileno, 0, ARCHIVES_PATH, "" ), "r" ) ) ) 140 { 141 sprintf( tmp_ptr, 142 "Cannot open bigfile %ld (%s)'s info file", 143 bigfileno + 1, bigfile_fname_ptr); 144 log_to_screen( tmp_ptr ); 145 return( 1 ); 146 } 147 fread( ( void* )&biggiestruct, 1, sizeof( biggiestruct ), fin); 148 paranoid_fclose( fin ); 149 150 strcpy( checksum_ptr, biggiestruct.checksum ); 151 strcpy( bigfile_fname_ptr, biggiestruct.filename ); 152 153 log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename ); 154 log_msg(2, "biggiestruct.checksum = %s", biggiestruct.checksum ); 155 156 sprintf( tmp_ptr, "Comparing %s", bigfile_fname_ptr); 157 158 if (!g_text_mode) 159 { 160 newtDrawRootText( 0, 22, tmp_ptr); 161 newtRefresh(); 162 } 163 if ( !checksum[0] ) { 164 log_msg(2, "Warning - %s has no checksum", bigfile_fname_ptr ); 165 } 166 if ( !strncmp( bigfile_fname_ptr, "/dev/", 5 ) ) 167 { 168 strcpy( original_cksum_ptr, "IGNORE" ); 169 } 170 else 171 { 172 sprintf( command_ptr, 173 "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors.txt", 174 MNT_RESTORING, bigfile_fname_ptr); 175 } 176 log_msg(2, command_ptr ); 177 paranoid_system( "cat /tmp/errors >> /tmp/mondo-restore.log 2> /dev/null" ); 178 if ( system( command_ptr ) ) 179 { 180 log_OS_error( "Warning - command failed" ); 181 original_cksum[0] = '\0'; 182 return( 1 ); 183 } 184 else 185 { 186 if ( !(fin = fopen( "/tmp/md5sum.txt", "r" ) ) ) 187 { 188 log_msg(2, "Unable to open /tmp/md5sum.txt; can't get live checksum" ); 189 original_cksum[0] = '\0'; 190 return( 1 ); 191 } 192 else 193 { 194 fgets( original_cksum_ptr, MAX_STR_LEN - 1, fin ); 195 paranoid_fclose( fin ); 196 for(i = strlen( original_cksum_ptr ); i > 0 && original_cksum[i-1] < 32; i-- ); 197 original_cksum[i] = '\0'; 198 p = ( char* ) strchr( original_cksum_ptr, ' ' ); 199 if ( p ) 200 { 201 *p = '\0'; 202 } 203 } 204 } 205 sprintf( tmp_ptr, "bigfile #%ld ('%s') ", bigfileno + 1, bigfile_fname_ptr); 206 if ( !strcmp(checksum_ptr, original_cksum_ptr ) != 0 ) 207 { 208 strcat( tmp_ptr," ... OK"); 209 } 210 else 211 { 212 strcat( tmp_ptr, "... changed" ); 213 retval++; 214 } 215 log_msg(1, tmp_ptr ); 216 if ( retval ) 217 { 218 if ( !( fout = fopen("/tmp/changed.txt", "a") ) ) 219 { 220 fatal_error( "Cannot openout changed.txt"); 221 } 222 fprintf( fout, "%s\n", bigfile_fname_ptr ); 223 paranoid_fclose( fout ); 224 } 225 226 paranoid_free (original_cksum_ptr); 227 paranoid_free (original_cksum); 228 paranoid_free (bigfile_fname_ptr); 229 paranoid_free (bigfile_fname); 230 paranoid_free (checksum_ptr); 231 paranoid_free (checksum); 232 paranoid_free (command_ptr); 233 paranoid_free (command); 234 paranoid_free (tmp_ptr); 235 paranoid_free (tmp); 236 237 return( retval ); 125 if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) { 126 if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) { 127 insist_on_this_cd_number(bkpinfo, (++g_current_media_number)); 128 } else { 129 sprintf(tmp_ptr, 130 "No CD's left. No biggiefiles left. No prob, Bob."); 131 log_msg(2, tmp_ptr); 132 return (0); 133 } 134 } 135 if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) { 136 sprintf(tmp_ptr, 137 "Cannot open bigfile %ld (%s)'s info file", 138 bigfileno + 1, bigfile_fname_ptr); 139 log_to_screen(tmp_ptr); 140 return (1); 141 } 142 fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin); 143 paranoid_fclose(fin); 144 145 strcpy(checksum_ptr, biggiestruct.checksum); 146 strcpy(bigfile_fname_ptr, biggiestruct.filename); 147 148 log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename); 149 log_msg(2, "biggiestruct.checksum = %s", biggiestruct.checksum); 150 151 sprintf(tmp_ptr, "Comparing %s", bigfile_fname_ptr); 152 153 if (!g_text_mode) { 154 newtDrawRootText(0, 22, tmp_ptr); 155 newtRefresh(); 156 } 157 if (!checksum[0]) { 158 log_msg(2, "Warning - %s has no checksum", bigfile_fname_ptr); 159 } 160 if (!strncmp(bigfile_fname_ptr, "/dev/", 5)) { 161 strcpy(original_cksum_ptr, "IGNORE"); 162 } else { 163 sprintf(command_ptr, 164 "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors.txt", 165 MNT_RESTORING, bigfile_fname_ptr); 166 } 167 log_msg(2, command_ptr); 168 paranoid_system 169 ("cat /tmp/errors >> /tmp/mondo-restore.log 2> /dev/null"); 170 if (system(command_ptr)) { 171 log_OS_error("Warning - command failed"); 172 original_cksum[0] = '\0'; 173 return (1); 174 } else { 175 if (!(fin = fopen("/tmp/md5sum.txt", "r"))) { 176 log_msg(2, 177 "Unable to open /tmp/md5sum.txt; can't get live checksum"); 178 original_cksum[0] = '\0'; 179 return (1); 180 } else { 181 fgets(original_cksum_ptr, MAX_STR_LEN - 1, fin); 182 paranoid_fclose(fin); 183 for (i = strlen(original_cksum_ptr); 184 i > 0 && original_cksum[i - 1] < 32; i--); 185 original_cksum[i] = '\0'; 186 p = (char *) strchr(original_cksum_ptr, ' '); 187 if (p) { 188 *p = '\0'; 189 } 190 } 191 } 192 sprintf(tmp_ptr, "bigfile #%ld ('%s') ", bigfileno + 1, 193 bigfile_fname_ptr); 194 if (!strcmp(checksum_ptr, original_cksum_ptr) != 0) { 195 strcat(tmp_ptr, " ... OK"); 196 } else { 197 strcat(tmp_ptr, "... changed"); 198 retval++; 199 } 200 log_msg(1, tmp_ptr); 201 if (retval) { 202 if (!(fout = fopen("/tmp/changed.txt", "a"))) { 203 fatal_error("Cannot openout changed.txt"); 204 } 205 fprintf(fout, "%s\n", bigfile_fname_ptr); 206 paranoid_fclose(fout); 207 } 208 209 paranoid_free(original_cksum_ptr); 210 paranoid_free(original_cksum); 211 paranoid_free(bigfile_fname_ptr); 212 paranoid_free(bigfile_fname); 213 paranoid_free(checksum_ptr); 214 paranoid_free(checksum); 215 paranoid_free(command_ptr); 216 paranoid_free(command); 217 paranoid_free(tmp_ptr); 218 paranoid_free(tmp); 219 220 return (retval); 238 221 } 239 222 … … 248 231 * @return 0 for success, nonzero for failure. 249 232 */ 250 int 251 compare_all_biggiefiles(struct s_bkpinfo*bkpinfo) 233 int compare_all_biggiefiles(struct s_bkpinfo *bkpinfo) 252 234 { 253 int retval = 0; 254 int res; 255 long noof_biggiefiles,bigfileno = 0; 256 char tmp[MAX_STR_LEN]; 257 258 assert(bkpinfo!=NULL); 259 log_msg(1, "Comparing biggiefiles" ); 260 261 if ( length_of_file(BIGGIELIST) < 6 ) 262 { 263 log_msg(1, "OK, really teeny-tiny biggielist; not comparing biggiefiles" ); 264 return( 0 ); 265 } 266 noof_biggiefiles = count_lines_in_file(BIGGIELIST); 267 if (noof_biggiefiles <= 0 ) 268 { 269 log_msg(1, "OK, no biggiefiles; not comparing biggiefiles"); 270 return( 0 ); 271 } 272 mvaddstr_and_log_it( g_currentY, 0, "Comparing large files "); 273 open_progress_form("Comparing large files", "I am now comparing the large files" , "against the filesystem. Please wait.", 274 "", 275 noof_biggiefiles ); 276 for( bigfileno = 0; bigfileno < noof_biggiefiles; bigfileno++ ) 277 { 278 sprintf( tmp, "Comparing big file #%ld", bigfileno + 1 ); 279 log_msg(1, tmp ); 280 update_progress_form( tmp ); 281 res = compare_a_biggiefile( bkpinfo, bigfileno ); 282 retval += res; 283 g_current_progress++; 284 } 285 close_progress_form(); 286 return( 0 ); 287 if ( retval ) 288 { 289 mvaddstr_and_log_it( g_currentY++, 74, "Errors." ); 290 } 291 else 292 { 293 mvaddstr_and_log_it( g_currentY++,74, "Done." ); 294 } 295 return( retval ); 235 int retval = 0; 236 int res; 237 long noof_biggiefiles, bigfileno = 0; 238 char tmp[MAX_STR_LEN]; 239 240 assert(bkpinfo != NULL); 241 log_msg(1, "Comparing biggiefiles"); 242 243 if (length_of_file(BIGGIELIST) < 6) { 244 log_msg(1, 245 "OK, really teeny-tiny biggielist; not comparing biggiefiles"); 246 return (0); 247 } 248 noof_biggiefiles = count_lines_in_file(BIGGIELIST); 249 if (noof_biggiefiles <= 0) { 250 log_msg(1, "OK, no biggiefiles; not comparing biggiefiles"); 251 return (0); 252 } 253 mvaddstr_and_log_it(g_currentY, 0, 254 "Comparing large files "); 255 open_progress_form("Comparing large files", 256 "I am now comparing the large files", 257 "against the filesystem. Please wait.", "", 258 noof_biggiefiles); 259 for (bigfileno = 0; bigfileno < noof_biggiefiles; bigfileno++) { 260 sprintf(tmp, "Comparing big file #%ld", bigfileno + 1); 261 log_msg(1, tmp); 262 update_progress_form(tmp); 263 res = compare_a_biggiefile(bkpinfo, bigfileno); 264 retval += res; 265 g_current_progress++; 266 } 267 close_progress_form(); 268 return (0); 269 if (retval) { 270 mvaddstr_and_log_it(g_currentY++, 74, "Errors."); 271 } else { 272 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 273 } 274 return (retval); 296 275 } 276 297 277 /************************************************************************** 298 278 *END_COMPARE_ALL_BIGGIEFILES * … … 308 288 * @return 0 for success, nonzero for failure. 309 289 */ 310 int 311 compare_a_tarball( char *tarball_fname, int current_tarball_number ) 290 int compare_a_tarball(char *tarball_fname, int current_tarball_number) 312 291 { 313 314 315 316 317 318 292 int retval = 0; 293 int res; 294 long noof_lines; 295 long archiver_errors; 296 bool use_star; 297 319 298 /*** needs malloc *********/ 320 char *command, *tmp, *filelist_name, *logfile, *archiver_exe, *compressor_exe; 321 322 malloc_string(command); 323 malloc_string(tmp);324 malloc_string(filelist_name);325 malloc_string(logfile);326 malloc_string(archiver_exe);327 malloc_string(compressor_exe);328 329 use_star = (strstr(tarball_fname, ".star"))?TRUE:FALSE; 330 assert_string_is_neither_NULL_nor_zerolength(tarball_fname);331 sprintf( logfile, "/tmp/afio.log.%d", current_tarball_number);332 sprintf( filelist_name, MNT_CDROM"/archives/filelist.%d", current_tarball_number);333 334 noof_lines = count_lines_in_file( filelist_name);335 336 if ( strstr( tarball_fname, ".bz2") ) 337 { 338 strcpy( compressor_exe, "bzip2"); 339 } 340 else if ( strstr (tarball_fname, ".lzo") ) 341 { 342 strcpy( compressor_exe, "lzop" ); 343 } 344 else 345 { 346 compressor_exe[0] = '\0'; 347 } 348 349 if (use_star) 350 { strcpy(archiver_exe, "star");}351 else 352 { strcpy(archiver_exe, "afio"); } 353 354 if (compressor_exe[0]) 355 { 356 strcpy(tmp, compressor_exe); 357 if (!find_home_of_exe(tmp)) 358 { fatal_error("(compare_a_tarball) Compression program missing"); } 359 if (use_star) // star 360 { 361 if (!strcmp(compressor_exe, "bzip2"))362 { strcat(archiver_exe, " -bz"); }363 else { fatal_error("(compare_a_tarball) Please use only bzip2 with star"); }364 }365 else// afio366 367 368 }369 299 char *command, *tmp, *filelist_name, *logfile, *archiver_exe, 300 *compressor_exe; 301 302 malloc_string(command); 303 malloc_string(tmp); 304 malloc_string(filelist_name); 305 malloc_string(logfile); 306 malloc_string(archiver_exe); 307 malloc_string(compressor_exe); 308 309 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE; 310 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 311 sprintf(logfile, "/tmp/afio.log.%d", current_tarball_number); 312 sprintf(filelist_name, MNT_CDROM "/archives/filelist.%d", 313 current_tarball_number); 314 315 noof_lines = count_lines_in_file(filelist_name); 316 317 if (strstr(tarball_fname, ".bz2")) { 318 strcpy(compressor_exe, "bzip2"); 319 } else if (strstr(tarball_fname, ".lzo")) { 320 strcpy(compressor_exe, "lzop"); 321 } else { 322 compressor_exe[0] = '\0'; 323 } 324 325 if (use_star) { 326 strcpy(archiver_exe, "star"); 327 } else { 328 strcpy(archiver_exe, "afio"); 329 } 330 331 if (compressor_exe[0]) { 332 strcpy(tmp, compressor_exe); 333 if (!find_home_of_exe(tmp)) { 334 fatal_error("(compare_a_tarball) Compression program missing"); 335 } 336 if (use_star) // star 337 { 338 if (!strcmp(compressor_exe, "bzip2")) { 339 strcat(archiver_exe, " -bz"); 340 } else { 341 fatal_error 342 ("(compare_a_tarball) Please use only bzip2 with star"); 343 } 344 } else // afio 345 { 346 sprintf(compressor_exe, "-P %s -Z", tmp); 347 } 348 } 370 349 // star -diff H=star -bz file=.... 371 350 … … 375 354 #define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE 376 355 #endif 377 if (use_star) // doesn't use compressor_exe 378 { 379 sprintf( command, 380 "%s -diff H=star file=%s >> %s 2>> %s", 381 archiver_exe, tarball_fname, logfile, logfile); 382 } 383 else 384 { 385 sprintf( command, 386 "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s", 387 archiver_exe, 388 TAPE_BLOCK_SIZE, 389 BUFSIZE, 390 compressor_exe, tarball_fname, 391 logfile, 392 logfile); 393 } 356 if (use_star) // doesn't use compressor_exe 357 { 358 sprintf(command, 359 "%s -diff H=star file=%s >> %s 2>> %s", 360 archiver_exe, tarball_fname, logfile, logfile); 361 } else { 362 sprintf(command, 363 "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s", 364 archiver_exe, 365 TAPE_BLOCK_SIZE, 366 BUFSIZE, compressor_exe, tarball_fname, logfile, logfile); 367 } 394 368 #undef BUFSIZE 395 369 396 res = system( command ); 397 retval += res; 398 if ( res ) 399 { 400 log_OS_error( command ); 401 sprintf( tmp, "Warning - afio returned error = %d", res ); 402 } 403 if (length_of_file(logfile)>5) 404 { 405 sprintf(command, 406 "cat %s | sed s/': \\\"'/\\|/ | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort | uniq | grep -vx \"dev/.*\" >> /tmp/changed.txt", 407 logfile); 408 system(command); 409 archiver_errors = count_lines_in_file( logfile ); 410 } 411 else 412 { 413 archiver_errors = 0; 414 } 415 sprintf(tmp, "%ld difference%c in fileset #%d ", 416 archiver_errors, (archiver_errors != 1) ? 's' : ' ', current_tarball_number); 417 if (archiver_errors) 418 { 419 sprintf(tmp, 420 "Differences found while processing fileset #%d ", 421 current_tarball_number); 422 log_msg(1, tmp ); 423 } 424 unlink( logfile ); 425 paranoid_free(command); 426 paranoid_free(tmp); 427 paranoid_free(filelist_name); 428 paranoid_free(logfile); 429 malloc_string(archiver_exe); 430 malloc_string(compressor_exe); 431 return( retval ); 370 res = system(command); 371 retval += res; 372 if (res) { 373 log_OS_error(command); 374 sprintf(tmp, "Warning - afio returned error = %d", res); 375 } 376 if (length_of_file(logfile) > 5) { 377 sprintf(command, 378 "cat %s | sed s/': \\\"'/\\|/ | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort | uniq | grep -vx \"dev/.*\" >> /tmp/changed.txt", 379 logfile); 380 system(command); 381 archiver_errors = count_lines_in_file(logfile); 382 } else { 383 archiver_errors = 0; 384 } 385 sprintf(tmp, "%ld difference%c in fileset #%d ", 386 archiver_errors, (archiver_errors != 1) ? 's' : ' ', 387 current_tarball_number); 388 if (archiver_errors) { 389 sprintf(tmp, 390 "Differences found while processing fileset #%d ", 391 current_tarball_number); 392 log_msg(1, tmp); 393 } 394 unlink(logfile); 395 paranoid_free(command); 396 paranoid_free(tmp); 397 paranoid_free(filelist_name); 398 paranoid_free(logfile); 399 malloc_string(archiver_exe); 400 malloc_string(compressor_exe); 401 return (retval); 432 402 } 403 433 404 /************************************************************************** 434 405 *END_COMPARE_A_TARBALL * … … 441 412 * @return 0 for success, nonzero for failure. 442 413 */ 443 int 444 compare_all_tarballs( struct s_bkpinfo *bkpinfo ) 414 int compare_all_tarballs(struct s_bkpinfo *bkpinfo) 445 415 { 446 447 448 416 int retval = 0; 417 int res; 418 int current_tarball_number = 0; 449 419 450 420 /** needs malloc **********/ 451 452 char *tarball_fname, *progress_str, *tmp; 453 long max_val; 454 455 malloc_string(tarball_fname); 456 malloc_string(progress_str); 457 malloc_string(tmp); 458 459 assert(bkpinfo!=NULL); 460 mvaddstr_and_log_it( g_currentY,0, "Comparing archives" ); 461 read_cfg_var( g_mondo_cfg_file, "last-filelist-number", tmp ); 462 463 max_val = atol( tmp ); 464 sprintf( progress_str, "Comparing with %s #%d ", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number ); 465 466 open_progress_form("Comparing files", 467 "Comparing tarballs against filesystem.", 468 "Please wait. This may take some time.", 469 progress_str, 470 max_val); 471 472 log_to_screen( progress_str ); 473 474 for( ;; ) 475 { 476 insist_on_this_cd_number( bkpinfo, g_current_media_number ); 477 update_progress_form( progress_str ); 478 sprintf( tarball_fname, 479 MNT_CDROM"/archives/%d.afio.bz2", 480 current_tarball_number); 481 482 if ( !does_file_exist( tarball_fname ) ) 483 { 484 sprintf( tarball_fname, MNT_CDROM"/archives/%d.afio.lzo", current_tarball_number ); 485 } 486 if (!does_file_exist ( tarball_fname ) ) 487 { 488 sprintf(tarball_fname, MNT_CDROM"/archives/%d.afio.", 489 current_tarball_number); 490 } 491 if (!does_file_exist ( tarball_fname ) ) 492 { 493 sprintf(tarball_fname, MNT_CDROM"/archives/%d.star.bz2", 494 current_tarball_number); 495 } 496 if (!does_file_exist ( tarball_fname ) ) 497 { 498 sprintf(tarball_fname, MNT_CDROM"/archives/%d.star.", 499 current_tarball_number); 500 } 501 if ( !does_file_exist( tarball_fname ) ) 502 { 503 if ( !does_file_exist( MNT_CDROM"/archives/NOT-THE-LAST" ) || 504 system( "find "MNT_CDROM"/archives/slice* > /dev/null 2> /dev/null" ) 505 == 0 ) 506 { 507 log_msg(2, "OK, I think I'm done with tarballs..." ); 508 break; 509 } 510 log_msg(2, "OK, I think it's time for another CD..." ); 511 g_current_media_number++; 512 sprintf( progress_str, "Comparing with %s #%d ", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number ); 513 log_to_screen( progress_str ); 514 } 515 else 516 { 517 res = 518 compare_a_tarball( tarball_fname, current_tarball_number ); 519 520 g_current_progress++; 521 current_tarball_number++; 522 } 523 } 524 close_progress_form(); 525 if ( retval ) 526 { 527 mvaddstr_and_log_it( g_currentY++,74, "Errors." ); 528 } 529 else 530 { 531 mvaddstr_and_log_it( g_currentY++, 532 74, 533 "Done."); 534 } 535 paranoid_free(tarball_fname); 536 paranoid_free(progress_str); 537 paranoid_free(tmp); 538 return(retval); 421 422 char *tarball_fname, *progress_str, *tmp; 423 long max_val; 424 425 malloc_string(tarball_fname); 426 malloc_string(progress_str); 427 malloc_string(tmp); 428 429 assert(bkpinfo != NULL); 430 mvaddstr_and_log_it(g_currentY, 0, "Comparing archives"); 431 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp); 432 433 max_val = atol(tmp); 434 sprintf(progress_str, "Comparing with %s #%d ", 435 media_descriptor_string(bkpinfo->backup_media_type), 436 g_current_media_number); 437 438 open_progress_form("Comparing files", 439 "Comparing tarballs against filesystem.", 440 "Please wait. This may take some time.", 441 progress_str, max_val); 442 443 log_to_screen(progress_str); 444 445 for (;;) { 446 insist_on_this_cd_number(bkpinfo, g_current_media_number); 447 update_progress_form(progress_str); 448 sprintf(tarball_fname, 449 MNT_CDROM "/archives/%d.afio.bz2", current_tarball_number); 450 451 if (!does_file_exist(tarball_fname)) { 452 sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.lzo", 453 current_tarball_number); 454 } 455 if (!does_file_exist(tarball_fname)) { 456 sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.", 457 current_tarball_number); 458 } 459 if (!does_file_exist(tarball_fname)) { 460 sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.bz2", 461 current_tarball_number); 462 } 463 if (!does_file_exist(tarball_fname)) { 464 sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.", 465 current_tarball_number); 466 } 467 if (!does_file_exist(tarball_fname)) { 468 if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST") || 469 system("find " MNT_CDROM 470 "/archives/slice* > /dev/null 2> /dev/null") 471 == 0) { 472 log_msg(2, "OK, I think I'm done with tarballs..."); 473 break; 474 } 475 log_msg(2, "OK, I think it's time for another CD..."); 476 g_current_media_number++; 477 sprintf(progress_str, "Comparing with %s #%d ", 478 media_descriptor_string(bkpinfo->backup_media_type), 479 g_current_media_number); 480 log_to_screen(progress_str); 481 } else { 482 res = compare_a_tarball(tarball_fname, current_tarball_number); 483 484 g_current_progress++; 485 current_tarball_number++; 486 } 487 } 488 close_progress_form(); 489 if (retval) { 490 mvaddstr_and_log_it(g_currentY++, 74, "Errors."); 491 } else { 492 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 493 } 494 paranoid_free(tarball_fname); 495 paranoid_free(progress_str); 496 paranoid_free(tmp); 497 return (retval); 539 498 } 499 540 500 /************************************************************************** 541 501 *END_COMPARE_ALL_TARBALLS * … … 554 514 * @return 0 for success, nonzero for failure. 555 515 */ 556 int 557 compare_to_CD( struct s_bkpinfo *bkpinfo ) 516 int compare_to_CD(struct s_bkpinfo *bkpinfo) 558 517 { 559 518 /** needs malloc *********/ 560 char *tmp, *cwd, *new, *command; 561 int resA = 0; 562 int resB = 0; 563 long noof_changed_files; 564 565 malloc_string(tmp); 566 malloc_string(cwd); 567 malloc_string(new); 568 malloc_string(command); 569 570 assert(bkpinfo!=NULL); 571 572 getcwd( cwd, MAX_STR_LEN - 1 ); 573 chdir( bkpinfo->restore_path ); 574 getcwd( new, MAX_STR_LEN - 1 ); 575 sprintf( tmp, "new path is %s", new ); 576 insist_on_this_cd_number( bkpinfo, g_current_media_number ); 577 unlink( "/tmp/changed.txt" ); 578 579 resA = compare_all_tarballs( bkpinfo ); 580 resB = compare_all_biggiefiles( bkpinfo ); 581 chdir( cwd ); 582 noof_changed_files = count_lines_in_file( "/tmp/changed.txt" ); 583 if ( noof_changed_files ) 584 { 585 sprintf( tmp, "%ld files do not match the backup ", 586 noof_changed_files ); 587 // mvaddstr_and_log_it( g_currentY++, 0, tmp ); 588 log_to_screen (tmp); 589 sprintf(command, "cat /tmp/changed.txt >> %s", MONDO_LOGFILE ); 590 paranoid_system( command ); 591 } 592 else 593 { 594 sprintf( tmp, "All files match the backup "); 595 mvaddstr_and_log_it( g_currentY++, 0, tmp ); 596 log_to_screen( tmp ); 597 } 598 599 paranoid_free(tmp); 600 paranoid_free(cwd); 601 paranoid_free(new); 602 paranoid_free(command); 603 604 return( resA + resB ); 519 char *tmp, *cwd, *new, *command; 520 int resA = 0; 521 int resB = 0; 522 long noof_changed_files; 523 524 malloc_string(tmp); 525 malloc_string(cwd); 526 malloc_string(new); 527 malloc_string(command); 528 529 assert(bkpinfo != NULL); 530 531 getcwd(cwd, MAX_STR_LEN - 1); 532 chdir(bkpinfo->restore_path); 533 getcwd(new, MAX_STR_LEN - 1); 534 sprintf(tmp, "new path is %s", new); 535 insist_on_this_cd_number(bkpinfo, g_current_media_number); 536 unlink("/tmp/changed.txt"); 537 538 resA = compare_all_tarballs(bkpinfo); 539 resB = compare_all_biggiefiles(bkpinfo); 540 chdir(cwd); 541 noof_changed_files = count_lines_in_file("/tmp/changed.txt"); 542 if (noof_changed_files) { 543 sprintf(tmp, "%ld files do not match the backup ", 544 noof_changed_files); 545 // mvaddstr_and_log_it( g_currentY++, 0, tmp ); 546 log_to_screen(tmp); 547 sprintf(command, "cat /tmp/changed.txt >> %s", MONDO_LOGFILE); 548 paranoid_system(command); 549 } else { 550 sprintf(tmp, "All files match the backup "); 551 mvaddstr_and_log_it(g_currentY++, 0, tmp); 552 log_to_screen(tmp); 553 } 554 555 paranoid_free(tmp); 556 paranoid_free(cwd); 557 paranoid_free(new); 558 paranoid_free(command); 559 560 return (resA + resB); 605 561 } 606 562 … … 622 578 */ 623 579 int 624 compare_mode( struct s_bkpinfo *bkpinfo,625 struct mountlist_itself *mountlist,626 580 compare_mode(struct s_bkpinfo *bkpinfo, 581 struct mountlist_itself *mountlist, 582 struct raidlist_itself *raidlist) 627 583 { 628 629 630 631 632 584 int retval = 0; 585 long q; 586 char *tmp; 587 588 malloc_string(tmp); 633 589 634 590 /************************************************************************** … … 636 592 * restore them from start of tape, if available * 637 593 **************************************************************************/ 638 assert(bkpinfo!=NULL); 639 assert(mountlist!=NULL); 640 assert(raidlist!=NULL); 641 642 while (get_cfg_file_from_archive( bkpinfo )) 643 { 644 if (!ask_me_yes_or_no("Failed to find config file/archives. Choose another source?")) 645 { fatal_error("Unable to find config file/archives. Aborting."); } 646 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); 647 } 648 649 read_cfg_file_into_bkpinfo( g_mondo_cfg_file, bkpinfo ); 650 g_current_media_number = 1; 651 mvaddstr_and_log_it( 1, 30, "Comparing Automatically" ); 652 iamhere("Pre-MAD"); 653 retval = mount_all_devices( mountlist, FALSE ); 654 iamhere("Post-MAD"); 655 if ( retval ) 656 { 657 unmount_all_devices( mountlist ); 658 return( retval ); 659 } 660 if ( bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) 661 { 662 retval += compare_to_tape( bkpinfo ); 663 } 664 else if ( bkpinfo->backup_media_type == cdstream ) 665 { 666 retval += compare_to_cdstream( bkpinfo ); 667 } 668 else 669 { 670 retval += compare_to_CD( bkpinfo ); 671 } 672 if ( retval ) 673 { 674 mvaddstr_and_log_it( g_currentY++, 675 0, 676 "Warning - differences found during the compare phase"); 677 } 678 679 retval += unmount_all_devices( mountlist ); 680 681 if ( count_lines_in_file("/tmp/changed.txt") > 0 ) 682 { 683 mvaddstr_and_log_it( g_currentY++, 0, 684 "Differences found while files were being compared." ); 685 streamline_changes_file( "/tmp/changed.files", "/tmp/changed.txt" ); 686 if (count_lines_in_file( "/tmp/changed.files" ) <= 0 ) 687 { 688 mvaddstr_and_log_it( g_currentY++,0, 689 "...but they were logfiles and temporary files. Your archives are fine."); 690 log_to_screen( "The differences were logfiles and temporary files. Your archives are fine."); 691 } 692 else 693 { 694 q = count_lines_in_file("/tmp/changed.files"); 695 sprintf( tmp, "%ld significant difference%s found.", q, (q!=1) ? "s" : ""); 696 mvaddstr_and_log_it( g_currentY++, 0, tmp); 697 log_to_screen (tmp); 698 699 strcpy( tmp, "Type 'less /tmp/changed.files' for a list of non-matching files" ); 700 mvaddstr_and_log_it( g_currentY++, 0, tmp ); 701 log_to_screen( tmp ); 702 703 log_msg(2, "calling popup_changelist_from_file()"); 704 popup_changelist_from_file("/tmp/changed.files"); 705 log_msg(2, "Returning from popup_changelist_from_file()"); 706 } 707 } 708 else 709 { 710 log_to_screen( "No significant differences were found. Your backup is perfect." ); 711 } 712 kill_petris(); 713 paranoid_free(tmp); 714 return( retval ); 594 assert(bkpinfo != NULL); 595 assert(mountlist != NULL); 596 assert(raidlist != NULL); 597 598 while (get_cfg_file_from_archive(bkpinfo)) { 599 if (!ask_me_yes_or_no 600 ("Failed to find config file/archives. Choose another source?")) 601 { 602 fatal_error("Unable to find config file/archives. Aborting."); 603 } 604 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); 605 } 606 607 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo); 608 g_current_media_number = 1; 609 mvaddstr_and_log_it(1, 30, "Comparing Automatically"); 610 iamhere("Pre-MAD"); 611 retval = mount_all_devices(mountlist, FALSE); 612 iamhere("Post-MAD"); 613 if (retval) { 614 unmount_all_devices(mountlist); 615 return (retval); 616 } 617 if (bkpinfo->backup_media_type == tape 618 || bkpinfo->backup_media_type == udev) { 619 retval += compare_to_tape(bkpinfo); 620 } else if (bkpinfo->backup_media_type == cdstream) { 621 retval += compare_to_cdstream(bkpinfo); 622 } else { 623 retval += compare_to_CD(bkpinfo); 624 } 625 if (retval) { 626 mvaddstr_and_log_it(g_currentY++, 627 0, 628 "Warning - differences found during the compare phase"); 629 } 630 631 retval += unmount_all_devices(mountlist); 632 633 if (count_lines_in_file("/tmp/changed.txt") > 0) { 634 mvaddstr_and_log_it(g_currentY++, 0, 635 "Differences found while files were being compared."); 636 streamline_changes_file("/tmp/changed.files", "/tmp/changed.txt"); 637 if (count_lines_in_file("/tmp/changed.files") <= 0) { 638 mvaddstr_and_log_it(g_currentY++, 0, 639 "...but they were logfiles and temporary files. Your archives are fine."); 640 log_to_screen 641 ("The differences were logfiles and temporary files. Your archives are fine."); 642 } else { 643 q = count_lines_in_file("/tmp/changed.files"); 644 sprintf(tmp, "%ld significant difference%s found.", q, 645 (q != 1) ? "s" : ""); 646 mvaddstr_and_log_it(g_currentY++, 0, tmp); 647 log_to_screen(tmp); 648 649 strcpy(tmp, 650 "Type 'less /tmp/changed.files' for a list of non-matching files"); 651 mvaddstr_and_log_it(g_currentY++, 0, tmp); 652 log_to_screen(tmp); 653 654 log_msg(2, "calling popup_changelist_from_file()"); 655 popup_changelist_from_file("/tmp/changed.files"); 656 log_msg(2, "Returning from popup_changelist_from_file()"); 657 } 658 } else { 659 log_to_screen 660 ("No significant differences were found. Your backup is perfect."); 661 } 662 kill_petris(); 663 paranoid_free(tmp); 664 return (retval); 715 665 } 716 666 … … 727 677 * @return 0 for success, nonzero for failure. 728 678 */ 729 int 730 compare_to_cdstream(struct s_bkpinfo *bkpinfo) 679 int compare_to_cdstream(struct s_bkpinfo *bkpinfo) 731 680 { 732 681 int res; 733 682 734 683 /** needs malloc **/ 735 char *dir, *command; 736 737 assert(bkpinfo!=NULL); 738 malloc_string(dir); 739 malloc_string(command); 740 getcwd( dir, MAX_STR_LEN ); 741 chdir( bkpinfo->restore_path ); 742 743 sprintf( command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", bkpinfo->restore_path ); 744 run_program_and_log_output( command, FALSE ); 745 mvaddstr_and_log_it(g_currentY, 746 0, 747 "Verifying archives against filesystem" ); 748 749 if (bkpinfo->disaster_recovery && does_file_exist("/tmp/CDROM-LIVES-HERE")) 750 { strcpy(bkpinfo->media_device, last_line_of_file("/tmp/CDROM-LIVES-HERE")); } 751 else 752 { find_cdrom_device( bkpinfo->media_device, FALSE ); } 753 res = verify_tape_backups( bkpinfo ); 754 chdir( dir ); 755 if ( length_of_file ( "/tmp/changed.txt" ) > 2 && length_of_file ( "/tmp/changed.files" ) > 2 ) 756 { 757 log_msg(0, "Type 'less /tmp/changed.files' to see which files don't match the archives" ); 758 log_msg(2, "Calling popup_changelist_from_file()" ); 759 popup_changelist_from_file( "/tmp/changed.files" ); 760 log_msg(2, "Returned from popup_changelist_from_file()" ); 761 } 762 763 mvaddstr_and_log_it( g_currentY++, 74, "Done." ); 764 paranoid_free(dir); 765 paranoid_free(command); 766 return( res ); 684 char *dir, *command; 685 686 assert(bkpinfo != NULL); 687 malloc_string(dir); 688 malloc_string(command); 689 getcwd(dir, MAX_STR_LEN); 690 chdir(bkpinfo->restore_path); 691 692 sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", 693 bkpinfo->restore_path); 694 run_program_and_log_output(command, FALSE); 695 mvaddstr_and_log_it(g_currentY, 696 0, "Verifying archives against filesystem"); 697 698 if (bkpinfo->disaster_recovery 699 && does_file_exist("/tmp/CDROM-LIVES-HERE")) { 700 strcpy(bkpinfo->media_device, 701 last_line_of_file("/tmp/CDROM-LIVES-HERE")); 702 } else { 703 find_cdrom_device(bkpinfo->media_device, FALSE); 704 } 705 res = verify_tape_backups(bkpinfo); 706 chdir(dir); 707 if (length_of_file("/tmp/changed.txt") > 2 708 && length_of_file("/tmp/changed.files") > 2) { 709 log_msg(0, 710 "Type 'less /tmp/changed.files' to see which files don't match the archives"); 711 log_msg(2, "Calling popup_changelist_from_file()"); 712 popup_changelist_from_file("/tmp/changed.files"); 713 log_msg(2, "Returned from popup_changelist_from_file()"); 714 } 715 716 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 717 paranoid_free(dir); 718 paranoid_free(command); 719 return (res); 767 720 } 721 768 722 /************************************************************************** 769 723 *END_COMPARE_CD_STREAM * … … 782 736 * returns: int * 783 737 **************************************************************************/ 784 int 785 compare_to_tape( struct s_bkpinfo *bkpinfo ) 738 int compare_to_tape(struct s_bkpinfo *bkpinfo) 786 739 { 787 int res; 788 char *dir, *command; 789 790 assert(bkpinfo!=NULL); 791 malloc_string(dir); 792 malloc_string(command); 793 794 getcwd( dir, MAX_STR_LEN ); 795 chdir( bkpinfo->restore_path ); 796 sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", bkpinfo->restore_path); 797 run_program_and_log_output( command, FALSE ); 798 mvaddstr_and_log_it( g_currentY, 799 0, 800 "Verifying archives against filesystem"); 801 res = verify_tape_backups( bkpinfo ); 802 chdir( dir ); 803 if ( res ) 804 { 805 mvaddstr_and_log_it( g_currentY++, 74, "Failed." ); 806 } 807 else 808 { 809 mvaddstr_and_log_it( g_currentY++, 74, "Done." ); 810 } 811 paranoid_free(dir); 812 paranoid_free(command); 813 return( res ); 740 int res; 741 char *dir, *command; 742 743 assert(bkpinfo != NULL); 744 malloc_string(dir); 745 malloc_string(command); 746 747 getcwd(dir, MAX_STR_LEN); 748 chdir(bkpinfo->restore_path); 749 sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", 750 bkpinfo->restore_path); 751 run_program_and_log_output(command, FALSE); 752 mvaddstr_and_log_it(g_currentY, 753 0, "Verifying archives against filesystem"); 754 res = verify_tape_backups(bkpinfo); 755 chdir(dir); 756 if (res) { 757 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 758 } else { 759 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 760 } 761 paranoid_free(dir); 762 paranoid_free(command); 763 return (res); 814 764 } 815 765 … … 819 769 820 770 /* @} - end compareGroup */ 821
Note:
See TracChangeset
for help on using the changeset viewer.