[48] | 1 | /* $Id: libmondo-verify.c 783 2006-08-31 15:09:20Z bruno $ */
|
---|
[1] | 2 |
|
---|
| 3 | /**
|
---|
| 4 | * @file
|
---|
| 5 | * Functions for verifying backups (booted from hard drive, not CD).
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[688] | 8 | #include <unistd.h>
|
---|
| 9 |
|
---|
[1] | 10 | #include "my-stuff.h"
|
---|
| 11 | #include "mondostructures.h"
|
---|
| 12 | #include "libmondo-verify.h"
|
---|
[507] | 13 | #include "newt-specific-EXT.h"
|
---|
[1] | 14 | #include "libmondo-files-EXT.h"
|
---|
| 15 | #include "libmondo-fork-EXT.h"
|
---|
| 16 | #include "libmondo-stream-EXT.h"
|
---|
| 17 | #include "libmondo-string-EXT.h"
|
---|
| 18 | #include "libmondo-devices-EXT.h"
|
---|
| 19 | #include "libmondo-tools-EXT.h"
|
---|
| 20 |
|
---|
| 21 | /*@unused@*/
|
---|
[48] | 22 | //static char cvsid[] = "$Id: libmondo-verify.c 783 2006-08-31 15:09:20Z bruno $";
|
---|
[1] | 23 |
|
---|
[48] | 24 | char *vfy_tball_fname(struct s_bkpinfo *, char *, int);
|
---|
[1] | 25 |
|
---|
| 26 |
|
---|
| 27 | /**
|
---|
| 28 | * The number of the most recently verified afioball.
|
---|
| 29 | * @ingroup globalGroup
|
---|
| 30 | */
|
---|
| 31 | int g_last_afioball_number = -1;
|
---|
| 32 |
|
---|
| 33 |
|
---|
| 34 | /**
|
---|
| 35 | * Generate a list of the files that have changed, based on @c afio @c -r
|
---|
| 36 | * messages.
|
---|
| 37 | * @param changedfiles_fname Filename of the place to put a list of afio's reported changed.
|
---|
| 38 | * @param ignorefiles_fname Filename of a list of files to ignore (use "" if none).
|
---|
| 39 | * @param stderr_fname File containing afio's stderr output.
|
---|
| 40 | * @return The number of differences found (0 for a perfect backup).
|
---|
| 41 | * @bug This function seems orphaned.
|
---|
| 42 | * @ingroup utilityGroup
|
---|
| 43 | */
|
---|
| 44 | long
|
---|
[48] | 45 | generate_list_of_changed_files(char *changedfiles_fname,
|
---|
| 46 | char *ignorefiles_fname, char *stderr_fname)
|
---|
[1] | 47 | {
|
---|
[48] | 48 | /*@ buffer ********************************************************** */
|
---|
| 49 | char *command;
|
---|
[1] | 50 | char *afio_found_changes;
|
---|
| 51 |
|
---|
[48] | 52 | /*@ int ************************************************************* */
|
---|
| 53 | int res = 0;
|
---|
[1] | 54 |
|
---|
[48] | 55 | /*@ long ************************************************************ */
|
---|
| 56 | long afio_diffs = 0;
|
---|
[1] | 57 |
|
---|
[48] | 58 | assert_string_is_neither_NULL_nor_zerolength(changedfiles_fname);
|
---|
| 59 | assert_string_is_neither_NULL_nor_zerolength(ignorefiles_fname);
|
---|
| 60 | assert_string_is_neither_NULL_nor_zerolength(stderr_fname);
|
---|
[1] | 61 |
|
---|
[48] | 62 | asprintf(&afio_found_changes, "%s.afio", ignorefiles_fname);
|
---|
[688] | 63 | sync();
|
---|
[48] | 64 |
|
---|
[783] | 65 | /* s-printf (command,
|
---|
[274] | 66 | "grep \"afio: \" %s | awk '{j=substr($0,8); i=index(j,\": \");printf \"/%%s\\n\",substr(j,1,i-2);}' | sort -u | grep -v \"incheckentry.*xwait\" | grep -vx \"/afio:.*\" | grep -vx \"/dev/.*\" > %s",
|
---|
[1] | 67 | stderr_fname, afio_found_changes);
|
---|
| 68 | */
|
---|
| 69 |
|
---|
[48] | 70 | log_msg(1, "Now scanning log file for 'afio: ' stuff");
|
---|
| 71 | asprintf(&command,
|
---|
[274] | 72 | "grep \"afio: \" %s | sed 's/afio: //' | grep -vx \"/dev/.*\" >> %s",
|
---|
[59] | 73 | stderr_fname, afio_found_changes);
|
---|
[48] | 74 | log_msg(2, command);
|
---|
| 75 | res = system(command);
|
---|
| 76 | paranoid_free(command);
|
---|
| 77 | if (res) {
|
---|
| 78 | log_msg(2, "Warning - failed to think");
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | log_msg(1, "Now scanning log file for 'star: ' stuff");
|
---|
| 82 | asprintf(&command,
|
---|
[274] | 83 | "grep \"star: \" %s | sed 's/star: //' | grep -vx \"/dev/.*\" >> %s",
|
---|
[59] | 84 | stderr_fname, afio_found_changes);
|
---|
[48] | 85 | log_msg(2, command);
|
---|
| 86 | res = system(command);
|
---|
| 87 | paranoid_free(command);
|
---|
| 88 | if (res) {
|
---|
| 89 | log_msg(2, "Warning - failed to think");
|
---|
| 90 | }
|
---|
[1] | 91 | // exclude_nonexistent_files (afio_found_changes);
|
---|
[48] | 92 | afio_diffs = count_lines_in_file(afio_found_changes);
|
---|
| 93 | asprintf(&command,
|
---|
[274] | 94 | "sort %s %s %s | uniq -c | awk '{ if ($1==\"2\") {print $2;};}' | grep -v \"incheckentry xwait()\" > %s",
|
---|
[59] | 95 | ignorefiles_fname, afio_found_changes, afio_found_changes,
|
---|
| 96 | changedfiles_fname);
|
---|
[48] | 97 | log_msg(2, command);
|
---|
| 98 | paranoid_system(command);
|
---|
| 99 | paranoid_free(command);
|
---|
| 100 | paranoid_free(afio_found_changes);
|
---|
| 101 | return (afio_diffs);
|
---|
[1] | 102 | }
|
---|
| 103 |
|
---|
| 104 |
|
---|
| 105 | /**
|
---|
| 106 | * @addtogroup LLverifyGroup
|
---|
| 107 | * @{
|
---|
| 108 | */
|
---|
| 109 | /**
|
---|
| 110 | * Verify all afioballs stored on the inserted CD (or an ISO image).
|
---|
| 111 | * @param bkpinfo The backup information structure. @c bkpinfo->backup_media_type
|
---|
| 112 | * is used in this function, and the structure is also passed to verify_an_afioball_from_CD().
|
---|
| 113 | * @param mountpoint The location the CD/DVD/ISO is mounted on.
|
---|
| 114 | * @return The number of sets containing differences (0 for success).
|
---|
| 115 | */
|
---|
[48] | 116 | int verify_afioballs_on_CD(struct s_bkpinfo *bkpinfo, char *mountpoint)
|
---|
[1] | 117 | {
|
---|
| 118 |
|
---|
[48] | 119 | /*@ buffers ********************************************************* */
|
---|
| 120 | char *tmp;
|
---|
[1] | 121 |
|
---|
[48] | 122 | /*@ int ************************************************************* */
|
---|
| 123 | int set_number = 0;
|
---|
[1] | 124 | int retval = 0;
|
---|
| 125 | int total_sets = 0;
|
---|
| 126 | int percentage = 0;
|
---|
| 127 |
|
---|
[48] | 128 | assert_string_is_neither_NULL_nor_zerolength(mountpoint);
|
---|
| 129 | assert(bkpinfo != NULL);
|
---|
| 130 |
|
---|
| 131 | for (set_number = 0;
|
---|
| 132 | set_number < 9999
|
---|
| 133 | &&
|
---|
| 134 | !does_file_exist(vfy_tball_fname
|
---|
| 135 | (bkpinfo, mountpoint, set_number));
|
---|
| 136 | set_number++);
|
---|
| 137 | if (!does_file_exist(vfy_tball_fname(bkpinfo, mountpoint, set_number))) {
|
---|
| 138 | return (0);
|
---|
[1] | 139 | }
|
---|
[48] | 140 |
|
---|
| 141 | if (g_last_afioball_number != set_number - 1) {
|
---|
| 142 | if (set_number == 0) {
|
---|
| 143 | log_msg(1,
|
---|
| 144 | "Weird error in verify_afioballs_on_CD() but it's really a cosmetic error, nothing more");
|
---|
| 145 | } else {
|
---|
| 146 | retval++;
|
---|
| 147 | asprintf(&tmp, "Warning - missing set(s) between %d and %d\n",
|
---|
[59] | 148 | g_last_afioball_number, set_number - 1);
|
---|
[48] | 149 | log_to_screen(tmp);
|
---|
| 150 | paranoid_free(tmp);
|
---|
| 151 | }
|
---|
| 152 | }
|
---|
| 153 | asprintf(&tmp, "Verifying %s #%d's tarballs",
|
---|
[783] | 154 | bkpinfo->backup_media_string,
|
---|
[59] | 155 | g_current_media_number);
|
---|
[48] | 156 | open_evalcall_form(tmp);
|
---|
| 157 | paranoid_free(tmp);
|
---|
| 158 |
|
---|
| 159 | for (total_sets = set_number;
|
---|
| 160 | does_file_exist(vfy_tball_fname(bkpinfo, mountpoint, total_sets));
|
---|
| 161 | total_sets++) {
|
---|
| 162 | log_msg(1, "total_sets = %d", total_sets);
|
---|
| 163 | }
|
---|
| 164 | for (;
|
---|
| 165 | does_file_exist(vfy_tball_fname(bkpinfo, mountpoint, set_number));
|
---|
| 166 | set_number++) {
|
---|
| 167 | percentage =
|
---|
| 168 | (set_number - g_last_afioball_number) * 100 / (total_sets -
|
---|
| 169 | g_last_afioball_number);
|
---|
| 170 | update_evalcall_form(percentage);
|
---|
| 171 | log_msg(1, "set = %d", set_number);
|
---|
| 172 | retval +=
|
---|
| 173 | verify_an_afioball_from_CD(bkpinfo,
|
---|
| 174 | vfy_tball_fname(bkpinfo, mountpoint,
|
---|
[59] | 175 | set_number));
|
---|
[48] | 176 | }
|
---|
| 177 | g_last_afioball_number = set_number - 1;
|
---|
| 178 | close_evalcall_form();
|
---|
| 179 | return (retval);
|
---|
[1] | 180 | }
|
---|
| 181 |
|
---|
[48] | 182 |
|
---|
[1] | 183 | /**
|
---|
| 184 | * Verify all slices stored on the inserted CD (or a mounted ISO image).
|
---|
| 185 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 186 | * - @c compression_level
|
---|
| 187 | * - @c restore_path
|
---|
| 188 | * - @c use_lzo
|
---|
| 189 | * - @c zip_suffix
|
---|
| 190 | * @param mtpt The mountpoint the CD/DVD/ISO is mounted on.
|
---|
| 191 | * @return The number of differences (0 for perfect biggiefiles).
|
---|
| 192 | */
|
---|
[48] | 193 | int verify_all_slices_on_CD(struct s_bkpinfo *bkpinfo, char *mtpt)
|
---|
[1] | 194 | {
|
---|
| 195 |
|
---|
[688] | 196 | char *tmp = NULL;
|
---|
| 197 | char *tmp1 = NULL;
|
---|
| 198 | char *tmp2 = NULL;
|
---|
| 199 | char *mountpoint = NULL;
|
---|
| 200 | char *command = NULL;
|
---|
| 201 | char *sz_exe = NULL;
|
---|
[48] | 202 | static char *bufblkA = NULL;
|
---|
| 203 | static char *bufblkB = NULL;
|
---|
| 204 | const long maxbufsize = 65536L;
|
---|
[688] | 205 | long currsizA = 0L;
|
---|
| 206 | long currsizB = 0L;
|
---|
| 207 | long j = 0L;
|
---|
| 208 | long bigfile_num = 0L;
|
---|
[48] | 209 | long slice_num = -1;
|
---|
[688] | 210 | int res = 0;
|
---|
[1] | 211 |
|
---|
[48] | 212 | static FILE *forig = NULL;
|
---|
| 213 | static struct s_filename_and_lstat_info biggiestruct;
|
---|
| 214 | static long last_bigfile_num = -1;
|
---|
| 215 | static long last_slice_num = -1;
|
---|
[688] | 216 | FILE *pin = NULL;
|
---|
| 217 | FILE *fin = NULL;
|
---|
[48] | 218 | int retval = 0;
|
---|
[1] | 219 |
|
---|
[48] | 220 | if (!bufblkA) {
|
---|
| 221 | if (!(bufblkA = malloc(maxbufsize))) {
|
---|
| 222 | fatal_error("Cannot malloc bufblkA");
|
---|
| 223 | }
|
---|
| 224 | }
|
---|
| 225 | if (!bufblkB) {
|
---|
| 226 | if (!(bufblkB = malloc(maxbufsize))) {
|
---|
| 227 | fatal_error("Cannot malloc bufblkB");
|
---|
| 228 | }
|
---|
| 229 | }
|
---|
[1] | 230 |
|
---|
[48] | 231 | assert(bkpinfo != NULL);
|
---|
| 232 | assert_string_is_neither_NULL_nor_zerolength(mtpt);
|
---|
[1] | 233 |
|
---|
[48] | 234 | if (bkpinfo->compression_level > 0) {
|
---|
| 235 | if (bkpinfo->use_lzo) {
|
---|
| 236 | asprintf(&sz_exe, "lzop");
|
---|
| 237 | } else {
|
---|
| 238 | asprintf(&sz_exe, "bzip2");
|
---|
| 239 | }
|
---|
| 240 | } else {
|
---|
[171] | 241 | asprintf(&sz_exe, " ");
|
---|
[48] | 242 | }
|
---|
[1] | 243 |
|
---|
[48] | 244 | iamhere("before vsbf");
|
---|
| 245 | asprintf(&tmp, "Verifying %s#%d's big files",
|
---|
[783] | 246 | bkpinfo->backup_media_string,
|
---|
[59] | 247 | g_current_media_number);
|
---|
[48] | 248 | open_evalcall_form(tmp);
|
---|
| 249 | paranoid_free(tmp);
|
---|
[688] | 250 |
|
---|
[48] | 251 | iamhere("after vsbf");
|
---|
| 252 | asprintf(&mountpoint, "%s/archives", mtpt);
|
---|
| 253 | if (last_bigfile_num == -1) {
|
---|
| 254 | bigfile_num = 0;
|
---|
| 255 | slice_num = 0;
|
---|
| 256 | } else if (slice_num == 0) {
|
---|
| 257 | bigfile_num = last_bigfile_num + 1;
|
---|
| 258 | slice_num = 0;
|
---|
| 259 | } else {
|
---|
| 260 | bigfile_num = last_bigfile_num;
|
---|
| 261 | slice_num = last_slice_num + 1;
|
---|
| 262 | }
|
---|
[688] | 263 |
|
---|
| 264 | tmp = slice_fname(bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix);
|
---|
| 265 | tmp1 = slice_fname(bigfile_num, slice_num, mountpoint, "");
|
---|
| 266 | while (does_file_exist(tmp) || does_file_exist(tmp1)) {
|
---|
| 267 | // handle slices until end of CD
|
---|
[48] | 268 | if (slice_num == 0) {
|
---|
| 269 | log_msg(2, "ISO=%d bigfile=%ld --START--",
|
---|
| 270 | g_current_media_number, bigfile_num);
|
---|
[688] | 271 | if (!(fin = fopen(tmp1,"r"))) {
|
---|
[48] | 272 | log_msg(2, "Cannot open bigfile's info file");
|
---|
| 273 | } else {
|
---|
| 274 | if (fread
|
---|
| 275 | ((void *) &biggiestruct, 1, sizeof(biggiestruct),
|
---|
| 276 | fin) < sizeof(biggiestruct)) {
|
---|
| 277 | log_msg(2, "Unable to get biggiestruct");
|
---|
| 278 | }
|
---|
| 279 | paranoid_fclose(fin);
|
---|
| 280 | }
|
---|
[688] | 281 | asprintf(&tmp2, "%s/%s", bkpinfo->restore_path,
|
---|
[59] | 282 | biggiestruct.filename);
|
---|
[688] | 283 | log_msg(2, "Opening biggiefile #%ld - '%s'", bigfile_num, tmp2);
|
---|
| 284 | if (!(forig = fopen(tmp2, "r"))) {
|
---|
[48] | 285 | log_msg(2, "Failed to open bigfile. Darn.");
|
---|
| 286 | retval++;
|
---|
| 287 | }
|
---|
[688] | 288 | paranoid_free(tmp2);
|
---|
[48] | 289 |
|
---|
| 290 | slice_num++;
|
---|
[688] | 291 | } else if (does_file_exist(tmp1)) {
|
---|
[48] | 292 | log_msg(2, "ISO=%d bigfile=%ld ---END---",
|
---|
| 293 | g_current_media_number, bigfile_num);
|
---|
| 294 | bigfile_num++;
|
---|
| 295 | paranoid_fclose(forig);
|
---|
| 296 | slice_num = 0;
|
---|
| 297 | } else {
|
---|
| 298 | log_msg(2, "ISO=%d bigfile=%ld slice=%ld \r",
|
---|
| 299 | g_current_media_number, bigfile_num, slice_num);
|
---|
| 300 | if (bkpinfo->compression_level > 0) {
|
---|
[688] | 301 | asprintf(&command, "%s -dc %s 2>> %s", sz_exe, tmp, MONDO_LOGFILE);
|
---|
[48] | 302 | } else {
|
---|
[688] | 303 | asprintf(&command, "cat %s", tmp);
|
---|
[48] | 304 | }
|
---|
| 305 | if ((pin = popen(command, "r"))) {
|
---|
| 306 | res = 0;
|
---|
| 307 | while (!feof(pin)) {
|
---|
| 308 | currsizA = fread(bufblkA, 1, maxbufsize, pin);
|
---|
| 309 | if (currsizA <= 0) {
|
---|
| 310 | break;
|
---|
| 311 | }
|
---|
| 312 | currsizB = fread(bufblkB, 1, currsizA, forig);
|
---|
| 313 | if (currsizA != currsizB) {
|
---|
| 314 | res++;
|
---|
| 315 | } else {
|
---|
| 316 | for (j = 0;
|
---|
| 317 | j < currsizA && bufblkA[j] == bufblkB[j];
|
---|
| 318 | j++);
|
---|
| 319 | if (j < currsizA) {
|
---|
| 320 | res++;
|
---|
| 321 | }
|
---|
| 322 | }
|
---|
| 323 | }
|
---|
| 324 | paranoid_pclose(pin);
|
---|
| 325 | if (res && !strncmp(biggiestruct.filename, " /dev/", 5)) {
|
---|
| 326 | log_msg(3,
|
---|
[300] | 327 | "Ignoring differences between %s and live filesystem because it's a device and therefore the archives are stored via ntfsclone, not dd.",
|
---|
[48] | 328 | biggiestruct.filename);
|
---|
| 329 | log_msg(3,
|
---|
| 330 | "If you really want verification for %s, please contact the devteam and offer an incentive.",
|
---|
| 331 | biggiestruct.filename);
|
---|
| 332 | res = 0;
|
---|
| 333 | }
|
---|
| 334 | if (res) {
|
---|
| 335 | log_msg(0,
|
---|
| 336 | "afio: \"%s\": Corrupt biggie file, says libmondo-archive.c",
|
---|
| 337 | biggiestruct.filename);
|
---|
| 338 | retval++;
|
---|
| 339 | }
|
---|
| 340 | }
|
---|
| 341 | paranoid_free(command);
|
---|
| 342 | slice_num++;
|
---|
| 343 | }
|
---|
[1] | 344 | }
|
---|
[688] | 345 | paranoid_free(tmp);
|
---|
| 346 | paranoid_free(tmp1);
|
---|
[48] | 347 | paranoid_free(mountpoint);
|
---|
| 348 | paranoid_free(sz_exe);
|
---|
| 349 |
|
---|
| 350 | last_bigfile_num = bigfile_num;
|
---|
| 351 | last_slice_num = slice_num - 1;
|
---|
| 352 | if (last_slice_num < 0) {
|
---|
| 353 | last_bigfile_num--;
|
---|
[1] | 354 | }
|
---|
[48] | 355 | close_evalcall_form();
|
---|
| 356 | if (bufblkA) {
|
---|
| 357 | paranoid_free(bufblkA);
|
---|
[1] | 358 | }
|
---|
[48] | 359 | if (bufblkB) {
|
---|
| 360 | paranoid_free(bufblkB);
|
---|
| 361 | }
|
---|
| 362 | return (0);
|
---|
[1] | 363 | }
|
---|
| 364 |
|
---|
| 365 |
|
---|
| 366 | /**
|
---|
| 367 | * Verify one afioball from the CD.
|
---|
| 368 | * You should be changed to the root directory (/) for this to work.
|
---|
| 369 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 370 | * - @c bkpinfo->use_lzo
|
---|
| 371 | * - @c bkpinfo->tmpdir
|
---|
| 372 | * - @c bkpinfo->zip_exe
|
---|
| 373 | * - @c bkpinfo->zip_suffix
|
---|
| 374 | * @param tarball_fname The filename of the afioball to verify.
|
---|
| 375 | * @return 0, always.
|
---|
| 376 | */
|
---|
[48] | 377 | int verify_a_tarball(struct s_bkpinfo *bkpinfo, char *tarball_fname)
|
---|
[1] | 378 | {
|
---|
[48] | 379 | /*@ buffers ********************************************************* */
|
---|
| 380 | char *command;
|
---|
[1] | 381 | char *outlog;
|
---|
[48] | 382 | char *tmp = NULL;
|
---|
| 383 | // char *p;
|
---|
[1] | 384 |
|
---|
[48] | 385 | /*@ pointers ******************************************************* */
|
---|
| 386 | FILE *pin;
|
---|
[1] | 387 |
|
---|
[49] | 388 | size_t n = 0;
|
---|
[1] | 389 |
|
---|
[48] | 390 | /*@ long *********************************************************** */
|
---|
| 391 | long diffs = 0;
|
---|
[1] | 392 |
|
---|
[48] | 393 | assert(bkpinfo != NULL);
|
---|
| 394 | assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
|
---|
[1] | 395 |
|
---|
[48] | 396 | log_it("Verifying fileset '%s'", tarball_fname);
|
---|
[1] | 397 |
|
---|
[48] | 398 | /* chdir("/"); */
|
---|
| 399 | asprintf(&outlog, "%s/afio.log", bkpinfo->tmpdir);
|
---|
[1] | 400 |
|
---|
[48] | 401 | /* if programmer forgot to say which compression thingy to use then find out */
|
---|
| 402 | if (strstr(tarball_fname, ".lzo")
|
---|
| 403 | && strcmp(bkpinfo->zip_suffix, "lzo")) {
|
---|
| 404 | log_msg(2, "OK, I'm going to start using lzop.");
|
---|
[783] | 405 | paranoid_alloc(bkpinfo->zip_exe, "lzop");
|
---|
| 406 | paranoid_alloc(bkpinfo->zip_suffix, "lzo");
|
---|
[48] | 407 | bkpinfo->use_lzo = TRUE;
|
---|
| 408 | }
|
---|
| 409 | if (strstr(tarball_fname, ".bz2")
|
---|
| 410 | && strcmp(bkpinfo->zip_suffix, "bz2")) {
|
---|
| 411 | log_msg(2, "OK, I'm going to start using bzip2.");
|
---|
[783] | 412 | paranoid_alloc(bkpinfo->zip_exe, "bzip2");
|
---|
| 413 | paranoid_alloc(bkpinfo->zip_suffix, "bz2");
|
---|
[48] | 414 | bkpinfo->use_lzo = FALSE;
|
---|
| 415 | }
|
---|
| 416 | unlink(outlog);
|
---|
| 417 | if (strstr(tarball_fname, ".star")) {
|
---|
| 418 | bkpinfo->use_star = TRUE;
|
---|
| 419 | if (strstr(tarball_fname, ".bz2"))
|
---|
| 420 | asprintf(&command,
|
---|
[59] | 421 | "star -diff diffopts=mode,size,data file=%s %s >> %s 2>> %s",
|
---|
| 422 | tarball_fname,
|
---|
| 423 | (strstr(tarball_fname, ".bz2")) ? "-bz" : " ", outlog,
|
---|
| 424 | outlog);
|
---|
[48] | 425 | } else {
|
---|
| 426 | bkpinfo->use_star = FALSE;
|
---|
| 427 | asprintf(&command, "afio -r -P %s -Z %s >> %s 2>> %s",
|
---|
[59] | 428 | bkpinfo->zip_exe, tarball_fname, outlog, outlog);
|
---|
[48] | 429 | }
|
---|
| 430 | log_msg(6, "command=%s", command);
|
---|
| 431 | paranoid_system(command);
|
---|
| 432 | paranoid_free(command);
|
---|
[1] | 433 |
|
---|
[48] | 434 | if (length_of_file(outlog) < 10) {
|
---|
| 435 | asprintf(&command, "cat %s >> %s", outlog, MONDO_LOGFILE);
|
---|
| 436 | } else {
|
---|
[274] | 437 | asprintf(&command, "cut -d':' -f%d %s | sort -u",
|
---|
| 438 | (bkpinfo->use_star) ? 1 : 2, outlog);
|
---|
[48] | 439 | pin = popen(command, "r");
|
---|
| 440 | if (pin) {
|
---|
| 441 | for (getline(&tmp, &n, pin); !feof(pin);
|
---|
[49] | 442 | getline(&tmp, &n, pin)) {
|
---|
[48] | 443 | if (bkpinfo->use_star) {
|
---|
| 444 | if (!strstr(tmp, "diffopts=")) {
|
---|
| 445 | while (strlen(tmp) > 0
|
---|
| 446 | && tmp[strlen(tmp) - 1] < 32) {
|
---|
| 447 | tmp[strlen(tmp) - 1] = '\0';
|
---|
| 448 | }
|
---|
| 449 | if (strchr(tmp, '/')) {
|
---|
| 450 | if (!diffs) {
|
---|
| 451 | log_msg(0, "'%s' - differences found",
|
---|
| 452 | tarball_fname);
|
---|
| 453 | }
|
---|
| 454 | log_msg(0, "star: /%s",
|
---|
| 455 | strip_afio_output_line(tmp));
|
---|
| 456 | diffs++;
|
---|
| 457 | }
|
---|
| 458 | }
|
---|
| 459 | } else {
|
---|
| 460 | if (!diffs) {
|
---|
| 461 | log_msg(0, "'%s' - differences found",
|
---|
| 462 | tarball_fname);
|
---|
| 463 | }
|
---|
| 464 | log_msg(0, "afio: /%s", strip_afio_output_line(tmp));
|
---|
| 465 | diffs++;
|
---|
| 466 | }
|
---|
| 467 | }
|
---|
| 468 | paranoid_pclose(pin);
|
---|
| 469 | paranoid_free(tmp);
|
---|
| 470 | } else {
|
---|
| 471 | log_OS_error(command);
|
---|
| 472 | }
|
---|
| 473 | }
|
---|
| 474 | paranoid_free(outlog);
|
---|
| 475 | paranoid_free(command);
|
---|
[1] | 476 |
|
---|
[48] | 477 | /* chdir(old_pwd); */
|
---|
[783] | 478 | // s-printf (tmp, "uniq -u %s >> %s", "/tmp/mondo-verify.err", MONDO_LOGFILE);
|
---|
[48] | 479 | // paranoid_system (tmp);
|
---|
| 480 | // unlink ("/tmp/mondo-verify.err");
|
---|
| 481 | return (0);
|
---|
| 482 | }
|
---|
[1] | 483 |
|
---|
| 484 |
|
---|
| 485 | /**
|
---|
| 486 | * Verify one afioball from the CD.
|
---|
| 487 | * Checks for existence (calls fatal_error() if it does not exist) and
|
---|
| 488 | * then calls verify_an_afioball().
|
---|
| 489 | * @param bkpinfo The backup information structure. Passed to verify_an_afioball().
|
---|
| 490 | * @param tarball_fname The filename of the afioball to verify.
|
---|
| 491 | * @return The return value of verify_an_afioball().
|
---|
| 492 | * @see verify_an_afioball
|
---|
| 493 | */
|
---|
| 494 | int
|
---|
[48] | 495 | verify_an_afioball_from_CD(struct s_bkpinfo *bkpinfo, char *tarball_fname)
|
---|
[1] | 496 | {
|
---|
| 497 |
|
---|
[48] | 498 | /*@ int ************************************************************* */
|
---|
| 499 | int res = 0;
|
---|
[1] | 500 |
|
---|
[48] | 501 | assert(bkpinfo != NULL);
|
---|
| 502 | assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
|
---|
[1] | 503 |
|
---|
[48] | 504 | log_msg(1, "Verifying %s", tarball_fname);
|
---|
| 505 | if (!does_file_exist(tarball_fname)) {
|
---|
| 506 | fatal_error("Cannot verify nonexistent afioball");
|
---|
| 507 | }
|
---|
| 508 | res = verify_a_tarball(bkpinfo, tarball_fname);
|
---|
| 509 | return (res);
|
---|
[1] | 510 | }
|
---|
| 511 |
|
---|
| 512 |
|
---|
| 513 | /**
|
---|
| 514 | * Verify one afioball from the opened tape/CD stream.
|
---|
| 515 | * Copies the file from tape to tmpdir and then calls verify_an_afioball().
|
---|
| 516 | * @param bkpinfo The backup information structure. Passed to verify_an_afioball().
|
---|
| 517 | * @param orig_fname The original filename of the afioball to verify.
|
---|
| 518 | * @param size The size of the afioball to verify.
|
---|
| 519 | * @return The return value of verify_an_afioball().
|
---|
| 520 | * @see verify_an_afioball
|
---|
| 521 | */
|
---|
| 522 | int
|
---|
[48] | 523 | verify_an_afioball_from_stream(struct s_bkpinfo *bkpinfo, char *orig_fname,
|
---|
| 524 | long long size)
|
---|
[1] | 525 | {
|
---|
| 526 |
|
---|
[48] | 527 | /*@ int ************************************************************** */
|
---|
| 528 | int retval = 0;
|
---|
[1] | 529 | int res = 0;
|
---|
| 530 |
|
---|
[48] | 531 | /*@ buffers ********************************************************** */
|
---|
| 532 | char *tmp;
|
---|
[1] | 533 | char *tarball_fname;
|
---|
| 534 |
|
---|
[48] | 535 | /*@ pointers ********************************************************* */
|
---|
| 536 | char *p;
|
---|
[1] | 537 |
|
---|
[48] | 538 | assert(bkpinfo != NULL);
|
---|
| 539 | assert_string_is_neither_NULL_nor_zerolength(orig_fname);
|
---|
[1] | 540 |
|
---|
[48] | 541 | p = strrchr(orig_fname, '/');
|
---|
| 542 | if (!p) {
|
---|
| 543 | p = orig_fname;
|
---|
| 544 | } else {
|
---|
| 545 | p++;
|
---|
| 546 | }
|
---|
| 547 | asprintf(&tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
|
---|
| 548 | paranoid_system(tmp);
|
---|
| 549 | paranoid_free(tmp);
|
---|
| 550 |
|
---|
| 551 | asprintf(&tarball_fname, "%s/tmpfs/temporary-%s", bkpinfo->tmpdir, p);
|
---|
| 552 | /* BERLIOS : useless
|
---|
[59] | 553 | asprintf(&tmp, "Temporarily copying file from tape to '%s'",
|
---|
| 554 | tarball_fname);
|
---|
| 555 | log_it(tmp);
|
---|
| 556 | paranoid_free(tmp);
|
---|
| 557 | */
|
---|
[48] | 558 | read_file_from_stream_to_file(bkpinfo, tarball_fname, size);
|
---|
| 559 | res = verify_a_tarball(bkpinfo, tarball_fname);
|
---|
| 560 | if (res) {
|
---|
| 561 | asprintf(&tmp,
|
---|
[59] | 562 | "Afioball '%s' no longer matches your live filesystem",
|
---|
| 563 | p);
|
---|
[48] | 564 | log_msg(0, tmp);
|
---|
| 565 | paranoid_free(tmp);
|
---|
| 566 | retval++;
|
---|
| 567 | }
|
---|
| 568 | unlink(tarball_fname);
|
---|
| 569 | paranoid_free(tarball_fname);
|
---|
| 570 | return (retval);
|
---|
[1] | 571 | }
|
---|
| 572 |
|
---|
| 573 |
|
---|
| 574 | /**
|
---|
| 575 | * Verify one biggiefile form the opened tape/CD stream.
|
---|
| 576 | * @param bkpinfo The backup information structure. @c bkpinfo->tmpdir is the only field used.
|
---|
| 577 | * @param biggie_fname The filename of the biggiefile to verify.
|
---|
| 578 | * @param size The size in bytes of said biggiefile.
|
---|
| 579 | * @return 0 for success (even if the file doesn't match); nonzero for a tape error.
|
---|
| 580 | */
|
---|
| 581 | int
|
---|
[48] | 582 | verify_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo,
|
---|
| 583 | char *biggie_fname, long long size)
|
---|
[1] | 584 | {
|
---|
| 585 |
|
---|
[48] | 586 | /*@ int ************************************************************* */
|
---|
| 587 | int retval = 0;
|
---|
[1] | 588 | int res = 0;
|
---|
| 589 | int current_slice_number = 0;
|
---|
| 590 | int ctrl_chr = '\0';
|
---|
| 591 |
|
---|
[48] | 592 | /*@ char ************************************************************ */
|
---|
[1] | 593 | char *test_file;
|
---|
| 594 | char *biggie_cksum;
|
---|
| 595 | char *orig_cksum;
|
---|
| 596 | char *tmp;
|
---|
[127] | 597 | char *slice_fnam = (char *) &res;
|
---|
[48] | 598 |
|
---|
| 599 | /*@ pointers ******************************************************** */
|
---|
[1] | 600 | char *p;
|
---|
| 601 |
|
---|
[48] | 602 | /*@ long long ******************************************************* */
|
---|
| 603 | long long slice_siz;
|
---|
[1] | 604 |
|
---|
[48] | 605 | assert(bkpinfo != NULL);
|
---|
| 606 | assert_string_is_neither_NULL_nor_zerolength(biggie_fname);
|
---|
[1] | 607 |
|
---|
[48] | 608 | p = strrchr(biggie_fname, '/');
|
---|
| 609 | if (!p) {
|
---|
| 610 | p = biggie_fname;
|
---|
| 611 | } else {
|
---|
| 612 | p++;
|
---|
[1] | 613 | }
|
---|
[48] | 614 | asprintf(&test_file, "%s/temporary-%s", bkpinfo->tmpdir, p);
|
---|
[122] | 615 | asprintf(&tmp,
|
---|
[127] | 616 | "Temporarily copying biggiefile %s's slices from tape to '%s'",
|
---|
| 617 | p, test_file);
|
---|
| 618 | log_it(tmp);
|
---|
[122] | 619 | paranoid_free(tmp);
|
---|
[59] | 620 | for (res =
|
---|
| 621 | read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr);
|
---|
[48] | 622 | ctrl_chr != BLK_STOP_A_BIGGIE;
|
---|
[59] | 623 | res =
|
---|
| 624 | read_header_block_from_stream(&slice_siz, slice_fnam,
|
---|
| 625 | &ctrl_chr)) {
|
---|
[48] | 626 | if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
|
---|
| 627 | wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
|
---|
| 628 | }
|
---|
| 629 | res = read_file_from_stream_to_file(bkpinfo, test_file, slice_siz);
|
---|
| 630 | unlink(test_file);
|
---|
[122] | 631 | paranoid_free(slice_fnam);
|
---|
[127] | 632 | slice_fnam = (char *) &res;
|
---|
[59] | 633 | res =
|
---|
| 634 | read_header_block_from_stream(&slice_siz, slice_fnam,
|
---|
| 635 | &ctrl_chr);
|
---|
[48] | 636 | if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
|
---|
| 637 | log_msg(2, "test_file = %s", test_file);
|
---|
| 638 | wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
|
---|
| 639 | }
|
---|
| 640 | current_slice_number++;
|
---|
| 641 | retval += res;
|
---|
[122] | 642 | paranoid_free(slice_fnam);
|
---|
[127] | 643 | slice_fnam = (char *) &res;
|
---|
[1] | 644 | }
|
---|
[48] | 645 | paranoid_free(test_file);
|
---|
| 646 |
|
---|
| 647 | asprintf(&biggie_cksum, slice_fnam);
|
---|
| 648 | paranoid_free(slice_fnam);
|
---|
| 649 |
|
---|
| 650 | if (biggie_cksum[0] != '\0') {
|
---|
[171] | 651 | orig_cksum = calc_checksum_of_file(biggie_fname);
|
---|
[48] | 652 | if (strcmp(biggie_cksum, orig_cksum)) {
|
---|
| 653 | asprintf(&tmp, "orig cksum=%s; curr cksum=%s", biggie_cksum,
|
---|
[59] | 654 | orig_cksum);
|
---|
[48] | 655 | log_msg(2, tmp);
|
---|
| 656 | paranoid_free(tmp);
|
---|
| 657 |
|
---|
[507] | 658 | asprintf(&tmp, _("%s has changed on live filesystem"),
|
---|
[59] | 659 | biggie_fname);
|
---|
[48] | 660 | log_to_screen(tmp);
|
---|
| 661 | paranoid_free(tmp);
|
---|
| 662 |
|
---|
| 663 | asprintf(&tmp, "echo \"%s\" >> /tmp/biggies.changed",
|
---|
[59] | 664 | biggie_fname);
|
---|
[48] | 665 | system(tmp);
|
---|
| 666 | paranoid_free(tmp);
|
---|
| 667 | }
|
---|
| 668 | paranoid_free(orig_cksum);
|
---|
[1] | 669 | }
|
---|
[48] | 670 | paranoid_free(biggie_cksum);
|
---|
| 671 |
|
---|
| 672 | return (retval);
|
---|
[1] | 673 | }
|
---|
| 674 |
|
---|
| 675 |
|
---|
| 676 | /**
|
---|
| 677 | * Verify all afioballs from the opened tape/CD stream.
|
---|
| 678 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 679 | * - @c bkpinfo->restore_path
|
---|
| 680 | * - @c bkpinfo->tmpdir
|
---|
| 681 | *
|
---|
| 682 | * @return 0 for success (even if there are differences); nonzero for a tape error.
|
---|
| 683 | */
|
---|
[48] | 684 | int verify_afioballs_from_stream(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 685 | {
|
---|
[48] | 686 | /*@ int ********************************************************** */
|
---|
| 687 | int retval = 0;
|
---|
[1] | 688 | int res = 0;
|
---|
| 689 | long current_afioball_number = 0;
|
---|
| 690 | int ctrl_chr = 0;
|
---|
| 691 | int total_afioballs = 0;
|
---|
| 692 |
|
---|
[48] | 693 | /*@ buffers ***************************************************** */
|
---|
| 694 | char *tmp;
|
---|
[127] | 695 | char *fname = (char *) &res; /* Should NOT be NULL */
|
---|
[48] | 696 | char *curr_xattr_list_fname;
|
---|
| 697 | char *curr_acl_list_fname;
|
---|
[1] | 698 |
|
---|
[48] | 699 | /*@ long long *************************************************** */
|
---|
| 700 | long long size = 0;
|
---|
[1] | 701 |
|
---|
[48] | 702 | assert(bkpinfo != NULL);
|
---|
[1] | 703 |
|
---|
[48] | 704 | asprintf(&curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ,
|
---|
[59] | 705 | bkpinfo->tmpdir);
|
---|
[48] | 706 | asprintf(&curr_acl_list_fname, ACL_BIGGLST_FNAME_RAW_SZ,
|
---|
[59] | 707 | bkpinfo->tmpdir);
|
---|
[507] | 708 | log_to_screen(_("Verifying regular archives on tape"));
|
---|
[48] | 709 | total_afioballs = get_last_filelist_number(bkpinfo) + 1;
|
---|
[507] | 710 | open_progress_form(_("Verifying filesystem"),
|
---|
| 711 | _("I am verifying archives against your live filesystem now."),
|
---|
| 712 | _("Please wait. This may take a couple of hours."), "",
|
---|
[48] | 713 | total_afioballs);
|
---|
[122] | 714 | res = read_header_block_from_stream(&size, NULL, &ctrl_chr);
|
---|
[48] | 715 | if (ctrl_chr != BLK_START_AFIOBALLS) {
|
---|
| 716 | iamhere("YOU SHOULD NOT GET HERE");
|
---|
| 717 | iamhere("Grabbing the EXAT files");
|
---|
| 718 | if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
|
---|
| 719 | res =
|
---|
[122] | 720 | read_EXAT_files_from_tape(bkpinfo, &size, NULL, &ctrl_chr,
|
---|
[48] | 721 | curr_xattr_list_fname,
|
---|
| 722 | curr_acl_list_fname);
|
---|
| 723 | }
|
---|
[1] | 724 | }
|
---|
[48] | 725 | if (ctrl_chr != BLK_START_AFIOBALLS) {
|
---|
| 726 | wrong_marker(BLK_START_AFIOBALLS, ctrl_chr);
|
---|
[1] | 727 | }
|
---|
[48] | 728 | paranoid_free(curr_xattr_list_fname);
|
---|
| 729 | paranoid_free(curr_acl_list_fname);
|
---|
| 730 |
|
---|
| 731 | for (res = read_header_block_from_stream(&size, fname, &ctrl_chr);
|
---|
| 732 | ctrl_chr != BLK_STOP_AFIOBALLS;
|
---|
[127] | 733 | res = read_header_block_from_stream(&size, fname, &ctrl_chr)) {
|
---|
[48] | 734 | asprintf(&curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
|
---|
[59] | 735 | bkpinfo->tmpdir, current_afioball_number);
|
---|
[48] | 736 | asprintf(&curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
|
---|
[59] | 737 | bkpinfo->tmpdir, current_afioball_number);
|
---|
[48] | 738 | if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
|
---|
| 739 | iamhere("Reading EXAT files from tape");
|
---|
[122] | 740 | paranoid_free(fname);
|
---|
[127] | 741 | fname = (char *) &res;
|
---|
[48] | 742 | res =
|
---|
| 743 | read_EXAT_files_from_tape(bkpinfo, &size, fname, &ctrl_chr,
|
---|
| 744 | curr_xattr_list_fname,
|
---|
| 745 | curr_acl_list_fname);
|
---|
| 746 | }
|
---|
| 747 | paranoid_free(curr_xattr_list_fname);
|
---|
| 748 | paranoid_free(curr_acl_list_fname);
|
---|
| 749 |
|
---|
| 750 | if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
|
---|
| 751 | wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
|
---|
| 752 | }
|
---|
| 753 | asprintf(&tmp, "Verifying fileset #%ld", current_afioball_number);
|
---|
| 754 | /*log_it(tmp); */
|
---|
| 755 | update_progress_form(tmp);
|
---|
| 756 | paranoid_free(tmp);
|
---|
| 757 |
|
---|
| 758 | res = verify_an_afioball_from_stream(bkpinfo, fname, size);
|
---|
| 759 | if (res) {
|
---|
[507] | 760 | asprintf(&tmp, _("Afioball %ld differs from live filesystem"),
|
---|
[59] | 761 | current_afioball_number);
|
---|
[48] | 762 | log_to_screen(tmp);
|
---|
| 763 | paranoid_free(tmp);
|
---|
| 764 | }
|
---|
| 765 | retval += res;
|
---|
| 766 | current_afioball_number++;
|
---|
| 767 | g_current_progress++;
|
---|
[122] | 768 | paranoid_free(fname);
|
---|
[127] | 769 | fname = (char *) &res;
|
---|
[48] | 770 | res = read_header_block_from_stream(&size, fname, &ctrl_chr);
|
---|
| 771 | if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
|
---|
| 772 | wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
|
---|
| 773 | }
|
---|
[122] | 774 | paranoid_free(fname);
|
---|
[127] | 775 | fname = (char *) &res;
|
---|
[1] | 776 | }
|
---|
[48] | 777 | log_msg(1, "All done with afioballs");
|
---|
| 778 | close_progress_form();
|
---|
| 779 | paranoid_free(fname);
|
---|
| 780 | return (retval);
|
---|
[1] | 781 | }
|
---|
| 782 |
|
---|
[48] | 783 |
|
---|
[1] | 784 | /**
|
---|
| 785 | * Verify all biggiefiles on the opened CD/tape stream.
|
---|
| 786 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 787 | * - @c bkpinfo->restore_path
|
---|
| 788 | * - @c bkpinfo->tmpdir
|
---|
| 789 | *
|
---|
| 790 | * @return 0 for success (even if there are differences); nonzero for a tape error.
|
---|
| 791 | */
|
---|
[48] | 792 | int verify_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 793 | {
|
---|
| 794 |
|
---|
[48] | 795 | /*@ int ************************************************************ */
|
---|
| 796 | int retval = 0;
|
---|
[1] | 797 | int res = 0;
|
---|
| 798 | int ctrl_chr = 0;
|
---|
| 799 |
|
---|
[48] | 800 | /*@ long *********************************************************** */
|
---|
| 801 | long noof_biggiefiles = 0;
|
---|
[1] | 802 | long current_biggiefile_number = 0;
|
---|
| 803 |
|
---|
[48] | 804 | /*@ buffers ******************************************************** */
|
---|
[127] | 805 | char *orig_fname = (char *) &ctrl_chr; /* Should NOT be NULL */
|
---|
[122] | 806 | char *logical_fname;
|
---|
[1] | 807 | char *comment;
|
---|
| 808 | char *curr_xattr_list_fname;
|
---|
| 809 | char *curr_acl_list_fname;
|
---|
[48] | 810 | /*@ pointers ******************************************************* */
|
---|
[1] | 811 | char *p;
|
---|
| 812 |
|
---|
[48] | 813 | /*@ long long size ************************************************* */
|
---|
| 814 | long long size = 0;
|
---|
[1] | 815 |
|
---|
[48] | 816 | assert(bkpinfo != NULL);
|
---|
[1] | 817 |
|
---|
[48] | 818 | asprintf(&curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ,
|
---|
[59] | 819 | bkpinfo->tmpdir);
|
---|
[48] | 820 | asprintf(&curr_acl_list_fname, ACL_BIGGLST_FNAME_RAW_SZ,
|
---|
[59] | 821 | bkpinfo->tmpdir);
|
---|
[48] | 822 | asprintf(&comment, "Verifying all bigfiles.");
|
---|
| 823 | log_to_screen(comment);
|
---|
| 824 | res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr);
|
---|
| 825 | if (ctrl_chr != BLK_START_BIGGIEFILES) {
|
---|
| 826 | if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
|
---|
| 827 | iamhere("Grabbing the EXAT biggiefiles");
|
---|
[122] | 828 | paranoid_free(orig_fname);
|
---|
[127] | 829 | orig_fname = (char *) &ctrl_chr;
|
---|
[48] | 830 | res =
|
---|
| 831 | read_EXAT_files_from_tape(bkpinfo, &size, orig_fname,
|
---|
| 832 | &ctrl_chr, curr_xattr_list_fname,
|
---|
| 833 | curr_acl_list_fname);
|
---|
| 834 | }
|
---|
[1] | 835 | }
|
---|
[48] | 836 | paranoid_free(curr_xattr_list_fname);
|
---|
| 837 | paranoid_free(curr_acl_list_fname);
|
---|
[122] | 838 | paranoid_free(orig_fname);
|
---|
[127] | 839 | orig_fname = (char *) &ctrl_chr;
|
---|
[48] | 840 |
|
---|
| 841 | if (ctrl_chr != BLK_START_BIGGIEFILES) {
|
---|
| 842 | wrong_marker(BLK_START_BIGGIEFILES, ctrl_chr);
|
---|
[1] | 843 | }
|
---|
[48] | 844 | noof_biggiefiles = (long) size;
|
---|
| 845 | log_msg(1, "noof_biggiefiles = %ld", noof_biggiefiles);
|
---|
[507] | 846 | open_progress_form(_("Verifying big files"), comment,
|
---|
| 847 | _("Please wait. This may take some time."), "",
|
---|
[48] | 848 | noof_biggiefiles);
|
---|
| 849 | paranoid_free(comment);
|
---|
| 850 |
|
---|
| 851 | for (res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr);
|
---|
| 852 | ctrl_chr != BLK_STOP_BIGGIEFILES;
|
---|
| 853 | res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr))
|
---|
[1] | 854 | {
|
---|
[48] | 855 | if (ctrl_chr != BLK_START_A_NORMBIGGIE
|
---|
| 856 | && ctrl_chr != BLK_START_A_PIHBIGGIE) {
|
---|
| 857 | wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr);
|
---|
| 858 | }
|
---|
| 859 | p = strrchr(orig_fname, '/');
|
---|
| 860 | if (!p) {
|
---|
| 861 | p = orig_fname;
|
---|
| 862 | } else {
|
---|
| 863 | p++;
|
---|
| 864 | }
|
---|
[507] | 865 | asprintf(&comment, _("Verifying bigfile #%ld (%ld K)"),
|
---|
[59] | 866 | current_biggiefile_number, (long) size >> 10);
|
---|
[48] | 867 | update_progress_form(comment);
|
---|
| 868 | paranoid_free(comment);
|
---|
| 869 |
|
---|
[59] | 870 | asprintf(&logical_fname, "%s/%s", bkpinfo->restore_path,
|
---|
| 871 | orig_fname);
|
---|
| 872 | res =
|
---|
| 873 | verify_a_biggiefile_from_stream(bkpinfo, logical_fname, size);
|
---|
[48] | 874 | paranoid_free(logical_fname);
|
---|
| 875 | retval += res;
|
---|
| 876 | current_biggiefile_number++;
|
---|
| 877 | g_current_progress++;
|
---|
[122] | 878 | paranoid_free(orig_fname);
|
---|
[127] | 879 | orig_fname = (char *) &ctrl_chr;
|
---|
[1] | 880 | }
|
---|
[48] | 881 | close_progress_form();
|
---|
| 882 | return (retval);
|
---|
[1] | 883 | }
|
---|
| 884 |
|
---|
| 885 | /* @} - end of LLverifyGroup */
|
---|
| 886 |
|
---|
| 887 |
|
---|
| 888 | /**
|
---|
| 889 | * Verify the CD indicated by @c g_current_media_number.
|
---|
| 890 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 891 | * - @c bkpinfo->isodir
|
---|
[20] | 892 | * - @c bkpinfo->prefix
|
---|
[1] | 893 | * - @c bkpinfo->manual_cd_tray
|
---|
| 894 | * - @c bkpinfo->media_device
|
---|
| 895 | * - @c bkpinfo->nfs_remote_dir
|
---|
| 896 | * - @c bkpinfo->tmpdir
|
---|
| 897 | * - @c bkpinfo->verify_data
|
---|
| 898 | *
|
---|
| 899 | * @return 0 for success (even if differences are found), nonzero for failure.
|
---|
| 900 | * @ingroup verifyGroup
|
---|
| 901 | */
|
---|
[48] | 902 | int verify_cd_image(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 903 | {
|
---|
| 904 |
|
---|
[48] | 905 | /*@ int ************************************************************ */
|
---|
| 906 | int retval = 0;
|
---|
[1] | 907 |
|
---|
[48] | 908 | /*@ buffers ******************************************************** */
|
---|
| 909 | char *mountpoint;
|
---|
[1] | 910 | char *command;
|
---|
| 911 | char *tmp;
|
---|
| 912 | char *fname;
|
---|
| 913 | #ifdef __FreeBSD__
|
---|
[48] | 914 | char mdd[32];
|
---|
[1] | 915 | char *mddevice = mdd;
|
---|
[48] | 916 | int ret = 0;
|
---|
| 917 | int vndev = 2;
|
---|
[1] | 918 | #else
|
---|
| 919 | //skip
|
---|
| 920 | #endif
|
---|
| 921 |
|
---|
[48] | 922 | assert(bkpinfo != NULL);
|
---|
[1] | 923 |
|
---|
[48] | 924 | asprintf(&mountpoint, "%s/cdrom", bkpinfo->tmpdir);
|
---|
[485] | 925 | asprintf(&fname, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->nfs_remote_dir,
|
---|
| 926 | bkpinfo->prefix, g_current_media_number);
|
---|
[1] | 927 |
|
---|
[48] | 928 | mkdir(mountpoint, 1777);
|
---|
| 929 | sync();
|
---|
| 930 | if (!does_file_exist(fname)) {
|
---|
| 931 | asprintf(&tmp,
|
---|
[59] | 932 | "%s not found; assuming you backed up to CD; verifying CD...",
|
---|
| 933 | fname);
|
---|
[48] | 934 | log_msg(2, tmp);
|
---|
| 935 | paranoid_free(tmp);
|
---|
| 936 |
|
---|
| 937 | if (bkpinfo->manual_cd_tray) {
|
---|
[507] | 938 | popup_and_OK(_("Please push CD tray closed."));
|
---|
[48] | 939 | }
|
---|
| 940 | if (find_and_mount_actual_cd(bkpinfo, mountpoint)) {
|
---|
[507] | 941 | log_to_screen(_("failed to mount actual CD"));
|
---|
[48] | 942 | return (1);
|
---|
| 943 | }
|
---|
| 944 | } else {
|
---|
| 945 | asprintf(&tmp, "%s found; verifying ISO...", fname);
|
---|
| 946 | log_to_screen(tmp);
|
---|
| 947 | paranoid_free(tmp);
|
---|
[1] | 948 | #ifdef __FreeBSD__
|
---|
[48] | 949 | ret = 0;
|
---|
| 950 | vndev = 2;
|
---|
| 951 | mddevice = make_vn(fname);
|
---|
| 952 | if (ret) {
|
---|
[507] | 953 | asprintf(&tmp, _("make_vn of %s failed; unable to verify ISO\n"),
|
---|
[59] | 954 | fname);
|
---|
[48] | 955 | log_to_screen(tmp);
|
---|
| 956 | paranoid_free(tmp);
|
---|
| 957 | return (1);
|
---|
| 958 | }
|
---|
| 959 | asprintf(&command, "mount_cd9660 %s %s", mddevice, mountpoint);
|
---|
[1] | 960 | #else
|
---|
[48] | 961 | asprintf(&command, "mount -o loop,ro -t iso9660 %s %s", fname,
|
---|
[59] | 962 | mountpoint);
|
---|
[1] | 963 | #endif
|
---|
[48] | 964 | if (run_program_and_log_output(command, FALSE)) {
|
---|
[507] | 965 | asprintf(&tmp, _("%s failed; unable to mount ISO image\n"),
|
---|
[59] | 966 | command);
|
---|
[48] | 967 | log_to_screen(tmp);
|
---|
| 968 | paranoid_free(tmp);
|
---|
| 969 | return (1);
|
---|
| 970 | }
|
---|
| 971 | paranoid_free(command);
|
---|
[1] | 972 | }
|
---|
[48] | 973 | log_msg(2, "OK, I've mounted the ISO/CD\n");
|
---|
| 974 | asprintf(&tmp, "%s/archives/NOT-THE-LAST", mountpoint);
|
---|
| 975 | if (!does_file_exist(tmp)) {
|
---|
| 976 | log_msg
|
---|
| 977 | (2,
|
---|
| 978 | "This is the last CD. I am therefore setting bkpinfo->verify_data to FALSE.");
|
---|
| 979 | bkpinfo->verify_data = FALSE;
|
---|
[1] | 980 | /*
|
---|
| 981 | (a) It's an easy way to tell the calling subroutine that we've finished &
|
---|
| 982 | there are no more CD's to be verified; (b) It stops the post-backup verifier
|
---|
| 983 | from running after the per-CD verifier has run too.
|
---|
| 984 | */
|
---|
[48] | 985 | }
|
---|
| 986 | paranoid_free(tmp);
|
---|
[1] | 987 |
|
---|
[48] | 988 | verify_afioballs_on_CD(bkpinfo, mountpoint);
|
---|
| 989 | iamhere("before verify_all_slices");
|
---|
| 990 | verify_all_slices_on_CD(bkpinfo, mountpoint);
|
---|
| 991 |
|
---|
[1] | 992 | #ifdef __FreeBSD__
|
---|
[48] | 993 | ret = 0;
|
---|
| 994 | asprintf(&command, "umount %s", mountpoint);
|
---|
| 995 | ret += system(command);
|
---|
| 996 |
|
---|
| 997 | ret += kick_vn(mddevice);
|
---|
| 998 | if (ret)
|
---|
[1] | 999 | #else
|
---|
[48] | 1000 | asprintf(&command, "umount %s", mountpoint);
|
---|
| 1001 |
|
---|
| 1002 | if (system(command))
|
---|
[1] | 1003 | #endif
|
---|
| 1004 | {
|
---|
[59] | 1005 | asprintf(&tmp, "%s failed; unable to unmount ISO image\n",
|
---|
| 1006 | command);
|
---|
[48] | 1007 | log_to_screen(tmp);
|
---|
| 1008 | paranoid_free(tmp);
|
---|
| 1009 | retval++;
|
---|
| 1010 | } else {
|
---|
| 1011 | log_msg(2, "OK, I've unmounted the ISO file\n");
|
---|
[1] | 1012 | }
|
---|
[48] | 1013 | paranoid_free(command);
|
---|
| 1014 | paranoid_free(mountpoint);
|
---|
| 1015 |
|
---|
| 1016 | if (!does_file_exist(fname)) {
|
---|
| 1017 | asprintf(&command, "umount %s", bkpinfo->media_device);
|
---|
| 1018 | run_program_and_log_output(command, 2);
|
---|
| 1019 | paranoid_free(command);
|
---|
| 1020 |
|
---|
| 1021 | if (!bkpinfo->please_dont_eject
|
---|
| 1022 | && eject_device(bkpinfo->media_device)) {
|
---|
| 1023 | log_msg(2, "Failed to eject CD-ROM drive");
|
---|
| 1024 | }
|
---|
| 1025 | }
|
---|
| 1026 | paranoid_free(fname);
|
---|
| 1027 | return (retval);
|
---|
[1] | 1028 | }
|
---|
| 1029 |
|
---|
[48] | 1030 |
|
---|
[1] | 1031 | /**
|
---|
| 1032 | * Verify all backups on tape.
|
---|
| 1033 | * This should be done after the backup process has already closed the tape.
|
---|
| 1034 | * @param bkpinfo The backup information structure. Passed to various helper functions.
|
---|
| 1035 | * @return 0 for success (even if thee were differences), nonzero for failure.
|
---|
| 1036 | * @ingroup verifyGroup
|
---|
| 1037 | */
|
---|
[48] | 1038 | int verify_tape_backups(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 1039 | {
|
---|
| 1040 |
|
---|
[48] | 1041 | /*@ int ************************************************************ */
|
---|
| 1042 | int retval = 0;
|
---|
[1] | 1043 |
|
---|
[48] | 1044 | /*@ buffers ******************************************************** */
|
---|
| 1045 | char *tmp;
|
---|
| 1046 | char *changed_files_fname;
|
---|
[1] | 1047 |
|
---|
[48] | 1048 | /*@ long *********************************************************** */
|
---|
| 1049 | long diffs = 0;
|
---|
[1] | 1050 |
|
---|
[48] | 1051 | assert(bkpinfo != NULL);
|
---|
[1] | 1052 |
|
---|
[48] | 1053 | log_msg(3, "verify_tape_backups --- starting");
|
---|
[507] | 1054 | log_to_screen(_("Verifying backups"));
|
---|
[48] | 1055 | openin_tape(bkpinfo);
|
---|
[1] | 1056 |
|
---|
[48] | 1057 | /* verify archives themselves */
|
---|
| 1058 | retval += verify_afioballs_from_stream(bkpinfo);
|
---|
| 1059 | retval += verify_biggiefiles_from_stream(bkpinfo);
|
---|
| 1060 |
|
---|
| 1061 | /* find the final blocks */
|
---|
[688] | 1062 | sync();
|
---|
[48] | 1063 | sleep(2);
|
---|
| 1064 | closein_tape(bkpinfo);
|
---|
| 1065 |
|
---|
| 1066 | /* close tape; exit */
|
---|
| 1067 | // fclose(g_tape_stream); <-- not needed; is handled by closein_tape()
|
---|
| 1068 | paranoid_system
|
---|
| 1069 | ("rm -f /tmp/biggies.changed /tmp/changed.files.[0-9]* 2> /dev/null");
|
---|
| 1070 | asprintf(&changed_files_fname, "/tmp/changed.files.%d",
|
---|
[59] | 1071 | (int) (random() % 32767));
|
---|
[48] | 1072 | asprintf(&tmp,
|
---|
[274] | 1073 | "grep -x \"%s:.*\" %s | cut -d'\"' -f2 | sort -u | awk '{print \"/\"$0;};' | tr -s '/' '/' | grep -v \"(total of\" | grep -v \"incheckentry.*xwait\" | grep -vx \"/afio:.*\" | grep -vx \"dev/.*\" > %s",
|
---|
| 1074 | (bkpinfo->use_star) ? "star" : "afio", MONDO_LOGFILE,
|
---|
[59] | 1075 | changed_files_fname);
|
---|
[48] | 1076 | log_msg(2, "Running command to derive list of changed files");
|
---|
| 1077 | log_msg(2, tmp);
|
---|
| 1078 | if (system(tmp)) {
|
---|
| 1079 | if (does_file_exist(changed_files_fname)
|
---|
| 1080 | && length_of_file(changed_files_fname) > 2) {
|
---|
| 1081 | log_to_screen
|
---|
[507] | 1082 | (_("Warning - unable to check logfile to derive list of changed files"));
|
---|
[48] | 1083 | } else {
|
---|
| 1084 | log_to_screen
|
---|
[507] | 1085 | (_("No differences found. Therefore, no 'changed.files' text file."));
|
---|
[48] | 1086 | }
|
---|
| 1087 | }
|
---|
| 1088 | paranoid_free(tmp);
|
---|
| 1089 |
|
---|
| 1090 | asprintf(&tmp, "cat /tmp/biggies.changed >> %s", changed_files_fname);
|
---|
| 1091 | paranoid_system(tmp);
|
---|
| 1092 | paranoid_free(tmp);
|
---|
| 1093 |
|
---|
| 1094 | diffs = count_lines_in_file(changed_files_fname);
|
---|
| 1095 | if (diffs > 0) {
|
---|
| 1096 | asprintf(&tmp, "cp -f %s %s", changed_files_fname,
|
---|
[59] | 1097 | "/tmp/changed.files");
|
---|
[48] | 1098 | run_program_and_log_output(tmp, FALSE);
|
---|
| 1099 | paranoid_free(tmp);
|
---|
| 1100 |
|
---|
| 1101 | asprintf(&tmp,
|
---|
[59] | 1102 | "%ld files differed from live filesystem; type less %s or less %s to see",
|
---|
| 1103 | diffs, changed_files_fname, "/tmp/changed.files");
|
---|
[48] | 1104 | log_msg(0, tmp);
|
---|
| 1105 | paranoid_free(tmp);
|
---|
| 1106 |
|
---|
| 1107 | log_to_screen
|
---|
[507] | 1108 | (_("See /tmp/changed.files for a list of nonmatching files."));
|
---|
[48] | 1109 | log_to_screen
|
---|
[507] | 1110 | (_("The files probably changed on filesystem, not on backup media."));
|
---|
[48] | 1111 | // retval++;
|
---|
| 1112 | }
|
---|
| 1113 | paranoid_free(changed_files_fname);
|
---|
| 1114 | return (retval);
|
---|
[1] | 1115 | }
|
---|
| 1116 |
|
---|
| 1117 |
|
---|
| 1118 | /**
|
---|
| 1119 | * Generate the filename of a tarball to verify.
|
---|
| 1120 | * @param bkpinfo The backup information structure. @c bkpinfo->zip_suffix is the only field used.
|
---|
| 1121 | * @param mountpoint The directory where the CD/DVD/ISO is mounted.
|
---|
| 1122 | * @param setno The afioball number to get the location of.
|
---|
| 1123 | * @return The absolute path to the afioball.
|
---|
| 1124 | * @note The returned string points to static data that will be overwritten with each call.
|
---|
| 1125 | * @ingroup stringGroup
|
---|
| 1126 | */
|
---|
[48] | 1127 | char *vfy_tball_fname(struct s_bkpinfo *bkpinfo, char *mountpoint,
|
---|
| 1128 | int setno)
|
---|
[1] | 1129 | {
|
---|
[48] | 1130 | /*@ buffers ******************************************************* */
|
---|
| 1131 | static char *output;
|
---|
[1] | 1132 |
|
---|
[48] | 1133 | assert(bkpinfo != NULL);
|
---|
| 1134 | assert_string_is_neither_NULL_nor_zerolength(mountpoint);
|
---|
| 1135 | asprintf(&output, "%s/archives/%d.star.%s", mountpoint, setno,
|
---|
[59] | 1136 | bkpinfo->zip_suffix);
|
---|
[48] | 1137 | if (!does_file_exist(output)) {
|
---|
| 1138 | paranoid_free(output);
|
---|
| 1139 | asprintf(&output, "%s/archives/%d.afio.%s", mountpoint, setno,
|
---|
[59] | 1140 | bkpinfo->zip_suffix);
|
---|
[48] | 1141 | }
|
---|
| 1142 | return (output);
|
---|
[1] | 1143 | }
|
---|