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