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