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