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