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

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

Logfile management in mondo (partly)

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