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