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