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