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