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