source: MondoRescue/branches/2.2.5/mondo/src/mondorestore/mondo-rstr-compare.c@ 1848

Last change on this file since 1848 was 1747, checked in by Bruno Cornec, 17 years ago
  • Solve problem on tmpfs in restore init (Problem of inexistant symlink and busybox)
  • Create MONDO_CACHE and use it everywhere + creation at start
  • Property svn:keywords set to Id
File size: 23.5 KB
RevLine 
[1]1/***************************************************************************
2 mondo-compare.c - compares mondoarchive data
3 -------------------
4 begin : Fri Apr 25 2003
5 copyright : (C) 2000 by Hugo Rabson
6 email : Hugo Rabson <hugorabson@msn.com>
[128]7 cvsid : $Id: mondo-rstr-compare.c 1747 2007-10-30 12:18:55Z bruno $
[1]8***************************************************************************/
9
10/***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18
19/***************************************************************************
20 * Change Log *
21 ***************************************************************************
22.
23
24
25
2610/21/2003
27- changed "/mnt/cdrom" to MNT_CDROM
28
2910/18
30- don't say unknown compressor if no compressor at all
31
3209/17
33- cleaned up logging & conversion-to-changed.txt
34- cleaned up compare_mode()
35
3609/16
37- fixed bad malloc(),free() pairs in compare_a_biggiefile()
38
3909/14
40- compare_mode() --- a couple of strings were the wrong way round,
41 e.g. changed.txt and changed.files
42
4305/05
44- exclude /dev/ * from list of changed files
45
4604/30
47- added textonly mode
48
4904/27
50- improved compare_mode() to allow for ISO/cd/crazy people
51
5204/25
53- first incarnation
54*/
55
56
57#include <pthread.h>
58#include "../common/my-stuff.h"
59#include "../common/mondostructures.h"
60#include "../common/libmondo.h"
61//#include "../../config.h"
62#include "mr-externs.h"
63#include "mondo-rstr-compare.h"
64#include "mondo-restore-EXT.h"
65#include "mondo-rstr-tools-EXT.h"
66
[1316]67extern char *MONDO_LOGFILE;
68
[1645]69/* Reference to global bkpinfo */
70extern struct s_bkpinfo *bkpinfo;
71
[1664]72extern char *g_mountlist_fname;
73
[128]74//static char cvsid[] = "$Id: mondo-rstr-compare.c 1747 2007-10-30 12:18:55Z bruno $";
[1]75
[128]76void popup_changelist_from_file(char *);
[1]77
78
79/**
80 * @addtogroup LLcompareGroup
81 * @{
82 */
83/**
84 * Compare biggiefile number @p bigfileno with the filesystem mounted on @p MNT_RESTORING.
85 * @param bkpinfo The backup information structure. Only used in insist_on_this_cd_number().
86 * @param bigfileno The biggiefile number (starting from 0) to compare.
87 * @note This function uses an MD5 checksum.
88 */
[1645]89int compare_a_biggiefile(long bigfileno)
[1]90{
91
[128]92 FILE *fin;
93 FILE *fout;
[1]94
95 /** needs malloc *******/
[128]96 char *checksum_ptr;
97 char *original_cksum_ptr;
98 char *bigfile_fname_ptr;
99 char *tmp_ptr;
100 char *command_ptr;
[1]101
[128]102 char *checksum, *original_cksum, *bigfile_fname, *tmp, *command;
[1]103
[128]104 char *p;
105 int i;
106 int retval = 0;
107
108 struct s_filename_and_lstat_info biggiestruct;
109
110 malloc_string(checksum);
111 malloc_string(original_cksum);
112 malloc_string(bigfile_fname);
113 malloc_string(tmp);
114 malloc_string(command);
115 malloc_string(checksum_ptr);
116 malloc_string(original_cksum_ptr);
117 malloc_string(bigfile_fname_ptr);
118 malloc_string(command_ptr);
119 malloc_string(tmp_ptr);
120
[1]121 /*********************************************************************
122 * allocate memory clear test sab 16 feb 2003 *
123 *********************************************************************/
[128]124 assert(bkpinfo != NULL);
125 memset(checksum_ptr, '\0', sizeof(checksum));
126 memset(original_cksum_ptr, '\0', sizeof(original_cksum));
127 memset(bigfile_fname_ptr, '\0', sizeof(bigfile_fname));
128 memset(tmp_ptr, '\0', sizeof(tmp));
129 memset(command_ptr, '\0', sizeof(command));
[1]130 /** end **/
131
[128]132 if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) {
133 if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) {
[1645]134 insist_on_this_cd_number((++g_current_media_number));
[128]135 } else {
136 sprintf(tmp_ptr,
137 "No CD's left. No biggiefiles left. No prob, Bob.");
138 log_msg(2, tmp_ptr);
139 return (0);
140 }
[1]141 }
[128]142 if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) {
143 sprintf(tmp_ptr,
[541]144 "Cannot open bigfile %ld (%s)'s info file",
[128]145 bigfileno + 1, bigfile_fname_ptr);
146 log_to_screen(tmp_ptr);
147 return (1);
[1]148 }
[128]149 fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin);
150 paranoid_fclose(fin);
151
152 strcpy(checksum_ptr, biggiestruct.checksum);
153 strcpy(bigfile_fname_ptr, biggiestruct.filename);
154
155 log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename);
156 log_msg(2, "biggiestruct.checksum = %s", biggiestruct.checksum);
157
[541]158 sprintf(tmp_ptr, "Comparing %s", bigfile_fname_ptr);
[128]159
160 if (!g_text_mode) {
161 newtDrawRootText(0, 22, tmp_ptr);
162 newtRefresh();
[1]163 }
[128]164 if (!checksum[0]) {
165 log_msg(2, "Warning - %s has no checksum", bigfile_fname_ptr);
166 }
167 if (!strncmp(bigfile_fname_ptr, "/dev/", 5)) {
168 strcpy(original_cksum_ptr, "IGNORE");
169 } else {
170 sprintf(command_ptr,
[1315]171 "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors",
[128]172 MNT_RESTORING, bigfile_fname_ptr);
173 }
174 log_msg(2, command_ptr);
[1321]175 sprintf(tmp_ptr, "cat /tmp/errors >> %s 2> /dev/null", MONDO_LOGFILE);
176 paranoid_system(tmp_ptr);
[128]177 if (system(command_ptr)) {
178 log_OS_error("Warning - command failed");
179 original_cksum[0] = '\0';
180 return (1);
181 } else {
182 if (!(fin = fopen("/tmp/md5sum.txt", "r"))) {
183 log_msg(2,
184 "Unable to open /tmp/md5sum.txt; can't get live checksum");
185 original_cksum[0] = '\0';
186 return (1);
187 } else {
188 fgets(original_cksum_ptr, MAX_STR_LEN - 1, fin);
189 paranoid_fclose(fin);
190 for (i = strlen(original_cksum_ptr);
191 i > 0 && original_cksum[i - 1] < 32; i--);
192 original_cksum[i] = '\0';
193 p = (char *) strchr(original_cksum_ptr, ' ');
194 if (p) {
195 *p = '\0';
196 }
197 }
198 }
199 sprintf(tmp_ptr, "bigfile #%ld ('%s') ", bigfileno + 1,
200 bigfile_fname_ptr);
201 if (!strcmp(checksum_ptr, original_cksum_ptr) != 0) {
202 strcat(tmp_ptr, " ... OK");
203 } else {
204 strcat(tmp_ptr, "... changed");
205 retval++;
206 }
207 log_msg(1, tmp_ptr);
208 if (retval) {
[1747]209 if (!(fout = fopen(MONDO_CACHE"/changed.txt", "a"))) {
[128]210 fatal_error("Cannot openout changed.txt");
211 }
212 fprintf(fout, "%s\n", bigfile_fname_ptr);
213 paranoid_fclose(fout);
214 }
[1]215
[128]216 paranoid_free(original_cksum_ptr);
217 paranoid_free(original_cksum);
218 paranoid_free(bigfile_fname_ptr);
219 paranoid_free(bigfile_fname);
220 paranoid_free(checksum_ptr);
221 paranoid_free(checksum);
222 paranoid_free(command_ptr);
223 paranoid_free(command);
224 paranoid_free(tmp_ptr);
225 paranoid_free(tmp);
[1]226
[128]227 return (retval);
[1]228}
229
230/**************************************************************************
231 *END_COMPARE_A_BIGGIEFILE *
232 **************************************************************************/
233
234
235/**
236 * Compare all biggiefiles in the backup.
237 * @return 0 for success, nonzero for failure.
238 */
[1645]239int compare_all_biggiefiles()
[1]240{
[128]241 int retval = 0;
242 int res;
243 long noof_biggiefiles, bigfileno = 0;
244 char tmp[MAX_STR_LEN];
[1]245
[128]246 log_msg(1, "Comparing biggiefiles");
247
248 if (length_of_file(BIGGIELIST) < 6) {
249 log_msg(1,
250 "OK, really teeny-tiny biggielist; not comparing biggiefiles");
251 return (0);
252 }
253 noof_biggiefiles = count_lines_in_file(BIGGIELIST);
254 if (noof_biggiefiles <= 0) {
255 log_msg(1, "OK, no biggiefiles; not comparing biggiefiles");
256 return (0);
257 }
258 mvaddstr_and_log_it(g_currentY, 0,
[541]259 "Comparing large files ");
260 open_progress_form("Comparing large files",
261 "I am now comparing the large files",
262 "against the filesystem. Please wait.", "",
[128]263 noof_biggiefiles);
264 for (bigfileno = 0; bigfileno < noof_biggiefiles; bigfileno++) {
265 sprintf(tmp, "Comparing big file #%ld", bigfileno + 1);
266 log_msg(1, tmp);
267 update_progress_form(tmp);
[1645]268 res = compare_a_biggiefile(bigfileno);
[128]269 retval += res;
270 g_current_progress++;
271 }
272 close_progress_form();
273 return (0);
274 if (retval) {
[541]275 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
[128]276 } else {
[541]277 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
[128]278 }
279 return (retval);
[1]280}
[128]281
[1]282/**************************************************************************
283 *END_COMPARE_ALL_BIGGIEFILES *
284 **************************************************************************/
285
286
287/**
288 * Compare afioball @p tarball_fname against the filesystem.
289 * You must be chdir()ed to the directory where the filesystem is mounted
290 * before you call this function.
291 * @param tarball_fname The filename of the tarball to compare.
292 * @param current_tarball_number The fileset number contained in @p tarball_fname.
293 * @return 0 for success, nonzero for failure.
294 */
[128]295int compare_a_tarball(char *tarball_fname, int current_tarball_number)
[1]296{
[128]297 int retval = 0;
298 int res;
299 long noof_lines;
300 long archiver_errors;
301 bool use_star;
302
[1]303 /*** needs malloc *********/
[128]304 char *command, *tmp, *filelist_name, *logfile, *archiver_exe,
305 *compressor_exe;
[1]306
[128]307 malloc_string(command);
308 malloc_string(tmp);
309 malloc_string(filelist_name);
310 malloc_string(logfile);
311 malloc_string(archiver_exe);
312 malloc_string(compressor_exe);
[1]313
[128]314 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
315 assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
316 sprintf(logfile, "/tmp/afio.log.%d", current_tarball_number);
317 sprintf(filelist_name, MNT_CDROM "/archives/filelist.%d",
318 current_tarball_number);
[1]319
[128]320 noof_lines = count_lines_in_file(filelist_name);
321
322 if (strstr(tarball_fname, ".bz2")) {
323 strcpy(compressor_exe, "bzip2");
[998]324 } else if (strstr(tarball_fname, ".gz")) {
325 strcpy(compressor_exe, "gzip");
[128]326 } else if (strstr(tarball_fname, ".lzo")) {
327 strcpy(compressor_exe, "lzop");
328 } else {
329 compressor_exe[0] = '\0';
[1]330 }
[128]331
332 if (use_star) {
333 strcpy(archiver_exe, "star");
334 } else {
335 strcpy(archiver_exe, "afio");
[1]336 }
[128]337
338 if (compressor_exe[0]) {
339 strcpy(tmp, compressor_exe);
340 if (!find_home_of_exe(tmp)) {
341 fatal_error("(compare_a_tarball) Compression program missing");
342 }
343 if (use_star) // star
344 {
345 if (!strcmp(compressor_exe, "bzip2")) {
346 strcat(archiver_exe, " -bz");
347 } else {
348 fatal_error
349 ("(compare_a_tarball) Please use only bzip2 with star");
350 }
351 } else // afio
352 {
353 sprintf(compressor_exe, "-P %s -Z", tmp);
354 }
355 }
[1]356// star -diff H=star -bz file=....
357
358#ifdef __FreeBSD__
359#define BUFSIZE 512L
360#else
361#define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE
362#endif
[128]363 if (use_star) // doesn't use compressor_exe
364 {
365 sprintf(command,
366 "%s -diff H=star file=%s >> %s 2>> %s",
367 archiver_exe, tarball_fname, logfile, logfile);
368 } else {
369 sprintf(command,
370 "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s",
371 archiver_exe,
372 TAPE_BLOCK_SIZE,
373 BUFSIZE, compressor_exe, tarball_fname, logfile, logfile);
374 }
[1]375#undef BUFSIZE
376
[128]377 res = system(command);
378 retval += res;
379 if (res) {
380 log_OS_error(command);
381 sprintf(tmp, "Warning - afio returned error = %d", res);
[1585]382 log_msg(2, tmp);
[128]383 }
384 if (length_of_file(logfile) > 5) {
385 sprintf(command,
[1747]386 "sed s/': \\\"'/\\|/ %s | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort -u | grep -vE \"^dev/.*\" >> "MONDO_CACHE"/changed.txt",
[128]387 logfile);
388 system(command);
389 archiver_errors = count_lines_in_file(logfile);
390 } else {
391 archiver_errors = 0;
392 }
393 sprintf(tmp, "%ld difference%c in fileset #%d ",
394 archiver_errors, (archiver_errors != 1) ? 's' : ' ',
395 current_tarball_number);
396 if (archiver_errors) {
397 sprintf(tmp,
398 "Differences found while processing fileset #%d ",
399 current_tarball_number);
400 log_msg(1, tmp);
401 }
402 unlink(logfile);
403 paranoid_free(command);
404 paranoid_free(tmp);
405 paranoid_free(filelist_name);
406 paranoid_free(logfile);
[1630]407 paranoid_free(archiver_exe);
408 paranoid_free(compressor_exe);
[128]409 return (retval);
[1]410}
[128]411
[1]412/**************************************************************************
413 *END_COMPARE_A_TARBALL *
414 **************************************************************************/
415
416
417/**
418 * Compare all afioballs in this backup.
419 * @param bkpinfo The backup media structure. Passed to other functions.
420 * @return 0 for success, nonzero for failure.
421 */
[1645]422int compare_all_tarballs()
[1]423{
[128]424 int retval = 0;
425 int res;
426 int current_tarball_number = 0;
[1]427
428 /** needs malloc **********/
429
[128]430 char *tarball_fname, *progress_str, *tmp;
431 long max_val;
[1]432
[128]433 malloc_string(tarball_fname);
434 malloc_string(progress_str);
435 malloc_string(tmp);
436
437 assert(bkpinfo != NULL);
[541]438 mvaddstr_and_log_it(g_currentY, 0, "Comparing archives");
[128]439 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
440
441 max_val = atol(tmp);
[541]442 sprintf(progress_str, "Comparing with %s #%d ",
[128]443 media_descriptor_string(bkpinfo->backup_media_type),
444 g_current_media_number);
445
[541]446 open_progress_form("Comparing files",
447 "Comparing tarballs against filesystem.",
448 "Please wait. This may take some time.",
[128]449 progress_str, max_val);
450
451 log_to_screen(progress_str);
452
453 for (;;) {
[1645]454 insist_on_this_cd_number(g_current_media_number);
[128]455 update_progress_form(progress_str);
456 sprintf(tarball_fname,
457 MNT_CDROM "/archives/%d.afio.bz2", current_tarball_number);
458
459 if (!does_file_exist(tarball_fname)) {
460 sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.lzo",
461 current_tarball_number);
462 }
463 if (!does_file_exist(tarball_fname)) {
[1630]464 sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.gz",
465 current_tarball_number);
466 }
467 if (!does_file_exist(tarball_fname)) {
[128]468 sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.",
469 current_tarball_number);
470 }
471 if (!does_file_exist(tarball_fname)) {
472 sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.bz2",
473 current_tarball_number);
474 }
475 if (!does_file_exist(tarball_fname)) {
476 sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.",
477 current_tarball_number);
478 }
479 if (!does_file_exist(tarball_fname)) {
480 if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST") ||
481 system("find " MNT_CDROM
482 "/archives/slice* > /dev/null 2> /dev/null")
483 == 0) {
484 log_msg(2, "OK, I think I'm done with tarballs...");
485 break;
486 }
487 log_msg(2, "OK, I think it's time for another CD...");
488 g_current_media_number++;
[541]489 sprintf(progress_str, "Comparing with %s #%d ",
[128]490 media_descriptor_string(bkpinfo->backup_media_type),
491 g_current_media_number);
492 log_to_screen(progress_str);
493 } else {
494 res = compare_a_tarball(tarball_fname, current_tarball_number);
495
496 g_current_progress++;
497 current_tarball_number++;
498 }
[1]499 }
[128]500 close_progress_form();
501 if (retval) {
[541]502 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
[128]503 } else {
[541]504 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
[1]505 }
[128]506 paranoid_free(tarball_fname);
507 paranoid_free(progress_str);
508 paranoid_free(tmp);
509 return (retval);
[1]510}
[128]511
[1]512/**************************************************************************
513 *END_COMPARE_ALL_TARBALLS *
514 **************************************************************************/
515
516/* @} - end LLcompareGroup */
517
518
519/**
520 * @addtogroup compareGroup
521 * @{
522 */
523/**
524 * Compare all data on a CD-R/CD-RW/DVD/ISO/NFS-based backup.
525 * @param bkpinfo The backup information structure. Passed to other functions.
526 * @return 0 for success, nonzero for failure.
527 */
[1645]528int compare_to_CD()
[1]529{
530 /** needs malloc *********/
[128]531 char *tmp, *cwd, *new, *command;
532 int resA = 0;
533 int resB = 0;
534 long noof_changed_files;
[1]535
[128]536 malloc_string(tmp);
537 malloc_string(cwd);
538 malloc_string(new);
539 malloc_string(command);
[1]540
[128]541 assert(bkpinfo != NULL);
542
543 getcwd(cwd, MAX_STR_LEN - 1);
544 chdir(bkpinfo->restore_path);
545 getcwd(new, MAX_STR_LEN - 1);
[1645]546 insist_on_this_cd_number(g_current_media_number);
[1747]547 unlink(MONDO_CACHE"/changed.txt");
[128]548
[1645]549 resA = compare_all_tarballs();
550 resB = compare_all_biggiefiles();
[128]551 chdir(cwd);
[1747]552 noof_changed_files = count_lines_in_file(MONDO_CACHE"/changed.txt");
[128]553 if (noof_changed_files) {
[541]554 sprintf(tmp, "%ld files do not match the backup ",
[128]555 noof_changed_files);
556 // mvaddstr_and_log_it( g_currentY++, 0, tmp );
557 log_to_screen(tmp);
[1747]558 sprintf(command, "cat "MONDO_CACHE"/changed.txt >> %s", MONDO_LOGFILE);
[128]559 paranoid_system(command);
560 } else {
[541]561 sprintf(tmp, "All files match the backup ");
[128]562 mvaddstr_and_log_it(g_currentY++, 0, tmp);
563 log_to_screen(tmp);
564 }
565
566 paranoid_free(tmp);
567 paranoid_free(cwd);
568 paranoid_free(new);
569 paranoid_free(command);
570
571 return (resA + resB);
[1]572}
573
574/**************************************************************************
575 *END_COMPARE_TO_CD *
576 **************************************************************************/
577
578
579
580
581/**
582 * Compare all data in the user's backup.
583 * This function will mount filesystems, compare afioballs and biggiefiles,
584 * and show the user the differences.
585 * @param bkpinfo The backup information structure. Passed to other functions.
586 * @param mountlist The mountlist containing partitions to mount.
587 * @param raidlist The raidlist containing the user's RAID devices.
588 * @return The number of errors/differences found.
589 */
590int
[1645]591compare_mode(struct mountlist_itself *mountlist,
[128]592 struct raidlist_itself *raidlist)
[1]593{
[128]594 int retval = 0;
[1664]595 int res = 0;
[128]596 long q;
597 char *tmp;
[1585]598 char *new;
599 char *cwd;
[1]600
[128]601 malloc_string(tmp);
[1585]602 malloc_string(new);
603 malloc_string(cwd);
[128]604
[1]605 /**************************************************************************
606 * also deletes tmp/filelist.full & tmp/biggielist.txt _and_ tries to *
607 * restore them from start of tape, if available *
608 **************************************************************************/
[128]609 assert(bkpinfo != NULL);
610 assert(mountlist != NULL);
611 assert(raidlist != NULL);
[1]612
[1645]613 while (get_cfg_file_from_archive()) {
[128]614 if (!ask_me_yes_or_no
[541]615 ("Failed to find config file/archives. Choose another source?"))
[128]616 {
617 fatal_error("Unable to find config file/archives. Aborting.");
618 }
[1645]619 interactively_obtain_media_parameters_from_user(FALSE);
[128]620 }
[1]621
[1645]622 read_cfg_file_into_bkpinfo(g_mondo_cfg_file);
[1664]623
624 /* edit_mountlist if wanted */
625 iamhere("About to edit mountlist");
626 if (g_text_mode) {
627 save_mountlist_to_disk(mountlist, g_mountlist_fname);
628 sprintf(tmp, "%s %s", find_my_editor(), g_mountlist_fname);
629 res = system(tmp);
630 load_mountlist(mountlist, g_mountlist_fname);
631 } else {
632 res = edit_mountlist(g_mountlist_fname, mountlist, raidlist);
633 }
634 iamhere("Finished editing mountlist");
635 if (res) {
636 paranoid_MR_finish(1);
637 }
638 save_mountlist_to_disk(mountlist, g_mountlist_fname);
639 save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
640
[128]641 g_current_media_number = 1;
[541]642 mvaddstr_and_log_it(1, 30, "Comparing Automatically");
[128]643 iamhere("Pre-MAD");
644 retval = mount_all_devices(mountlist, FALSE);
645 iamhere("Post-MAD");
646 if (retval) {
647 unmount_all_devices(mountlist);
648 return (retval);
649 }
650 if (bkpinfo->backup_media_type == tape
651 || bkpinfo->backup_media_type == udev) {
[1645]652 retval += compare_to_tape();
[128]653 } else if (bkpinfo->backup_media_type == cdstream) {
[1645]654 retval += compare_to_cdstream();
[128]655 } else {
[1645]656 retval += compare_to_CD();
[128]657 }
658 if (retval) {
659 mvaddstr_and_log_it(g_currentY++,
660 0,
[541]661 "Warning - differences found during the compare phase");
[128]662 }
[1]663
[1747]664 if (count_lines_in_file(MONDO_CACHE"/changed.txt") > 0) {
[128]665 mvaddstr_and_log_it(g_currentY++, 0,
[541]666 "Differences found while files were being compared.");
[1747]667 streamline_changes_file(MONDO_CACHE"/changed.files", MONDO_CACHE"/changed.txt");
668 if (count_lines_in_file(MONDO_CACHE"/changed.files") <= 0) {
[128]669 mvaddstr_and_log_it(g_currentY++, 0,
[541]670 "...but they were logfiles and temporary files. Your archives are fine.");
[128]671 log_to_screen
[541]672 ("The differences were logfiles and temporary files. Your archives are fine.");
[128]673 } else {
[1747]674 q = count_lines_in_file(MONDO_CACHE"/changed.files");
[541]675 sprintf(tmp, "%ld significant difference%s found.", q,
[128]676 (q != 1) ? "s" : "");
677 mvaddstr_and_log_it(g_currentY++, 0, tmp);
678 log_to_screen(tmp);
[1]679
[128]680 strcpy(tmp,
[541]681 "Type 'less /tmp/changed.files' for a list of non-matching files");
[128]682 mvaddstr_and_log_it(g_currentY++, 0, tmp);
683 log_to_screen(tmp);
[1]684
[128]685 log_msg(2, "calling popup_changelist_from_file()");
[1585]686 getcwd(cwd, MAX_STR_LEN - 1);
687 chdir(bkpinfo->restore_path);
688 getcwd(new, MAX_STR_LEN - 1);
[1747]689 popup_changelist_from_file(MONDO_CACHE"/changed.files");
[1585]690 chdir(cwd);
[128]691 log_msg(2, "Returning from popup_changelist_from_file()");
692 }
693 } else {
694 log_to_screen
[541]695 ("No significant differences were found. Your backup is perfect.");
[1]696 }
[1585]697 retval += unmount_all_devices(mountlist);
698
[128]699 kill_petris();
700 paranoid_free(tmp);
[1585]701 paranoid_free(new);
702 paranoid_free(cwd);
[128]703 return (retval);
[1]704}
705
706/**************************************************************************
707 *END_COMPARE_MODE *
708 **************************************************************************/
709
710/**
711 * Compare all data on a cdstream-based backup.
712 * @param bkpinfo The backup information structure. Fields used:
713 * - @c bkpinfo->disaster_recovery
714 * - @c bkpinfo->media_device
715 * - @c bkpinfo->restore_path
716 * @return 0 for success, nonzero for failure.
717 */
[1645]718int compare_to_cdstream()
[1]719{
[128]720 int res;
[1]721
722 /** needs malloc **/
[128]723 char *dir, *command;
[1]724
[128]725 assert(bkpinfo != NULL);
726 malloc_string(dir);
727 malloc_string(command);
728 getcwd(dir, MAX_STR_LEN);
729 chdir(bkpinfo->restore_path);
[1]730
[128]731 sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp",
732 bkpinfo->restore_path);
733 run_program_and_log_output(command, FALSE);
734 mvaddstr_and_log_it(g_currentY,
[541]735 0, "Verifying archives against filesystem");
[1]736
[128]737 if (bkpinfo->disaster_recovery
738 && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
739 strcpy(bkpinfo->media_device,
740 last_line_of_file("/tmp/CDROM-LIVES-HERE"));
741 } else {
742 find_cdrom_device(bkpinfo->media_device, FALSE);
743 }
[1645]744 res = verify_tape_backups();
[128]745 chdir(dir);
[1747]746 if (length_of_file(MONDO_CACHE"/changed.txt") > 2
747 && length_of_file(MONDO_CACHE"/changed.files") > 2) {
[128]748 log_msg(0,
[1747]749 "Type 'less "MONDO_CACHE"/changed.files' to see which files don't match the archives");
[128]750 log_msg(2, "Calling popup_changelist_from_file()");
[1747]751 popup_changelist_from_file(MONDO_CACHE"/changed.files");
[128]752 log_msg(2, "Returned from popup_changelist_from_file()");
753 }
754
[541]755 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
[128]756 paranoid_free(dir);
757 paranoid_free(command);
758 return (res);
[1]759}
[128]760
[1]761/**************************************************************************
762 *END_COMPARE_CD_STREAM *
763 **************************************************************************/
764
765
766/**
767 * Compare all data on a tape-based backup.
768 * @param bkpinfo The backup information structure. Field used: @c bkpinfo->restore_path.
769 * @return 0 for success, nonzero for failure.
770 */
771/**************************************************************************
772 * F@COMPARE_TO_TAPE() *
773 * compare_to_tape() - gots me?? *
774 * *
775 * returns: int *
776 **************************************************************************/
[1645]777int compare_to_tape()
[1]778{
[128]779 int res;
780 char *dir, *command;
[1]781
[128]782 assert(bkpinfo != NULL);
783 malloc_string(dir);
784 malloc_string(command);
785
786 getcwd(dir, MAX_STR_LEN);
787 chdir(bkpinfo->restore_path);
788 sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp",
789 bkpinfo->restore_path);
790 run_program_and_log_output(command, FALSE);
791 mvaddstr_and_log_it(g_currentY,
[541]792 0, "Verifying archives against filesystem");
[1645]793 res = verify_tape_backups();
[128]794 chdir(dir);
795 if (res) {
[541]796 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
[128]797 } else {
[541]798 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
[128]799 }
800 paranoid_free(dir);
801 paranoid_free(command);
802 return (res);
[1]803}
804
805/**************************************************************************
806 *END_COMPARE_TO_TAPE *
807 **************************************************************************/
808
809/* @} - end compareGroup */
Note: See TracBrowser for help on using the repository browser.