source: MondoRescue/branches/2.2.10/mondo/src/common/libmondo-verify.c@ 2324

Last change on this file since 2324 was 2324, checked in by Bruno Cornec, 15 years ago

r3335@localhost: bruno | 2009-08-08 23:04:12 +0200

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