source: MondoRescue/trunk/mondo/src/common/libmondo-verify.c@ 1081

Last change on this file since 1081 was 1081, checked in by Bruno Cornec, 17 years ago

merge -r1078:1080 $SVN_M/branches/stable

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