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