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