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