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