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