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