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

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

merge -r938:954 $SVN_M/branches/stable

  • Property svn:keywords set to Id
File size: 32.3 KB
RevLine 
[48]1/* $Id: libmondo-verify.c 956 2006-11-21 00:42:46Z 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 956 2006-11-21 00:42:46Z 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");
[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;
411 }
412 if (strstr(tarball_fname, ".bz2")
413 && strcmp(bkpinfo->zip_suffix, "bz2")) {
414 log_msg(2, "OK, I'm going to start using bzip2.");
[900]415 mr_allocstr(bkpinfo->zip_exe, "bzip2");
416 mr_allocstr(bkpinfo->zip_suffix, "bz2");
[48]417 bkpinfo->use_lzo = FALSE;
418 }
419 unlink(outlog);
420 if (strstr(tarball_fname, ".star")) {
421 bkpinfo->use_star = TRUE;
422 if (strstr(tarball_fname, ".bz2"))
[900]423 mr_asprintf(&command,
[59]424 "star -diff diffopts=mode,size,data file=%s %s >> %s 2>> %s",
425 tarball_fname,
426 (strstr(tarball_fname, ".bz2")) ? "-bz" : " ", outlog,
427 outlog);
[48]428 } else {
429 bkpinfo->use_star = FALSE;
[900]430 mr_asprintf(&command, "afio -r -P %s -Z %s >> %s 2>> %s",
[59]431 bkpinfo->zip_exe, tarball_fname, outlog, outlog);
[48]432 }
433 log_msg(6, "command=%s", command);
434 paranoid_system(command);
[900]435 mr_free(command);
[1]436
[48]437 if (length_of_file(outlog) < 10) {
[900]438 mr_asprintf(&command, "cat %s >> %s", outlog, MONDO_LOGFILE);
[48]439 } else {
[900]440 mr_asprintf(&command, "cut -d':' -f%d %s | sort -u",
[274]441 (bkpinfo->use_star) ? 1 : 2, outlog);
[48]442 pin = popen(command, "r");
443 if (pin) {
[900]444 for (mr_getline(&tmp, &n, pin); !feof(pin);
445 mr_getline(&tmp, &n, pin)) {
[48]446 if (bkpinfo->use_star) {
447 if (!strstr(tmp, "diffopts=")) {
448 while (strlen(tmp) > 0
449 && tmp[strlen(tmp) - 1] < 32) {
450 tmp[strlen(tmp) - 1] = '\0';
451 }
452 if (strchr(tmp, '/')) {
453 if (!diffs) {
454 log_msg(0, "'%s' - differences found",
455 tarball_fname);
456 }
457 log_msg(0, "star: /%s",
458 strip_afio_output_line(tmp));
459 diffs++;
460 }
461 }
462 } else {
463 if (!diffs) {
464 log_msg(0, "'%s' - differences found",
465 tarball_fname);
466 }
467 log_msg(0, "afio: /%s", strip_afio_output_line(tmp));
468 diffs++;
469 }
470 }
471 paranoid_pclose(pin);
[900]472 mr_free(tmp);
[48]473 } else {
474 log_OS_error(command);
475 }
476 }
[900]477 mr_free(outlog);
478 mr_free(command);
[1]479
[48]480 /* chdir(old_pwd); */
[783]481 // s-printf (tmp, "uniq -u %s >> %s", "/tmp/mondo-verify.err", MONDO_LOGFILE);
[48]482 // paranoid_system (tmp);
483 // unlink ("/tmp/mondo-verify.err");
484 return (0);
485}
[1]486
487
488/**
489 * Verify one afioball from the CD.
490 * Checks for existence (calls fatal_error() if it does not exist) and
491 * then calls verify_an_afioball().
492 * @param bkpinfo The backup information structure. Passed to verify_an_afioball().
493 * @param tarball_fname The filename of the afioball to verify.
494 * @return The return value of verify_an_afioball().
495 * @see verify_an_afioball
496 */
497int
[48]498verify_an_afioball_from_CD(struct s_bkpinfo *bkpinfo, char *tarball_fname)
[1]499{
500
[48]501 /*@ int ************************************************************* */
502 int res = 0;
[1]503
[48]504 assert(bkpinfo != NULL);
505 assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
[1]506
[48]507 log_msg(1, "Verifying %s", tarball_fname);
508 if (!does_file_exist(tarball_fname)) {
509 fatal_error("Cannot verify nonexistent afioball");
510 }
511 res = verify_a_tarball(bkpinfo, tarball_fname);
512 return (res);
[1]513}
514
515
516/**
517 * Verify one afioball from the opened tape/CD stream.
518 * Copies the file from tape to tmpdir and then calls verify_an_afioball().
519 * @param bkpinfo The backup information structure. Passed to verify_an_afioball().
520 * @param orig_fname The original filename of the afioball to verify.
521 * @param size The size of the afioball to verify.
522 * @return The return value of verify_an_afioball().
523 * @see verify_an_afioball
524 */
525int
[48]526verify_an_afioball_from_stream(struct s_bkpinfo *bkpinfo, char *orig_fname,
527 long long size)
[1]528{
529
[48]530 /*@ int ************************************************************** */
531 int retval = 0;
[1]532 int res = 0;
533
[48]534 /*@ buffers ********************************************************** */
535 char *tmp;
[1]536 char *tarball_fname;
537
[48]538 /*@ pointers ********************************************************* */
539 char *p;
[1]540
[48]541 assert(bkpinfo != NULL);
542 assert_string_is_neither_NULL_nor_zerolength(orig_fname);
[1]543
[48]544 p = strrchr(orig_fname, '/');
545 if (!p) {
546 p = orig_fname;
547 } else {
548 p++;
549 }
[900]550 mr_asprintf(&tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
[48]551 paranoid_system(tmp);
[900]552 mr_free(tmp);
[48]553
[900]554 mr_asprintf(&tarball_fname, "%s/tmpfs/temporary-%s", bkpinfo->tmpdir, p);
[48]555 /* BERLIOS : useless
[900]556 mr_asprintf(&tmp, "Temporarily copying file from tape to '%s'",
[59]557 tarball_fname);
558 log_it(tmp);
[900]559 mr_free(tmp);
[59]560 */
[48]561 read_file_from_stream_to_file(bkpinfo, tarball_fname, size);
562 res = verify_a_tarball(bkpinfo, tarball_fname);
563 if (res) {
[900]564 mr_asprintf(&tmp,
[59]565 "Afioball '%s' no longer matches your live filesystem",
566 p);
[48]567 log_msg(0, tmp);
[900]568 mr_free(tmp);
[48]569 retval++;
570 }
571 unlink(tarball_fname);
[900]572 mr_free(tarball_fname);
[48]573 return (retval);
[1]574}
575
576
577/**
578 * Verify one biggiefile form the opened tape/CD stream.
579 * @param bkpinfo The backup information structure. @c bkpinfo->tmpdir is the only field used.
580 * @param biggie_fname The filename of the biggiefile to verify.
581 * @param size The size in bytes of said biggiefile.
582 * @return 0 for success (even if the file doesn't match); nonzero for a tape error.
583 */
584int
[48]585verify_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo,
586 char *biggie_fname, long long size)
[1]587{
588
[48]589 /*@ int ************************************************************* */
590 int retval = 0;
[1]591 int res = 0;
592 int current_slice_number = 0;
593 int ctrl_chr = '\0';
594
[48]595 /*@ char ************************************************************ */
[1]596 char *test_file;
597 char *biggie_cksum;
598 char *orig_cksum;
599 char *tmp;
[127]600 char *slice_fnam = (char *) &res;
[48]601
602 /*@ pointers ******************************************************** */
[1]603 char *p;
604
[48]605 /*@ long long ******************************************************* */
606 long long slice_siz;
[1]607
[48]608 assert(bkpinfo != NULL);
609 assert_string_is_neither_NULL_nor_zerolength(biggie_fname);
[1]610
[48]611 p = strrchr(biggie_fname, '/');
612 if (!p) {
613 p = biggie_fname;
614 } else {
615 p++;
[1]616 }
[900]617 mr_asprintf(&test_file, "%s/temporary-%s", bkpinfo->tmpdir, p);
618 mr_asprintf(&tmp,
[127]619 "Temporarily copying biggiefile %s's slices from tape to '%s'",
620 p, test_file);
621 log_it(tmp);
[900]622 mr_free(tmp);
[59]623 for (res =
624 read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr);
[48]625 ctrl_chr != BLK_STOP_A_BIGGIE;
[59]626 res =
627 read_header_block_from_stream(&slice_siz, slice_fnam,
628 &ctrl_chr)) {
[48]629 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
630 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
631 }
632 res = read_file_from_stream_to_file(bkpinfo, test_file, slice_siz);
633 unlink(test_file);
[900]634 mr_free(slice_fnam);
[127]635 slice_fnam = (char *) &res;
[59]636 res =
637 read_header_block_from_stream(&slice_siz, slice_fnam,
638 &ctrl_chr);
[48]639 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
640 log_msg(2, "test_file = %s", test_file);
641 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
642 }
643 current_slice_number++;
644 retval += res;
[900]645 mr_free(slice_fnam);
[127]646 slice_fnam = (char *) &res;
[1]647 }
[900]648 mr_free(test_file);
[48]649
[900]650 mr_asprintf(&biggie_cksum, slice_fnam);
651 mr_free(slice_fnam);
[48]652
653 if (biggie_cksum[0] != '\0') {
[171]654 orig_cksum = calc_checksum_of_file(biggie_fname);
[48]655 if (strcmp(biggie_cksum, orig_cksum)) {
[900]656 mr_asprintf(&tmp, "orig cksum=%s; curr cksum=%s", biggie_cksum,
[59]657 orig_cksum);
[48]658 log_msg(2, tmp);
[900]659 mr_free(tmp);
[48]660
[900]661 mr_asprintf(&tmp, _("%s has changed on live filesystem"),
[59]662 biggie_fname);
[48]663 log_to_screen(tmp);
[900]664 mr_free(tmp);
[48]665
[900]666 mr_asprintf(&tmp, "echo \"%s\" >> /tmp/biggies.changed",
[59]667 biggie_fname);
[48]668 system(tmp);
[900]669 mr_free(tmp);
[48]670 }
[900]671 mr_free(orig_cksum);
[1]672 }
[900]673 mr_free(biggie_cksum);
[48]674
675 return (retval);
[1]676}
677
678
679/**
680 * Verify all afioballs from the opened tape/CD stream.
681 * @param bkpinfo The backup information structure. Fields used:
682 * - @c bkpinfo->restore_path
683 * - @c bkpinfo->tmpdir
684 *
685 * @return 0 for success (even if there are differences); nonzero for a tape error.
686 */
[48]687int verify_afioballs_from_stream(struct s_bkpinfo *bkpinfo)
[1]688{
[48]689 /*@ int ********************************************************** */
690 int retval = 0;
[1]691 int res = 0;
692 long current_afioball_number = 0;
693 int ctrl_chr = 0;
694 int total_afioballs = 0;
695
[48]696 /*@ buffers ***************************************************** */
697 char *tmp;
[127]698 char *fname = (char *) &res; /* Should NOT be NULL */
[48]699 char *curr_xattr_list_fname;
700 char *curr_acl_list_fname;
[1]701
[48]702 /*@ long long *************************************************** */
703 long long size = 0;
[1]704
[48]705 assert(bkpinfo != NULL);
[1]706
[956]707 if (g_getfattr) {
708 mr_asprintf(&curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ,
709 bkpinfo->tmpdir);
710 }
711 if (g_getfacl) {
712 mr_asprintf(&curr_acl_list_fname, ACL_BIGGLST_FNAME_RAW_SZ,
713 bkpinfo->tmpdir);
714 }
[507]715 log_to_screen(_("Verifying regular archives on tape"));
[48]716 total_afioballs = get_last_filelist_number(bkpinfo) + 1;
[507]717 open_progress_form(_("Verifying filesystem"),
718 _("I am verifying archives against your live filesystem now."),
719 _("Please wait. This may take a couple of hours."), "",
[48]720 total_afioballs);
[122]721 res = read_header_block_from_stream(&size, NULL, &ctrl_chr);
[48]722 if (ctrl_chr != BLK_START_AFIOBALLS) {
723 iamhere("YOU SHOULD NOT GET HERE");
724 iamhere("Grabbing the EXAT files");
725 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
726 res =
[122]727 read_EXAT_files_from_tape(bkpinfo, &size, NULL, &ctrl_chr,
[48]728 curr_xattr_list_fname,
729 curr_acl_list_fname);
730 }
[1]731 }
[48]732 if (ctrl_chr != BLK_START_AFIOBALLS) {
733 wrong_marker(BLK_START_AFIOBALLS, ctrl_chr);
[1]734 }
[900]735 mr_free(curr_xattr_list_fname);
736 mr_free(curr_acl_list_fname);
[48]737
738 for (res = read_header_block_from_stream(&size, fname, &ctrl_chr);
739 ctrl_chr != BLK_STOP_AFIOBALLS;
[127]740 res = read_header_block_from_stream(&size, fname, &ctrl_chr)) {
[956]741 if (g_getfattr) {
742 mr_asprintf(&curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
743 bkpinfo->tmpdir, current_afioball_number);
744 }
745 if (g_getfacl) {
746 mr_asprintf(&curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
747 bkpinfo->tmpdir, current_afioball_number);
748 }
[48]749 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
750 iamhere("Reading EXAT files from tape");
[900]751 mr_free(fname);
[127]752 fname = (char *) &res;
[48]753 res =
754 read_EXAT_files_from_tape(bkpinfo, &size, fname, &ctrl_chr,
755 curr_xattr_list_fname,
756 curr_acl_list_fname);
757 }
[900]758 mr_free(curr_xattr_list_fname);
759 mr_free(curr_acl_list_fname);
[48]760
761 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
762 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
763 }
[900]764 mr_asprintf(&tmp, "Verifying fileset #%ld", current_afioball_number);
[48]765 /*log_it(tmp); */
766 update_progress_form(tmp);
[900]767 mr_free(tmp);
[48]768
769 res = verify_an_afioball_from_stream(bkpinfo, fname, size);
770 if (res) {
[900]771 mr_asprintf(&tmp, _("Afioball %ld differs from live filesystem"),
[59]772 current_afioball_number);
[48]773 log_to_screen(tmp);
[900]774 mr_free(tmp);
[48]775 }
776 retval += res;
777 current_afioball_number++;
778 g_current_progress++;
[900]779 mr_free(fname);
[127]780 fname = (char *) &res;
[48]781 res = read_header_block_from_stream(&size, fname, &ctrl_chr);
782 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
783 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
784 }
[900]785 mr_free(fname);
[127]786 fname = (char *) &res;
[1]787 }
[48]788 log_msg(1, "All done with afioballs");
789 close_progress_form();
[900]790 mr_free(fname);
[48]791 return (retval);
[1]792}
793
[48]794
[1]795/**
796 * Verify all biggiefiles on the opened CD/tape stream.
797 * @param bkpinfo The backup information structure. Fields used:
798 * - @c bkpinfo->restore_path
799 * - @c bkpinfo->tmpdir
800 *
801 * @return 0 for success (even if there are differences); nonzero for a tape error.
802 */
[48]803int verify_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo)
[1]804{
805
[48]806 /*@ int ************************************************************ */
807 int retval = 0;
[1]808 int res = 0;
809 int ctrl_chr = 0;
810
[48]811 /*@ long *********************************************************** */
812 long noof_biggiefiles = 0;
[1]813 long current_biggiefile_number = 0;
814
[48]815 /*@ buffers ******************************************************** */
[127]816 char *orig_fname = (char *) &ctrl_chr; /* Should NOT be NULL */
[122]817 char *logical_fname;
[1]818 char *comment;
819 char *curr_xattr_list_fname;
820 char *curr_acl_list_fname;
[48]821 /*@ pointers ******************************************************* */
[1]822 char *p;
823
[48]824 /*@ long long size ************************************************* */
825 long long size = 0;
[1]826
[48]827 assert(bkpinfo != NULL);
[1]828
[956]829 if (g_getfattr) {
830 mr_asprintf(&curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ,
831 bkpinfo->tmpdir);
832 }
833 if (g_getfacl) {
834 mr_asprintf(&curr_acl_list_fname, ACL_BIGGLST_FNAME_RAW_SZ,
835 bkpinfo->tmpdir);
836 }
[900]837 mr_asprintf(&comment, "Verifying all bigfiles.");
[48]838 log_to_screen(comment);
839 res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr);
840 if (ctrl_chr != BLK_START_BIGGIEFILES) {
841 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
842 iamhere("Grabbing the EXAT biggiefiles");
[900]843 mr_free(orig_fname);
[127]844 orig_fname = (char *) &ctrl_chr;
[48]845 res =
846 read_EXAT_files_from_tape(bkpinfo, &size, orig_fname,
847 &ctrl_chr, curr_xattr_list_fname,
848 curr_acl_list_fname);
849 }
[1]850 }
[900]851 mr_free(curr_xattr_list_fname);
852 mr_free(curr_acl_list_fname);
853 mr_free(orig_fname);
[127]854 orig_fname = (char *) &ctrl_chr;
[48]855
856 if (ctrl_chr != BLK_START_BIGGIEFILES) {
857 wrong_marker(BLK_START_BIGGIEFILES, ctrl_chr);
[1]858 }
[48]859 noof_biggiefiles = (long) size;
860 log_msg(1, "noof_biggiefiles = %ld", noof_biggiefiles);
[507]861 open_progress_form(_("Verifying big files"), comment,
862 _("Please wait. This may take some time."), "",
[48]863 noof_biggiefiles);
[900]864 mr_free(comment);
[48]865
866 for (res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr);
867 ctrl_chr != BLK_STOP_BIGGIEFILES;
868 res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr))
[1]869 {
[48]870 if (ctrl_chr != BLK_START_A_NORMBIGGIE
871 && ctrl_chr != BLK_START_A_PIHBIGGIE) {
872 wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr);
873 }
874 p = strrchr(orig_fname, '/');
875 if (!p) {
876 p = orig_fname;
877 } else {
878 p++;
879 }
[900]880 mr_asprintf(&comment, _("Verifying bigfile #%ld (%ld K)"),
[59]881 current_biggiefile_number, (long) size >> 10);
[48]882 update_progress_form(comment);
[900]883 mr_free(comment);
[48]884
[900]885 mr_asprintf(&logical_fname, "%s/%s", bkpinfo->restore_path,
[59]886 orig_fname);
887 res =
888 verify_a_biggiefile_from_stream(bkpinfo, logical_fname, size);
[900]889 mr_free(logical_fname);
[48]890 retval += res;
891 current_biggiefile_number++;
892 g_current_progress++;
[900]893 mr_free(orig_fname);
[127]894 orig_fname = (char *) &ctrl_chr;
[1]895 }
[48]896 close_progress_form();
897 return (retval);
[1]898}
899
900/* @} - end of LLverifyGroup */
901
902
903/**
904 * Verify the CD indicated by @c g_current_media_number.
905 * @param bkpinfo The backup information structure. Fields used:
906 * - @c bkpinfo->isodir
[20]907 * - @c bkpinfo->prefix
[1]908 * - @c bkpinfo->manual_cd_tray
909 * - @c bkpinfo->media_device
910 * - @c bkpinfo->nfs_remote_dir
911 * - @c bkpinfo->tmpdir
912 * - @c bkpinfo->verify_data
913 *
914 * @return 0 for success (even if differences are found), nonzero for failure.
915 * @ingroup verifyGroup
916 */
[48]917int verify_cd_image(struct s_bkpinfo *bkpinfo)
[1]918{
919
[48]920 /*@ int ************************************************************ */
921 int retval = 0;
[1]922
[48]923 /*@ buffers ******************************************************** */
924 char *mountpoint;
[1]925 char *command;
926 char *tmp;
927 char *fname;
928#ifdef __FreeBSD__
[48]929 char mdd[32];
[1]930 char *mddevice = mdd;
[48]931 int ret = 0;
932 int vndev = 2;
[1]933#else
934//skip
935#endif
936
[48]937 assert(bkpinfo != NULL);
[1]938
[900]939 mr_asprintf(&mountpoint, "%s/cdrom", bkpinfo->tmpdir);
940 mr_asprintf(&fname, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->nfs_remote_dir,
[485]941 bkpinfo->prefix, g_current_media_number);
[1]942
[48]943 mkdir(mountpoint, 1777);
944 sync();
945 if (!does_file_exist(fname)) {
[900]946 mr_asprintf(&tmp,
[59]947 "%s not found; assuming you backed up to CD; verifying CD...",
948 fname);
[48]949 log_msg(2, tmp);
[900]950 mr_free(tmp);
[48]951
952 if (bkpinfo->manual_cd_tray) {
[507]953 popup_and_OK(_("Please push CD tray closed."));
[48]954 }
955 if (find_and_mount_actual_cd(bkpinfo, mountpoint)) {
[507]956 log_to_screen(_("failed to mount actual CD"));
[48]957 return (1);
958 }
959 } else {
[900]960 mr_asprintf(&tmp, "%s found; verifying ISO...", fname);
[48]961 log_to_screen(tmp);
[900]962 mr_free(tmp);
[1]963#ifdef __FreeBSD__
[48]964 ret = 0;
965 vndev = 2;
966 mddevice = make_vn(fname);
967 if (ret) {
[900]968 mr_asprintf(&tmp, _("make_vn of %s failed; unable to verify ISO\n"),
[59]969 fname);
[48]970 log_to_screen(tmp);
[900]971 mr_free(tmp);
[48]972 return (1);
973 }
[900]974 mr_asprintf(&command, "mount_cd9660 %s %s", mddevice, mountpoint);
[1]975#else
[900]976 mr_asprintf(&command, "mount -o loop,ro -t iso9660 %s %s", fname,
[59]977 mountpoint);
[1]978#endif
[48]979 if (run_program_and_log_output(command, FALSE)) {
[900]980 mr_asprintf(&tmp, _("%s failed; unable to mount ISO image\n"),
[59]981 command);
[48]982 log_to_screen(tmp);
[900]983 mr_free(tmp);
[48]984 return (1);
985 }
[900]986 mr_free(command);
[1]987 }
[48]988 log_msg(2, "OK, I've mounted the ISO/CD\n");
[900]989 mr_asprintf(&tmp, "%s/archives/NOT-THE-LAST", mountpoint);
[48]990 if (!does_file_exist(tmp)) {
991 log_msg
992 (2,
993 "This is the last CD. I am therefore setting bkpinfo->verify_data to FALSE.");
994 bkpinfo->verify_data = FALSE;
[1]995/*
996 (a) It's an easy way to tell the calling subroutine that we've finished &
997 there are no more CD's to be verified; (b) It stops the post-backup verifier
998 from running after the per-CD verifier has run too.
999*/
[48]1000 }
[900]1001 mr_free(tmp);
[1]1002
[48]1003 verify_afioballs_on_CD(bkpinfo, mountpoint);
1004 iamhere("before verify_all_slices");
1005 verify_all_slices_on_CD(bkpinfo, mountpoint);
1006
[1]1007#ifdef __FreeBSD__
[48]1008 ret = 0;
[900]1009 mr_asprintf(&command, "umount %s", mountpoint);
[48]1010 ret += system(command);
1011
1012 ret += kick_vn(mddevice);
1013 if (ret)
[1]1014#else
[900]1015 mr_asprintf(&command, "umount %s", mountpoint);
[48]1016
1017 if (system(command))
[1]1018#endif
1019 {
[900]1020 mr_asprintf(&tmp, "%s failed; unable to unmount ISO image\n",
[59]1021 command);
[48]1022 log_to_screen(tmp);
[900]1023 mr_free(tmp);
[48]1024 retval++;
1025 } else {
1026 log_msg(2, "OK, I've unmounted the ISO file\n");
[1]1027 }
[900]1028 mr_free(command);
1029 mr_free(mountpoint);
[48]1030
1031 if (!does_file_exist(fname)) {
[900]1032 mr_asprintf(&command, "umount %s", bkpinfo->media_device);
[48]1033 run_program_and_log_output(command, 2);
[900]1034 mr_free(command);
[48]1035
1036 if (!bkpinfo->please_dont_eject
1037 && eject_device(bkpinfo->media_device)) {
1038 log_msg(2, "Failed to eject CD-ROM drive");
1039 }
1040 }
[900]1041 mr_free(fname);
[48]1042 return (retval);
[1]1043}
1044
[48]1045
[1]1046/**
1047 * Verify all backups on tape.
1048 * This should be done after the backup process has already closed the tape.
1049 * @param bkpinfo The backup information structure. Passed to various helper functions.
1050 * @return 0 for success (even if thee were differences), nonzero for failure.
1051 * @ingroup verifyGroup
1052 */
[48]1053int verify_tape_backups(struct s_bkpinfo *bkpinfo)
[1]1054{
1055
[48]1056 /*@ int ************************************************************ */
1057 int retval = 0;
[1]1058
[48]1059 /*@ buffers ******************************************************** */
1060 char *tmp;
1061 char *changed_files_fname;
[1]1062
[48]1063 /*@ long *********************************************************** */
1064 long diffs = 0;
[1]1065
[48]1066 assert(bkpinfo != NULL);
[1]1067
[48]1068 log_msg(3, "verify_tape_backups --- starting");
[507]1069 log_to_screen(_("Verifying backups"));
[48]1070 openin_tape(bkpinfo);
[1]1071
[48]1072 /* verify archives themselves */
1073 retval += verify_afioballs_from_stream(bkpinfo);
1074 retval += verify_biggiefiles_from_stream(bkpinfo);
1075
1076 /* find the final blocks */
[688]1077 sync();
[48]1078 sleep(2);
1079 closein_tape(bkpinfo);
1080
1081 /* close tape; exit */
1082 // fclose(g_tape_stream); <-- not needed; is handled by closein_tape()
1083 paranoid_system
1084 ("rm -f /tmp/biggies.changed /tmp/changed.files.[0-9]* 2> /dev/null");
[900]1085 mr_asprintf(&changed_files_fname, "/tmp/changed.files.%d",
[59]1086 (int) (random() % 32767));
[900]1087 mr_asprintf(&tmp,
[914]1088 "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]1089 (bkpinfo->use_star) ? "star" : "afio", MONDO_LOGFILE,
[59]1090 changed_files_fname);
[48]1091 log_msg(2, "Running command to derive list of changed files");
1092 log_msg(2, tmp);
1093 if (system(tmp)) {
1094 if (does_file_exist(changed_files_fname)
1095 && length_of_file(changed_files_fname) > 2) {
1096 log_to_screen
[507]1097 (_("Warning - unable to check logfile to derive list of changed files"));
[48]1098 } else {
1099 log_to_screen
[507]1100 (_("No differences found. Therefore, no 'changed.files' text file."));
[48]1101 }
1102 }
[900]1103 mr_free(tmp);
[48]1104
[900]1105 mr_asprintf(&tmp, "cat /tmp/biggies.changed >> %s", changed_files_fname);
[48]1106 paranoid_system(tmp);
[900]1107 mr_free(tmp);
[48]1108
1109 diffs = count_lines_in_file(changed_files_fname);
1110 if (diffs > 0) {
[900]1111 mr_asprintf(&tmp, "cp -f %s %s", changed_files_fname,
[59]1112 "/tmp/changed.files");
[48]1113 run_program_and_log_output(tmp, FALSE);
[900]1114 mr_free(tmp);
[48]1115
[900]1116 mr_asprintf(&tmp,
[59]1117 "%ld files differed from live filesystem; type less %s or less %s to see",
1118 diffs, changed_files_fname, "/tmp/changed.files");
[48]1119 log_msg(0, tmp);
[900]1120 mr_free(tmp);
[48]1121
1122 log_to_screen
[507]1123 (_("See /tmp/changed.files for a list of nonmatching files."));
[48]1124 log_to_screen
[507]1125 (_("The files probably changed on filesystem, not on backup media."));
[48]1126 // retval++;
1127 }
[900]1128 mr_free(changed_files_fname);
[48]1129 return (retval);
[1]1130}
1131
1132
1133/**
1134 * Generate the filename of a tarball to verify.
1135 * @param bkpinfo The backup information structure. @c bkpinfo->zip_suffix is the only field used.
1136 * @param mountpoint The directory where the CD/DVD/ISO is mounted.
1137 * @param setno The afioball number to get the location of.
1138 * @return The absolute path to the afioball.
1139 * @note The returned string points to static data that will be overwritten with each call.
1140 * @ingroup stringGroup
1141 */
[48]1142char *vfy_tball_fname(struct s_bkpinfo *bkpinfo, char *mountpoint,
1143 int setno)
[1]1144{
[48]1145 /*@ buffers ******************************************************* */
1146 static char *output;
[1]1147
[48]1148 assert(bkpinfo != NULL);
1149 assert_string_is_neither_NULL_nor_zerolength(mountpoint);
[900]1150 mr_asprintf(&output, "%s/archives/%d.star.%s", mountpoint, setno,
[59]1151 bkpinfo->zip_suffix);
[48]1152 if (!does_file_exist(output)) {
[900]1153 mr_free(output);
1154 mr_asprintf(&output, "%s/archives/%d.afio.%s", mountpoint, setno,
[59]1155 bkpinfo->zip_suffix);
[48]1156 }
1157 return (output);
[1]1158}
Note: See TracBrowser for help on using the repository browser.