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