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