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