[1] | 1 | /***************************************************************************
|
---|
[1080] | 2 | * compares mondoarchive data
|
---|
| 3 | * $Id: mondo-rstr-compare.c 1638 2007-09-19 07:32:00Z 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 |
|
---|
[128] | 21 | //static char cvsid[] = "$Id: mondo-rstr-compare.c 1638 2007-09-19 07:32:00Z bruno $";
|
---|
[1] | 22 |
|
---|
[128] | 23 | void popup_changelist_from_file(char *);
|
---|
[1] | 24 |
|
---|
| 25 |
|
---|
| 26 | /**
|
---|
| 27 | * @addtogroup LLcompareGroup
|
---|
| 28 | * @{
|
---|
| 29 | */
|
---|
| 30 | /**
|
---|
| 31 | * Compare biggiefile number @p bigfileno with the filesystem mounted on @p MNT_RESTORING.
|
---|
| 32 | * @param bkpinfo The backup information structure. Only used in insist_on_this_cd_number().
|
---|
| 33 | * @param bigfileno The biggiefile number (starting from 0) to compare.
|
---|
| 34 | * @note This function uses an MD5 checksum.
|
---|
| 35 | */
|
---|
[128] | 36 | int compare_a_biggiefile(struct s_bkpinfo *bkpinfo, long bigfileno)
|
---|
[1] | 37 | {
|
---|
| 38 |
|
---|
[1200] | 39 | FILE *fin = NULL;
|
---|
| 40 | FILE *fout = NULL;
|
---|
[1] | 41 |
|
---|
| 42 | /** needs malloc *******/
|
---|
[1200] | 43 | char *checksum = NULL;
|
---|
| 44 | char *original_cksum = NULL;
|
---|
| 45 | char *bigfile_fname = NULL;
|
---|
| 46 | char *tmp = NULL;
|
---|
| 47 | char *command = NULL;
|
---|
[1] | 48 |
|
---|
[1200] | 49 | char *p = NULL;
|
---|
| 50 | int i = 0;
|
---|
| 51 | size_t n = 0;
|
---|
[128] | 52 | int retval = 0;
|
---|
| 53 |
|
---|
| 54 | struct s_filename_and_lstat_info biggiestruct;
|
---|
| 55 |
|
---|
| 56 | assert(bkpinfo != NULL);
|
---|
[1] | 57 |
|
---|
[128] | 58 | if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) {
|
---|
| 59 | if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) {
|
---|
| 60 | insist_on_this_cd_number(bkpinfo, (++g_current_media_number));
|
---|
| 61 | } else {
|
---|
[1200] | 62 | mr_msg(2, "No CD's left. No biggiefiles left. No problem.");
|
---|
[128] | 63 | return (0);
|
---|
| 64 | }
|
---|
[1] | 65 | }
|
---|
[128] | 66 | if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) {
|
---|
[1200] | 67 | log_to_screen(_("Cannot open bigfile %ld (%s)'s info file"),
|
---|
| 68 | bigfileno + 1, slice_fname(bigfileno, 0, ARCHIVES_PATH, ""));
|
---|
[128] | 69 | return (1);
|
---|
[1] | 70 | }
|
---|
[128] | 71 | fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin);
|
---|
| 72 | paranoid_fclose(fin);
|
---|
| 73 |
|
---|
[1200] | 74 | mr_asprintf(&bigfile_fname, biggiestruct.filename);
|
---|
| 75 | mr_msg(2, "biggiestruct.filename = %s", bigfile_fname);
|
---|
| 76 | if (!biggiestruct.checksum[0]) {
|
---|
| 77 | mr_msg(2, "Warning - %s has no checksum", bigfile_fname);
|
---|
| 78 | } else {
|
---|
| 79 | mr_asprintf(&checksum, biggiestruct.checksum);
|
---|
| 80 | mr_msg(2, "biggiestruct.checksum = %s", checksum);
|
---|
| 81 | }
|
---|
[128] | 82 |
|
---|
| 83 | if (!g_text_mode) {
|
---|
[1200] | 84 | mr_asprintf(&tmp, _("Comparing %s"), bigfile_fname);
|
---|
| 85 | newtDrawRootText(0, 22, tmp);
|
---|
[128] | 86 | newtRefresh();
|
---|
[1200] | 87 | mr_free(tmp);
|
---|
[1] | 88 | }
|
---|
[1200] | 89 |
|
---|
| 90 | if (!strncmp(bigfile_fname, "/dev/", 5)) {
|
---|
| 91 | mr_msg(2, _("Ignoring device %s"), bigfile_fname);
|
---|
| 92 | mr_free(bigfile_fname);
|
---|
| 93 | return(0);
|
---|
[128] | 94 | }
|
---|
[1200] | 95 | mr_asprintf(&command,
|
---|
[1326] | 96 | "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors",
|
---|
[1200] | 97 | MNT_RESTORING, bigfile_fname);
|
---|
| 98 | mr_msg(2, command);
|
---|
| 99 | if (system(command)) {
|
---|
[128] | 100 | log_OS_error("Warning - command failed");
|
---|
[1326] | 101 | mr_asprintf(&tmp, "cat /tmp/errors >> %s 2> /dev/null", MONDO_LOGFILE);
|
---|
| 102 | paranoid_system(tmp);
|
---|
| 103 | mr_free(tmp);
|
---|
[1200] | 104 | mr_free(command);
|
---|
| 105 | mr_free(bigfile_fname);
|
---|
[128] | 106 | return (1);
|
---|
| 107 | } else {
|
---|
[1200] | 108 | mr_free(command);
|
---|
[128] | 109 | if (!(fin = fopen("/tmp/md5sum.txt", "r"))) {
|
---|
[1200] | 110 | mr_msg(2, "Unable to open /tmp/md5sum.txt; can't get live checksum");
|
---|
| 111 | mr_free(bigfile_fname);
|
---|
[128] | 112 | return (1);
|
---|
| 113 | } else {
|
---|
[1200] | 114 | mr_getline(&original_cksum, &n, fin);
|
---|
[128] | 115 | paranoid_fclose(fin);
|
---|
[1200] | 116 | for (i = strlen(original_cksum);
|
---|
[128] | 117 | i > 0 && original_cksum[i - 1] < 32; i--);
|
---|
| 118 | original_cksum[i] = '\0';
|
---|
[1200] | 119 | p = (char *) strchr(original_cksum, ' ');
|
---|
[128] | 120 | if (p) {
|
---|
| 121 | *p = '\0';
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
[1200] | 125 | if (!strcmp(checksum, original_cksum) != 0) {
|
---|
| 126 | mr_msg(1, "bigfile #%ld ('%s') ... OK", bigfileno + 1, bigfile_fname);
|
---|
[128] | 127 | } else {
|
---|
[1200] | 128 | mr_msg(1, "bigfile #%ld ('%s') ... changed", bigfileno + 1, bigfile_fname);
|
---|
[128] | 129 | retval++;
|
---|
| 130 | }
|
---|
[1200] | 131 | mr_free(original_cksum);
|
---|
| 132 | mr_free(checksum);
|
---|
| 133 |
|
---|
[128] | 134 | if (retval) {
|
---|
| 135 | if (!(fout = fopen("/tmp/changed.txt", "a"))) {
|
---|
| 136 | fatal_error("Cannot openout changed.txt");
|
---|
| 137 | }
|
---|
[1200] | 138 | fprintf(fout, "%s\n", bigfile_fname);
|
---|
[128] | 139 | paranoid_fclose(fout);
|
---|
| 140 | }
|
---|
[1080] | 141 | mr_free(bigfile_fname);
|
---|
[1] | 142 |
|
---|
[128] | 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 | */
|
---|
[128] | 156 | int compare_all_biggiefiles(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 157 | {
|
---|
[128] | 158 | int retval = 0;
|
---|
[1200] | 159 | int res = 0;
|
---|
| 160 | long noof_biggiefiles = 0L, bigfileno = 0L;
|
---|
| 161 | char *tmp = NULL;
|
---|
[1] | 162 |
|
---|
[128] | 163 | assert(bkpinfo != NULL);
|
---|
[1108] | 164 | mr_msg(1, "Comparing biggiefiles");
|
---|
[128] | 165 |
|
---|
| 166 | if (length_of_file(BIGGIELIST) < 6) {
|
---|
[1108] | 167 | mr_msg(1,
|
---|
[128] | 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) {
|
---|
[1108] | 173 | mr_msg(1, "OK, no biggiefiles; not comparing biggiefiles");
|
---|
[128] | 174 | return (0);
|
---|
| 175 | }
|
---|
| 176 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
[1200] | 177 | _
|
---|
| 178 | ("Comparing large files "));
|
---|
| 179 | open_progress_form(_("Comparing large files"),
|
---|
| 180 | _("I am now comparing the large files"),
|
---|
| 181 | _("against the filesystem. Please wait."), "",
|
---|
[128] | 182 | noof_biggiefiles);
|
---|
| 183 | for (bigfileno = 0; bigfileno < noof_biggiefiles; bigfileno++) {
|
---|
[1200] | 184 | mr_asprintf(&tmp, "Comparing big file #%ld", bigfileno + 1);
|
---|
[1108] | 185 | mr_msg(1, tmp);
|
---|
[128] | 186 | update_progress_form(tmp);
|
---|
[1200] | 187 | mr_free(tmp);
|
---|
| 188 |
|
---|
[128] | 189 | res = compare_a_biggiefile(bkpinfo, bigfileno);
|
---|
| 190 | retval += res;
|
---|
| 191 | g_current_progress++;
|
---|
| 192 | }
|
---|
| 193 | close_progress_form();
|
---|
[1200] | 194 | /* BERLIOS: useless ?
|
---|
[128] | 195 | return (0);
|
---|
[1200] | 196 | */
|
---|
[128] | 197 | if (retval) {
|
---|
[1200] | 198 | mvaddstr_and_log_it(g_currentY++, 74, _("Errors."));
|
---|
[128] | 199 | } else {
|
---|
[1200] | 200 | mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
|
---|
[128] | 201 | }
|
---|
| 202 | return (retval);
|
---|
[1] | 203 | }
|
---|
[128] | 204 |
|
---|
[1] | 205 | /**************************************************************************
|
---|
| 206 | *END_COMPARE_ALL_BIGGIEFILES *
|
---|
| 207 | **************************************************************************/
|
---|
| 208 |
|
---|
| 209 |
|
---|
| 210 | /**
|
---|
| 211 | * Compare afioball @p tarball_fname against the filesystem.
|
---|
| 212 | * You must be chdir()ed to the directory where the filesystem is mounted
|
---|
| 213 | * before you call this function.
|
---|
| 214 | * @param tarball_fname The filename of the tarball to compare.
|
---|
| 215 | * @param current_tarball_number The fileset number contained in @p tarball_fname.
|
---|
| 216 | * @return 0 for success, nonzero for failure.
|
---|
| 217 | */
|
---|
[128] | 218 | int compare_a_tarball(char *tarball_fname, int current_tarball_number)
|
---|
[1] | 219 | {
|
---|
[128] | 220 | int retval = 0;
|
---|
[1200] | 221 | int res = 0;
|
---|
| 222 | long noof_lines = 0L;
|
---|
| 223 | long archiver_errors = 0L;
|
---|
| 224 | bool use_star = FALSE;
|
---|
[128] | 225 |
|
---|
[1200] | 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;
|
---|
[1638] | 232 | #ifdef __FreeBSD__
|
---|
| 233 | long BUFSIZE=512L;
|
---|
| 234 | #else
|
---|
| 235 | long BUFSIZE=(1024L*1024L)/mr_conf->external_tape_blexternal_tape_blocksize;
|
---|
| 236 | #endif
|
---|
[1] | 237 |
|
---|
[1638] | 238 |
|
---|
[128] | 239 | use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
|
---|
| 240 | assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
|
---|
[1200] | 241 | mr_asprintf(&filelist_name, MNT_CDROM "/archives/filelist.%d",
|
---|
[128] | 242 | current_tarball_number);
|
---|
[1] | 243 |
|
---|
[128] | 244 | noof_lines = count_lines_in_file(filelist_name);
|
---|
[1200] | 245 | mr_free(filelist_name);
|
---|
[128] | 246 |
|
---|
| 247 | if (strstr(tarball_fname, ".bz2")) {
|
---|
[1200] | 248 | mr_asprintf(&compressor_exe, "bzip2");
|
---|
[998] | 249 | } else if (strstr(tarball_fname, ".gz")) {
|
---|
[1200] | 250 | mr_asprintf(&compressor_exe, "gzip");
|
---|
[128] | 251 | } else if (strstr(tarball_fname, ".lzo")) {
|
---|
[1200] | 252 | mr_asprintf(&compressor_exe, "lzop");
|
---|
[128] | 253 | } else {
|
---|
[1200] | 254 | compressor_exe = NULL;
|
---|
[1] | 255 | }
|
---|
[128] | 256 |
|
---|
| 257 | if (use_star) {
|
---|
[1200] | 258 | mr_asprintf(&archiver_exe, "star -bz");
|
---|
[128] | 259 | } else {
|
---|
[1200] | 260 | mr_asprintf(&archiver_exe, "afio");
|
---|
[1] | 261 | }
|
---|
[128] | 262 |
|
---|
[1200] | 263 | if (compressor_exe != NULL) {
|
---|
| 264 | if (!find_home_of_exe(compressor_exe)) {
|
---|
[128] | 265 | fatal_error("(compare_a_tarball) Compression program missing");
|
---|
| 266 | }
|
---|
[1200] | 267 | if (use_star) {
|
---|
| 268 | if (strcmp(compressor_exe, "bzip2")) {
|
---|
[128] | 269 | fatal_error
|
---|
| 270 | ("(compare_a_tarball) Please use only bzip2 with star");
|
---|
| 271 | }
|
---|
[1200] | 272 | } else {
|
---|
| 273 | tmp = compressor_exe;
|
---|
| 274 | mr_asprintf(&compressor_exe, "-P %s -Z", tmp);
|
---|
| 275 | mr_free(tmp);
|
---|
[128] | 276 | }
|
---|
| 277 | }
|
---|
[1] | 278 |
|
---|
[1200] | 279 | mr_asprintf(&logfile, "/tmp/afio.log.%d", current_tarball_number);
|
---|
[128] | 280 | if (use_star) // doesn't use compressor_exe
|
---|
| 281 | {
|
---|
[1200] | 282 | mr_asprintf(&command,
|
---|
[128] | 283 | "%s -diff H=star file=%s >> %s 2>> %s",
|
---|
| 284 | archiver_exe, tarball_fname, logfile, logfile);
|
---|
| 285 | } else {
|
---|
[1200] | 286 | mr_asprintf(&command,
|
---|
[128] | 287 | "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s",
|
---|
| 288 | archiver_exe,
|
---|
[1638] | 289 | mr_conf->external_tape_blocksize,
|
---|
[128] | 290 | BUFSIZE, compressor_exe, tarball_fname, logfile, logfile);
|
---|
| 291 | }
|
---|
[1200] | 292 | mr_free(archiver_exe);
|
---|
| 293 | mr_free(compressor_exe);
|
---|
[1] | 294 |
|
---|
[128] | 295 | res = system(command);
|
---|
| 296 | retval += res;
|
---|
| 297 | if (res) {
|
---|
| 298 | log_OS_error(command);
|
---|
[1594] | 299 | mr_msg(2, tmp);
|
---|
[128] | 300 | }
|
---|
[1200] | 301 | mr_free(command);
|
---|
| 302 |
|
---|
[128] | 303 | if (length_of_file(logfile) > 5) {
|
---|
[1200] | 304 | mr_asprintf(&command,
|
---|
[1293] | 305 | "sed s/': \\\"'/\\|/ %s | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort -u | grep -vE \"^dev/.*\" >> /tmp/changed.txt",
|
---|
[128] | 306 | logfile);
|
---|
| 307 | system(command);
|
---|
[1200] | 308 | mr_free(command);
|
---|
[128] | 309 | archiver_errors = count_lines_in_file(logfile);
|
---|
| 310 | } else {
|
---|
| 311 | archiver_errors = 0;
|
---|
| 312 | }
|
---|
| 313 | if (archiver_errors) {
|
---|
[1200] | 314 | mr_msg(1, "Differences found while processing fileset #%d ",
|
---|
[128] | 315 | current_tarball_number);
|
---|
| 316 | }
|
---|
| 317 | unlink(logfile);
|
---|
[1080] | 318 | mr_free(logfile);
|
---|
[128] | 319 | return (retval);
|
---|
[1] | 320 | }
|
---|
[128] | 321 |
|
---|
[1] | 322 | /**************************************************************************
|
---|
| 323 | *END_COMPARE_A_TARBALL *
|
---|
| 324 | **************************************************************************/
|
---|
| 325 |
|
---|
| 326 |
|
---|
| 327 | /**
|
---|
| 328 | * Compare all afioballs in this backup.
|
---|
| 329 | * @param bkpinfo The backup media structure. Passed to other functions.
|
---|
| 330 | * @return 0 for success, nonzero for failure.
|
---|
| 331 | */
|
---|
[128] | 332 | int compare_all_tarballs(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 333 | {
|
---|
[128] | 334 | int retval = 0;
|
---|
[1200] | 335 | int res = 0;
|
---|
[128] | 336 | int current_tarball_number = 0;
|
---|
[1] | 337 |
|
---|
[1200] | 338 | char *tarball_fname = NULL;
|
---|
| 339 | char *progress_str = NULL;
|
---|
| 340 | char *tmp = NULL;
|
---|
| 341 | long max_val = 0L;
|
---|
[1] | 342 |
|
---|
[1200] | 343 | assert(bkpinfo != NULL);
|
---|
| 344 | mvaddstr_and_log_it(g_currentY, 0, _("Comparing archives"));
|
---|
[128] | 345 | malloc_string(tmp);
|
---|
| 346 | read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
|
---|
| 347 |
|
---|
| 348 | max_val = atol(tmp);
|
---|
[1200] | 349 | mr_free(tmp);
|
---|
| 350 |
|
---|
| 351 | mr_asprintf(&progress_str, _("Comparing with %s #%d "),
|
---|
| 352 | bkpinfo->backup_media_string,
|
---|
[128] | 353 | g_current_media_number);
|
---|
| 354 |
|
---|
[1200] | 355 | open_progress_form(_("Comparing files"),
|
---|
| 356 | _("Comparing tarballs against filesystem."),
|
---|
| 357 | _("Please wait. This may take some time."),
|
---|
[128] | 358 | progress_str, max_val);
|
---|
| 359 |
|
---|
| 360 | log_to_screen(progress_str);
|
---|
| 361 |
|
---|
| 362 | for (;;) {
|
---|
| 363 | insist_on_this_cd_number(bkpinfo, g_current_media_number);
|
---|
| 364 | update_progress_form(progress_str);
|
---|
[1200] | 365 | mr_asprintf(&tarball_fname,
|
---|
[128] | 366 | MNT_CDROM "/archives/%d.afio.bz2", current_tarball_number);
|
---|
| 367 |
|
---|
| 368 | if (!does_file_exist(tarball_fname)) {
|
---|
[1200] | 369 | mr_free(tarball_fname);
|
---|
| 370 | mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%d.afio.lzo",
|
---|
[128] | 371 | current_tarball_number);
|
---|
| 372 | }
|
---|
| 373 | if (!does_file_exist(tarball_fname)) {
|
---|
[1200] | 374 | mr_free(tarball_fname);
|
---|
[1633] | 375 | mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%d.afio.gz",
|
---|
| 376 | current_tarball_number);
|
---|
| 377 | }
|
---|
| 378 | if (!does_file_exist(tarball_fname)) {
|
---|
| 379 | mr_free(tarball_fname);
|
---|
[1200] | 380 | mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%d.afio.",
|
---|
[128] | 381 | current_tarball_number);
|
---|
| 382 | }
|
---|
| 383 | if (!does_file_exist(tarball_fname)) {
|
---|
[1200] | 384 | mr_free(tarball_fname);
|
---|
| 385 | mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%d.star.bz2",
|
---|
[128] | 386 | current_tarball_number);
|
---|
| 387 | }
|
---|
| 388 | if (!does_file_exist(tarball_fname)) {
|
---|
[1200] | 389 | mr_free(tarball_fname);
|
---|
| 390 | mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%d.star.",
|
---|
[128] | 391 | current_tarball_number);
|
---|
| 392 | }
|
---|
| 393 | if (!does_file_exist(tarball_fname)) {
|
---|
| 394 | if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST") ||
|
---|
| 395 | system("find " MNT_CDROM
|
---|
| 396 | "/archives/slice* > /dev/null 2> /dev/null")
|
---|
| 397 | == 0) {
|
---|
[1108] | 398 | mr_msg(2, "OK, I think I'm done with tarballs...");
|
---|
[1200] | 399 | mr_free(tarball_fname);
|
---|
[128] | 400 | break;
|
---|
| 401 | }
|
---|
[1108] | 402 | mr_msg(2, "OK, I think it's time for another CD...");
|
---|
[128] | 403 | g_current_media_number++;
|
---|
[1200] | 404 | mr_free(progress_str);
|
---|
| 405 | mr_asprintf(&progress_str, _("Comparing with %s #%d "),
|
---|
| 406 | bkpinfo->backup_media_string,
|
---|
[128] | 407 | g_current_media_number);
|
---|
| 408 | log_to_screen(progress_str);
|
---|
| 409 | } else {
|
---|
| 410 | res = compare_a_tarball(tarball_fname, current_tarball_number);
|
---|
| 411 | g_current_progress++;
|
---|
| 412 | current_tarball_number++;
|
---|
| 413 | }
|
---|
[1200] | 414 | mr_free(tarball_fname);
|
---|
[1] | 415 | }
|
---|
[1200] | 416 | mr_free(progress_str);
|
---|
[128] | 417 | close_progress_form();
|
---|
[1200] | 418 |
|
---|
[128] | 419 | if (retval) {
|
---|
[1200] | 420 | mvaddstr_and_log_it(g_currentY++, 74, _("Errors."));
|
---|
[128] | 421 | } else {
|
---|
[1200] | 422 | mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
|
---|
[1] | 423 | }
|
---|
[128] | 424 | return (retval);
|
---|
[1] | 425 | }
|
---|
[128] | 426 |
|
---|
[1] | 427 | /**************************************************************************
|
---|
| 428 | *END_COMPARE_ALL_TARBALLS *
|
---|
| 429 | **************************************************************************/
|
---|
| 430 |
|
---|
| 431 | /* @} - end LLcompareGroup */
|
---|
| 432 |
|
---|
| 433 |
|
---|
| 434 | /**
|
---|
| 435 | * @addtogroup compareGroup
|
---|
| 436 | * @{
|
---|
| 437 | */
|
---|
| 438 | /**
|
---|
| 439 | * Compare all data on a CD-R/CD-RW/DVD/ISO/NFS-based backup.
|
---|
| 440 | * @param bkpinfo The backup information structure. Passed to other functions.
|
---|
| 441 | * @return 0 for success, nonzero for failure.
|
---|
| 442 | */
|
---|
[128] | 443 | int compare_to_CD(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 444 | {
|
---|
| 445 | /** needs malloc *********/
|
---|
[1200] | 446 | char *tmp = NULL;
|
---|
| 447 | char *cwd = NULL;
|
---|
| 448 | char *new = NULL;
|
---|
| 449 | char *command = NULL;
|
---|
[128] | 450 | int resA = 0;
|
---|
| 451 | int resB = 0;
|
---|
[1200] | 452 | long noof_changed_files = 0L;
|
---|
[1] | 453 |
|
---|
[128] | 454 | malloc_string(cwd);
|
---|
| 455 | malloc_string(new);
|
---|
[1] | 456 |
|
---|
[128] | 457 | assert(bkpinfo != NULL);
|
---|
| 458 |
|
---|
| 459 | getcwd(cwd, MAX_STR_LEN - 1);
|
---|
| 460 | chdir(bkpinfo->restore_path);
|
---|
| 461 | getcwd(new, MAX_STR_LEN - 1);
|
---|
| 462 | insist_on_this_cd_number(bkpinfo, g_current_media_number);
|
---|
| 463 | unlink("/tmp/changed.txt");
|
---|
| 464 |
|
---|
| 465 | resA = compare_all_tarballs(bkpinfo);
|
---|
| 466 | resB = compare_all_biggiefiles(bkpinfo);
|
---|
| 467 | chdir(cwd);
|
---|
| 468 | noof_changed_files = count_lines_in_file("/tmp/changed.txt");
|
---|
| 469 | if (noof_changed_files) {
|
---|
[1200] | 470 | log_to_screen(_("%ld files do not match the backup "),
|
---|
[128] | 471 | noof_changed_files);
|
---|
[1200] | 472 | mr_asprintf(&command, "cat /tmp/changed.txt >> %s", MONDO_LOGFILE);
|
---|
[128] | 473 | paranoid_system(command);
|
---|
[1200] | 474 | mr_free(command);
|
---|
[128] | 475 | } else {
|
---|
[1200] | 476 | mr_asprintf(&tmp, _("All files match the backup "));
|
---|
[128] | 477 | mvaddstr_and_log_it(g_currentY++, 0, tmp);
|
---|
| 478 | log_to_screen(tmp);
|
---|
[1200] | 479 | mr_free(tmp);
|
---|
[128] | 480 | }
|
---|
| 481 |
|
---|
[1080] | 482 | mr_free(cwd);
|
---|
| 483 | mr_free(new);
|
---|
[128] | 484 |
|
---|
| 485 | return (resA + resB);
|
---|
[1] | 486 | }
|
---|
| 487 |
|
---|
| 488 | /**************************************************************************
|
---|
| 489 | *END_COMPARE_TO_CD *
|
---|
| 490 | **************************************************************************/
|
---|
| 491 |
|
---|
| 492 |
|
---|
| 493 | /**
|
---|
| 494 | * Compare all data in the user's backup.
|
---|
| 495 | * This function will mount filesystems, compare afioballs and biggiefiles,
|
---|
| 496 | * and show the user the differences.
|
---|
| 497 | * @param bkpinfo The backup information structure. Passed to other functions.
|
---|
| 498 | * @param mountlist The mountlist containing partitions to mount.
|
---|
| 499 | * @param raidlist The raidlist containing the user's RAID devices.
|
---|
| 500 | * @return The number of errors/differences found.
|
---|
| 501 | */
|
---|
| 502 | int
|
---|
[128] | 503 | compare_mode(struct s_bkpinfo *bkpinfo,
|
---|
| 504 | struct mountlist_itself *mountlist,
|
---|
| 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 |
|
---|
[128] | 524 | while (get_cfg_file_from_archive(bkpinfo)) {
|
---|
| 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 | }
|
---|
| 531 | interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
|
---|
| 532 | }
|
---|
[1] | 533 |
|
---|
[128] | 534 | read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
|
---|
| 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) {
|
---|
| 546 | retval += compare_to_tape(bkpinfo);
|
---|
| 547 | } else if (bkpinfo->backup_media_type == cdstream) {
|
---|
| 548 | retval += compare_to_cdstream(bkpinfo);
|
---|
| 549 | } else {
|
---|
| 550 | retval += compare_to_CD(bkpinfo);
|
---|
| 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 |
|
---|
[128] | 559 | if (count_lines_in_file("/tmp/changed.txt") > 0) {
|
---|
| 560 | mvaddstr_and_log_it(g_currentY++, 0,
|
---|
[1200] | 561 | _
|
---|
| 562 | ("Differences found while files were being compared."));
|
---|
[128] | 563 | streamline_changes_file("/tmp/changed.files", "/tmp/changed.txt");
|
---|
| 564 | if (count_lines_in_file("/tmp/changed.files") <= 0) {
|
---|
| 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 {
|
---|
| 571 | q = count_lines_in_file("/tmp/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);
|
---|
[128] | 588 | popup_changelist_from_file("/tmp/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 | */
|
---|
[128] | 618 | int compare_to_cdstream(struct s_bkpinfo *bkpinfo)
|
---|
[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 | }
|
---|
| 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) {
|
---|
[1108] | 648 | mr_msg(0,
|
---|
[128] | 649 | "Type 'less /tmp/changed.files' to see which files don't match the archives");
|
---|
[1108] | 650 | mr_msg(2, "Calling popup_changelist_from_file()");
|
---|
[128] | 651 | popup_changelist_from_file("/tmp/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 | **************************************************************************/
|
---|
[128] | 676 | int compare_to_tape(struct s_bkpinfo *bkpinfo)
|
---|
[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"));
|
---|
[128] | 694 | res = verify_tape_backups(bkpinfo);
|
---|
| 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 */
|
---|