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