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

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

merge -r1045:1078 £SVN_M/branches/stable

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