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