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