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

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

merge -r978:1042 $SVN_M/branches/stable

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