source: MondoRescue/branches/stable/mondo/src/common/libmondo-verify.c@ 1229

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

Merge trunk modifications for libmondo-verify.c

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