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