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