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