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