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