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