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