source: MondoRescue/branches/3.1/mondo/src/common/libmondo-verify.c@ 3161

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