[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 1003 2006-12-11 13:41:12Z 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 1003 2006-12-11 13:41:12Z 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, ""))) {
|
---|
[1] | 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.");
|
---|
| 393 | retval++;
|
---|
| 394 | }
|
---|
| 395 | slice_num++;
|
---|
| 396 | } else if (does_file_exist
|
---|
| 397 | (slice_fname(bigfile_num, slice_num, mountpoint, ""))) {
|
---|
| 398 | log_msg(2, "ISO=%d bigfile=%ld ---END---",
|
---|
| 399 | g_current_media_number, bigfile_num);
|
---|
| 400 | bigfile_num++;
|
---|
| 401 | paranoid_fclose(forig);
|
---|
| 402 | slice_num = 0;
|
---|
| 403 | } else {
|
---|
| 404 | log_msg(2, "ISO=%d bigfile=%ld slice=%ld \r",
|
---|
| 405 | g_current_media_number, bigfile_num, slice_num);
|
---|
| 406 | if (bkpinfo->compression_level > 0) {
|
---|
[273] | 407 | sprintf(command, "%s -dc %s 2>> %s",
|
---|
| 408 | sz_exe,
|
---|
[128] | 409 | slice_fname(bigfile_num, slice_num, mountpoint,
|
---|
[273] | 410 | bkpinfo->zip_suffix),
|
---|
[128] | 411 | MONDO_LOGFILE);
|
---|
| 412 | } else {
|
---|
| 413 | sprintf(command, "cat %s",
|
---|
| 414 | slice_fname(bigfile_num, slice_num, mountpoint,
|
---|
| 415 | bkpinfo->zip_suffix));
|
---|
| 416 | }
|
---|
| 417 | if ((pin = popen(command, "r"))) {
|
---|
| 418 | res = 0;
|
---|
| 419 | while (!feof(pin)) {
|
---|
| 420 | currsizA = fread(bufblkA, 1, maxbufsize, pin);
|
---|
| 421 | if (currsizA <= 0) {
|
---|
| 422 | break;
|
---|
| 423 | }
|
---|
| 424 | currsizB = fread(bufblkB, 1, currsizA, forig);
|
---|
| 425 | if (currsizA != currsizB) {
|
---|
| 426 | res++;
|
---|
| 427 | } else {
|
---|
| 428 | for (j = 0;
|
---|
| 429 | j < currsizA && bufblkA[j] == bufblkB[j];
|
---|
| 430 | j++);
|
---|
| 431 | if (j < currsizA) {
|
---|
| 432 | res++;
|
---|
| 433 | }
|
---|
| 434 | }
|
---|
| 435 | }
|
---|
| 436 | paranoid_pclose(pin);
|
---|
| 437 | if (res && !strncmp(biggiestruct.filename, " /dev/", 5)) {
|
---|
| 438 | log_msg(3,
|
---|
[296] | 439 | "Ignoring differences between %s and live filesystem because it's a device and therefore the archives are stored via ntfsclone, not dd.",
|
---|
[128] | 440 | biggiestruct.filename);
|
---|
| 441 | log_msg(3,
|
---|
| 442 | "If you really want verification for %s, please contact the devteam and offer an incentive.",
|
---|
| 443 | biggiestruct.filename);
|
---|
| 444 | res = 0;
|
---|
| 445 | }
|
---|
| 446 | if (res) {
|
---|
| 447 | log_msg(0,
|
---|
| 448 | "afio: \"%s\": Corrupt biggie file, says libmondo-archive.c",
|
---|
| 449 | biggiestruct.filename);
|
---|
| 450 | retval++;
|
---|
| 451 | }
|
---|
| 452 | }
|
---|
| 453 | slice_num++;
|
---|
| 454 | }
|
---|
[1] | 455 | }
|
---|
[128] | 456 | last_bigfile_num = bigfile_num;
|
---|
| 457 | last_slice_num = slice_num - 1;
|
---|
| 458 | if (last_slice_num < 0) {
|
---|
| 459 | last_bigfile_num--;
|
---|
[1] | 460 | }
|
---|
[128] | 461 | close_evalcall_form();
|
---|
| 462 | if (bufblkA) {
|
---|
| 463 | paranoid_free(bufblkA);
|
---|
[1] | 464 | }
|
---|
[128] | 465 | if (bufblkB) {
|
---|
| 466 | paranoid_free(bufblkB);
|
---|
| 467 | }
|
---|
| 468 | paranoid_free(tmp);
|
---|
| 469 | paranoid_free(command);
|
---|
| 470 | paranoid_free(sz_exe);
|
---|
| 471 | paranoid_free(mountpoint);
|
---|
| 472 | return (0);
|
---|
[1] | 473 | }
|
---|
| 474 |
|
---|
| 475 |
|
---|
| 476 |
|
---|
| 477 |
|
---|
| 478 |
|
---|
| 479 |
|
---|
| 480 | /**
|
---|
| 481 | * Verify one afioball from the CD.
|
---|
| 482 | * You should be changed to the root directory (/) for this to work.
|
---|
| 483 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 484 | * - @c bkpinfo->use_lzo
|
---|
| 485 | * - @c bkpinfo->tmpdir
|
---|
| 486 | * - @c bkpinfo->zip_exe
|
---|
| 487 | * - @c bkpinfo->zip_suffix
|
---|
| 488 | * @param tarball_fname The filename of the afioball to verify.
|
---|
| 489 | * @return 0, always.
|
---|
| 490 | */
|
---|
[128] | 491 | int verify_a_tarball(struct s_bkpinfo *bkpinfo, char *tarball_fname)
|
---|
[1] | 492 | {
|
---|
[128] | 493 | /*@ buffers ********************************************************* */
|
---|
| 494 | char *command;
|
---|
[1] | 495 | char *outlog;
|
---|
| 496 | char *tmp;
|
---|
[128] | 497 | // char *p;
|
---|
[1] | 498 |
|
---|
[128] | 499 | /*@ pointers ******************************************************* */
|
---|
| 500 | FILE *pin;
|
---|
[1] | 501 |
|
---|
[128] | 502 | /*@ long *********************************************************** */
|
---|
| 503 | long diffs = 0;
|
---|
| 504 | /* getcwd(old_pwd,MAX_STR_LEN-1); */
|
---|
[1] | 505 |
|
---|
| 506 |
|
---|
[128] | 507 | command = malloc(2000);
|
---|
| 508 | malloc_string(outlog);
|
---|
| 509 | malloc_string(tmp);
|
---|
| 510 | assert(bkpinfo != NULL);
|
---|
| 511 | assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
|
---|
[1] | 512 |
|
---|
[128] | 513 | log_it("Verifying fileset '%s'", tarball_fname);
|
---|
| 514 | /* chdir("/"); */
|
---|
| 515 | sprintf(outlog, "%s/afio.log", bkpinfo->tmpdir);
|
---|
[1] | 516 | /* if programmer forgot to say which compression thingy to use then find out */
|
---|
[128] | 517 | if (strstr(tarball_fname, ".lzo")
|
---|
| 518 | && strcmp(bkpinfo->zip_suffix, "lzo")) {
|
---|
| 519 | log_msg(2, "OK, I'm going to start using lzop.");
|
---|
| 520 | strcpy(bkpinfo->zip_exe, "lzop");
|
---|
| 521 | strcpy(bkpinfo->zip_suffix, "lzo");
|
---|
| 522 | bkpinfo->use_lzo = TRUE;
|
---|
[998] | 523 | bkpinfo->use_gzip = FALSE;
|
---|
[128] | 524 | }
|
---|
[998] | 525 | if (strstr(tarball_fname, ".gz")
|
---|
| 526 | && strcmp(bkpinfo->zip_suffix, "gz")) {
|
---|
| 527 | log_msg(2, "OK, I'm going to start using gzip.");
|
---|
| 528 | strcpy(bkpinfo->zip_exe, "gzip");
|
---|
| 529 | strcpy(bkpinfo->zip_suffix, "gz");
|
---|
| 530 | bkpinfo->use_lzo = FALSE;
|
---|
| 531 | bkpinfo->use_gzip = TRUE;
|
---|
| 532 | }
|
---|
[128] | 533 | if (strstr(tarball_fname, ".bz2")
|
---|
| 534 | && strcmp(bkpinfo->zip_suffix, "bz2")) {
|
---|
| 535 | log_msg(2, "OK, I'm going to start using bzip2.");
|
---|
| 536 | strcpy(bkpinfo->zip_exe, "bzip2");
|
---|
| 537 | strcpy(bkpinfo->zip_suffix, "bz2");
|
---|
| 538 | bkpinfo->use_lzo = FALSE;
|
---|
[998] | 539 | bkpinfo->use_gzip = FALSE;
|
---|
[128] | 540 | }
|
---|
| 541 | unlink(outlog);
|
---|
| 542 | if (strstr(tarball_fname, ".star")) {
|
---|
| 543 | bkpinfo->use_star = TRUE;
|
---|
| 544 | if (strstr(tarball_fname, ".bz2"))
|
---|
| 545 | sprintf(command,
|
---|
| 546 | "star -diff diffopts=mode,size,data file=%s %s >> %s 2>> %s",
|
---|
| 547 | tarball_fname,
|
---|
| 548 | (strstr(tarball_fname, ".bz2")) ? "-bz" : " ", outlog,
|
---|
| 549 | outlog);
|
---|
| 550 | } else {
|
---|
| 551 | bkpinfo->use_star = FALSE;
|
---|
| 552 | sprintf(command, "afio -r -P %s -Z %s >> %s 2>> %s",
|
---|
| 553 | bkpinfo->zip_exe, tarball_fname, outlog, outlog);
|
---|
| 554 | }
|
---|
| 555 | log_msg(6, "command=%s", command);
|
---|
| 556 | paranoid_system(command);
|
---|
| 557 | if (length_of_file(outlog) < 10) {
|
---|
| 558 | sprintf(command, "cat %s >> %s", outlog, MONDO_LOGFILE);
|
---|
| 559 | } else {
|
---|
[273] | 560 | sprintf(command, "cut -d: -f%d %s | sort -u",
|
---|
| 561 | (bkpinfo->use_star) ? 1 : 2, outlog);
|
---|
[128] | 562 | pin = popen(command, "r");
|
---|
| 563 | if (pin) {
|
---|
| 564 | for (fgets(tmp, MAX_STR_LEN, pin); !feof(pin);
|
---|
| 565 | fgets(tmp, MAX_STR_LEN, pin)) {
|
---|
| 566 | if (bkpinfo->use_star) {
|
---|
| 567 | if (!strstr(tmp, "diffopts=")) {
|
---|
| 568 | while (strlen(tmp) > 0
|
---|
| 569 | && tmp[strlen(tmp) - 1] < 32) {
|
---|
| 570 | tmp[strlen(tmp) - 1] = '\0';
|
---|
| 571 | }
|
---|
| 572 | if (strchr(tmp, '/')) {
|
---|
| 573 | if (!diffs) {
|
---|
| 574 | log_msg(0, "'%s' - differences found",
|
---|
| 575 | tarball_fname);
|
---|
| 576 | }
|
---|
| 577 | log_msg(0, "star: /%s",
|
---|
| 578 | strip_afio_output_line(tmp));
|
---|
| 579 | diffs++;
|
---|
| 580 | }
|
---|
| 581 | }
|
---|
| 582 | } else {
|
---|
| 583 | if (!diffs) {
|
---|
| 584 | log_msg(0, "'%s' - differences found",
|
---|
| 585 | tarball_fname);
|
---|
| 586 | }
|
---|
| 587 | log_msg(0, "afio: /%s", strip_afio_output_line(tmp));
|
---|
| 588 | diffs++;
|
---|
| 589 | }
|
---|
[1] | 590 | }
|
---|
[128] | 591 | paranoid_pclose(pin);
|
---|
| 592 | } else {
|
---|
| 593 | log_OS_error(command);
|
---|
| 594 | }
|
---|
| 595 | }
|
---|
| 596 | /* chdir(old_pwd); */
|
---|
[273] | 597 | // sprintf (tmp, "uniq -u %s >> %s", "/tmp/mondo-verify.err", MONDO_LOGFILE);
|
---|
[128] | 598 | // paranoid_system (tmp);
|
---|
| 599 | // unlink ("/tmp/mondo-verify.err");
|
---|
| 600 | paranoid_free(command);
|
---|
| 601 | paranoid_free(outlog);
|
---|
| 602 | paranoid_free(tmp);
|
---|
| 603 | return (0);
|
---|
[1] | 604 | }
|
---|
| 605 |
|
---|
| 606 |
|
---|
| 607 |
|
---|
| 608 |
|
---|
| 609 |
|
---|
| 610 |
|
---|
| 611 | /**
|
---|
| 612 | * Verify one afioball from the CD.
|
---|
| 613 | * Checks for existence (calls fatal_error() if it does not exist) and
|
---|
| 614 | * then calls verify_an_afioball().
|
---|
| 615 | * @param bkpinfo The backup information structure. Passed to verify_an_afioball().
|
---|
| 616 | * @param tarball_fname The filename of the afioball to verify.
|
---|
| 617 | * @return The return value of verify_an_afioball().
|
---|
| 618 | * @see verify_an_afioball
|
---|
| 619 | */
|
---|
| 620 | int
|
---|
[128] | 621 | verify_an_afioball_from_CD(struct s_bkpinfo *bkpinfo, char *tarball_fname)
|
---|
[1] | 622 | {
|
---|
| 623 |
|
---|
[128] | 624 | /*@ int ************************************************************* */
|
---|
| 625 | int res = 0;
|
---|
[1] | 626 |
|
---|
[128] | 627 | assert(bkpinfo != NULL);
|
---|
| 628 | assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
|
---|
[1] | 629 |
|
---|
[128] | 630 | log_msg(1, "Verifying %s", tarball_fname);
|
---|
| 631 | if (!does_file_exist(tarball_fname)) {
|
---|
| 632 | fatal_error("Cannot verify nonexistent afioball");
|
---|
| 633 | }
|
---|
| 634 | res = verify_a_tarball(bkpinfo, tarball_fname);
|
---|
| 635 | return (res);
|
---|
[1] | 636 | }
|
---|
| 637 |
|
---|
| 638 |
|
---|
| 639 | /**
|
---|
| 640 | * Verify one afioball from the opened tape/CD stream.
|
---|
| 641 | * Copies the file from tape to tmpdir and then calls verify_an_afioball().
|
---|
| 642 | * @param bkpinfo The backup information structure. Passed to verify_an_afioball().
|
---|
| 643 | * @param orig_fname The original filename of the afioball to verify.
|
---|
| 644 | * @param size The size of the afioball to verify.
|
---|
| 645 | * @return The return value of verify_an_afioball().
|
---|
| 646 | * @see verify_an_afioball
|
---|
| 647 | */
|
---|
| 648 | int
|
---|
[128] | 649 | verify_an_afioball_from_stream(struct s_bkpinfo *bkpinfo, char *orig_fname,
|
---|
| 650 | long long size)
|
---|
[1] | 651 | {
|
---|
| 652 |
|
---|
[128] | 653 | /*@ int ************************************************************** */
|
---|
| 654 | int retval = 0;
|
---|
[1] | 655 | int res = 0;
|
---|
| 656 |
|
---|
[128] | 657 | /*@ buffers ********************************************************** */
|
---|
| 658 | char *tmp;
|
---|
[1] | 659 | char *tarball_fname;
|
---|
| 660 |
|
---|
[128] | 661 | /*@ pointers ********************************************************* */
|
---|
| 662 | char *p;
|
---|
[1] | 663 |
|
---|
[128] | 664 | malloc_string(tmp);
|
---|
| 665 | malloc_string(tarball_fname);
|
---|
| 666 | assert(bkpinfo != NULL);
|
---|
| 667 | assert_string_is_neither_NULL_nor_zerolength(orig_fname);
|
---|
[1] | 668 |
|
---|
[128] | 669 | p = strrchr(orig_fname, '/');
|
---|
| 670 | if (!p) {
|
---|
| 671 | p = orig_fname;
|
---|
| 672 | } else {
|
---|
| 673 | p++;
|
---|
| 674 | }
|
---|
| 675 | sprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
|
---|
| 676 | paranoid_system(tmp);
|
---|
| 677 | sprintf(tarball_fname, "%s/tmpfs/temporary-%s", bkpinfo->tmpdir, p);
|
---|
| 678 | sprintf(tmp, "Temporarily copying file from tape to '%s'",
|
---|
| 679 | tarball_fname);
|
---|
[1] | 680 | /* log_it(tmp); */
|
---|
[128] | 681 | read_file_from_stream_to_file(bkpinfo, tarball_fname, size);
|
---|
| 682 | res = verify_a_tarball(bkpinfo, tarball_fname);
|
---|
| 683 | if (res) {
|
---|
| 684 | sprintf(tmp,
|
---|
| 685 | "Afioball '%s' no longer matches your live filesystem", p);
|
---|
| 686 | log_msg(0, tmp);
|
---|
| 687 | retval++;
|
---|
| 688 | }
|
---|
| 689 | unlink(tarball_fname);
|
---|
| 690 | paranoid_free(tmp);
|
---|
| 691 | paranoid_free(tarball_fname);
|
---|
| 692 | return (retval);
|
---|
[1] | 693 | }
|
---|
| 694 |
|
---|
| 695 |
|
---|
| 696 | /**
|
---|
| 697 | * Verify one biggiefile form the opened tape/CD stream.
|
---|
| 698 | * @param bkpinfo The backup information structure. @c bkpinfo->tmpdir is the only field used.
|
---|
| 699 | * @param biggie_fname The filename of the biggiefile to verify.
|
---|
| 700 | * @param size The size in bytes of said biggiefile.
|
---|
| 701 | * @return 0 for success (even if the file doesn't match); nonzero for a tape error.
|
---|
| 702 | */
|
---|
| 703 | int
|
---|
[128] | 704 | verify_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo,
|
---|
| 705 | char *biggie_fname, long long size)
|
---|
[1] | 706 | {
|
---|
| 707 |
|
---|
[128] | 708 | /*@ int ************************************************************* */
|
---|
| 709 | int retval = 0;
|
---|
[1] | 710 | int res = 0;
|
---|
| 711 | int current_slice_number = 0;
|
---|
| 712 | int ctrl_chr = '\0';
|
---|
| 713 |
|
---|
[128] | 714 | /*@ char ************************************************************ */
|
---|
[1] | 715 | char *test_file;
|
---|
| 716 | char *biggie_cksum;
|
---|
| 717 | char *orig_cksum;
|
---|
| 718 | char *tmp;
|
---|
| 719 | char *slice_fnam;
|
---|
[128] | 720 |
|
---|
| 721 | /*@ pointers ******************************************************** */
|
---|
[1] | 722 | char *p;
|
---|
| 723 |
|
---|
[128] | 724 | /*@ long long ******************************************************* */
|
---|
| 725 | long long slice_siz;
|
---|
[1] | 726 |
|
---|
[128] | 727 | malloc_string(test_file);
|
---|
| 728 | malloc_string(biggie_cksum);
|
---|
| 729 | malloc_string(orig_cksum);
|
---|
| 730 | malloc_string(tmp);
|
---|
| 731 | malloc_string(slice_fnam);
|
---|
| 732 | assert(bkpinfo != NULL);
|
---|
| 733 | assert_string_is_neither_NULL_nor_zerolength(biggie_fname);
|
---|
[1] | 734 |
|
---|
[128] | 735 | p = strrchr(biggie_fname, '/');
|
---|
| 736 | if (!p) {
|
---|
| 737 | p = biggie_fname;
|
---|
| 738 | } else {
|
---|
| 739 | p++;
|
---|
| 740 | }
|
---|
| 741 | sprintf(test_file, "%s/temporary-%s", bkpinfo->tmpdir, p);
|
---|
| 742 | sprintf(tmp,
|
---|
| 743 | "Temporarily copying biggiefile %s's slices from tape to '%s'",
|
---|
| 744 | p, test_file);
|
---|
[1] | 745 | /* log_it(tmp); */
|
---|
[128] | 746 | for (res =
|
---|
| 747 | read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr);
|
---|
| 748 | ctrl_chr != BLK_STOP_A_BIGGIE;
|
---|
| 749 | res =
|
---|
| 750 | read_header_block_from_stream(&slice_siz, slice_fnam,
|
---|
| 751 | &ctrl_chr)) {
|
---|
| 752 | if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
|
---|
| 753 | wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
|
---|
| 754 | }
|
---|
| 755 | res = read_file_from_stream_to_file(bkpinfo, test_file, slice_siz);
|
---|
| 756 | unlink(test_file);
|
---|
| 757 | res =
|
---|
| 758 | read_header_block_from_stream(&slice_siz, slice_fnam,
|
---|
| 759 | &ctrl_chr);
|
---|
| 760 | if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
|
---|
| 761 | log_msg(2, "test_file = %s", test_file);
|
---|
| 762 | wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
|
---|
| 763 | }
|
---|
| 764 | current_slice_number++;
|
---|
| 765 | retval += res;
|
---|
[1] | 766 | }
|
---|
[128] | 767 | strcpy(biggie_cksum, slice_fnam);
|
---|
| 768 | if (biggie_cksum[0] != '\0') {
|
---|
| 769 | strcpy(orig_cksum, calc_checksum_of_file(biggie_fname));
|
---|
| 770 | if (strcmp(biggie_cksum, orig_cksum)) {
|
---|
| 771 | sprintf(tmp, "orig cksum=%s; curr cksum=%s", biggie_cksum,
|
---|
| 772 | orig_cksum);
|
---|
| 773 | log_msg(2, tmp);
|
---|
[541] | 774 | sprintf(tmp, "%s has changed on live filesystem",
|
---|
[128] | 775 | biggie_fname);
|
---|
| 776 | log_to_screen(tmp);
|
---|
| 777 | sprintf(tmp, "echo \"%s\" >> /tmp/biggies.changed",
|
---|
| 778 | biggie_fname);
|
---|
| 779 | system(tmp);
|
---|
| 780 | }
|
---|
[1] | 781 | }
|
---|
[128] | 782 | paranoid_free(test_file);
|
---|
| 783 | paranoid_free(biggie_cksum);
|
---|
| 784 | paranoid_free(orig_cksum);
|
---|
| 785 | paranoid_free(tmp);
|
---|
| 786 | paranoid_free(slice_fnam);
|
---|
| 787 | return (retval);
|
---|
[1] | 788 | }
|
---|
| 789 |
|
---|
| 790 |
|
---|
| 791 | /**
|
---|
| 792 | * Verify all afioballs from the opened tape/CD stream.
|
---|
| 793 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 794 | * - @c bkpinfo->restore_path
|
---|
| 795 | * - @c bkpinfo->tmpdir
|
---|
| 796 | *
|
---|
| 797 | * @return 0 for success (even if there are differences); nonzero for a tape error.
|
---|
| 798 | */
|
---|
[128] | 799 | int verify_afioballs_from_stream(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 800 | {
|
---|
[128] | 801 | /*@ int ********************************************************** */
|
---|
| 802 | int retval = 0;
|
---|
[1] | 803 | int res = 0;
|
---|
| 804 | long current_afioball_number = 0;
|
---|
| 805 | int ctrl_chr = 0;
|
---|
| 806 | int total_afioballs = 0;
|
---|
| 807 |
|
---|
[128] | 808 | /*@ buffers ***************************************************** */
|
---|
| 809 | char *tmp;
|
---|
[1] | 810 | char *fname;
|
---|
[128] | 811 | char *curr_xattr_list_fname;
|
---|
| 812 | char *curr_acl_list_fname;
|
---|
[1] | 813 |
|
---|
[128] | 814 | /*@ long long *************************************************** */
|
---|
| 815 | long long size = 0;
|
---|
[1] | 816 |
|
---|
[128] | 817 | assert(bkpinfo != NULL);
|
---|
| 818 | malloc_string(tmp);
|
---|
| 819 | malloc_string(fname);
|
---|
| 820 | malloc_string(curr_xattr_list_fname);
|
---|
| 821 | malloc_string(curr_acl_list_fname);
|
---|
[1] | 822 |
|
---|
[948] | 823 | if (g_getfattr) {
|
---|
| 824 | sprintf(curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ,
|
---|
[128] | 825 | bkpinfo->tmpdir);
|
---|
[948] | 826 | }
|
---|
| 827 | if (g_getfacl) {
|
---|
| 828 | sprintf(curr_acl_list_fname, ACL_BIGGLST_FNAME_RAW_SZ,
|
---|
[128] | 829 | bkpinfo->tmpdir);
|
---|
[948] | 830 | }
|
---|
[541] | 831 | log_to_screen("Verifying regular archives on tape");
|
---|
[128] | 832 | total_afioballs = get_last_filelist_number(bkpinfo) + 1;
|
---|
[541] | 833 | open_progress_form("Verifying filesystem",
|
---|
| 834 | "I am verifying archives against your live filesystem now.",
|
---|
| 835 | "Please wait. This may take a couple of hours.", "",
|
---|
[128] | 836 | total_afioballs);
|
---|
| 837 | res = read_header_block_from_stream(&size, fname, &ctrl_chr);
|
---|
| 838 | if (ctrl_chr != BLK_START_AFIOBALLS) {
|
---|
| 839 | iamhere("YOU SHOULD NOT GET HERE");
|
---|
| 840 | iamhere("Grabbing the EXAT files");
|
---|
| 841 | if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
|
---|
| 842 | res =
|
---|
| 843 | read_EXAT_files_from_tape(bkpinfo, &size, fname, &ctrl_chr,
|
---|
| 844 | curr_xattr_list_fname,
|
---|
| 845 | curr_acl_list_fname);
|
---|
| 846 | }
|
---|
[1] | 847 | }
|
---|
[128] | 848 | if (ctrl_chr != BLK_START_AFIOBALLS) {
|
---|
| 849 | wrong_marker(BLK_START_AFIOBALLS, ctrl_chr);
|
---|
[1] | 850 | }
|
---|
[128] | 851 |
|
---|
| 852 | for (res = read_header_block_from_stream(&size, fname, &ctrl_chr);
|
---|
| 853 | ctrl_chr != BLK_STOP_AFIOBALLS;
|
---|
| 854 | res = read_header_block_from_stream(&size, fname, &ctrl_chr)) {
|
---|
[948] | 855 | if (g_getfattr) {
|
---|
| 856 | sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
|
---|
[128] | 857 | bkpinfo->tmpdir, current_afioball_number);
|
---|
[948] | 858 | }
|
---|
| 859 | if (g_getfacl) {
|
---|
| 860 | sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
|
---|
[128] | 861 | bkpinfo->tmpdir, current_afioball_number);
|
---|
[948] | 862 | }
|
---|
[128] | 863 | if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
|
---|
| 864 | iamhere("Reading EXAT files from tape");
|
---|
| 865 | res =
|
---|
| 866 | read_EXAT_files_from_tape(bkpinfo, &size, fname, &ctrl_chr,
|
---|
| 867 | curr_xattr_list_fname,
|
---|
| 868 | curr_acl_list_fname);
|
---|
| 869 | }
|
---|
| 870 | if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
|
---|
| 871 | wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
|
---|
| 872 | }
|
---|
| 873 | sprintf(tmp, "Verifying fileset #%ld", current_afioball_number);
|
---|
| 874 | /*log_it(tmp); */
|
---|
| 875 | update_progress_form(tmp);
|
---|
| 876 | res = verify_an_afioball_from_stream(bkpinfo, fname, size);
|
---|
| 877 | if (res) {
|
---|
[541] | 878 | sprintf(tmp, "Afioball %ld differs from live filesystem",
|
---|
[128] | 879 | current_afioball_number);
|
---|
| 880 | log_to_screen(tmp);
|
---|
| 881 | }
|
---|
| 882 | retval += res;
|
---|
| 883 | current_afioball_number++;
|
---|
| 884 | g_current_progress++;
|
---|
| 885 | res = read_header_block_from_stream(&size, fname, &ctrl_chr);
|
---|
| 886 | if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
|
---|
| 887 | wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
|
---|
| 888 | }
|
---|
[1] | 889 | }
|
---|
[128] | 890 | log_msg(1, "All done with afioballs");
|
---|
| 891 | close_progress_form();
|
---|
| 892 | paranoid_free(tmp);
|
---|
| 893 | paranoid_free(fname);
|
---|
| 894 | paranoid_free(curr_xattr_list_fname);
|
---|
| 895 | paranoid_free(curr_acl_list_fname);
|
---|
| 896 | return (retval);
|
---|
[1] | 897 | }
|
---|
| 898 |
|
---|
| 899 | /**
|
---|
| 900 | * Verify all biggiefiles on the opened CD/tape stream.
|
---|
| 901 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 902 | * - @c bkpinfo->restore_path
|
---|
| 903 | * - @c bkpinfo->tmpdir
|
---|
| 904 | *
|
---|
| 905 | * @return 0 for success (even if there are differences); nonzero for a tape error.
|
---|
| 906 | */
|
---|
[128] | 907 | int verify_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 908 | {
|
---|
| 909 |
|
---|
[128] | 910 | /*@ int ************************************************************ */
|
---|
| 911 | int retval = 0;
|
---|
[1] | 912 | int res = 0;
|
---|
| 913 | int ctrl_chr = 0;
|
---|
| 914 |
|
---|
[128] | 915 | /*@ long *********************************************************** */
|
---|
| 916 | long noof_biggiefiles = 0;
|
---|
[1] | 917 | long current_biggiefile_number = 0;
|
---|
| 918 |
|
---|
[128] | 919 | /*@ buffers ******************************************************** */
|
---|
| 920 | char *tmp;
|
---|
[1] | 921 | char *orig_fname, *logical_fname;
|
---|
| 922 | char *comment;
|
---|
| 923 | char *curr_xattr_list_fname;
|
---|
| 924 | char *curr_acl_list_fname;
|
---|
[128] | 925 | /*@ pointers ******************************************************* */
|
---|
[1] | 926 | char *p;
|
---|
| 927 |
|
---|
[128] | 928 | /*@ long long size ************************************************* */
|
---|
| 929 | long long size = 0;
|
---|
[1] | 930 |
|
---|
[128] | 931 | assert(bkpinfo != NULL);
|
---|
| 932 | malloc_string(tmp);
|
---|
| 933 | malloc_string(orig_fname);
|
---|
| 934 | malloc_string(logical_fname);
|
---|
| 935 | malloc_string(comment);
|
---|
| 936 | malloc_string(curr_xattr_list_fname);
|
---|
| 937 | malloc_string(curr_acl_list_fname);
|
---|
[1] | 938 |
|
---|
[948] | 939 | if (g_getfattr) {
|
---|
| 940 | sprintf(curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ,
|
---|
[128] | 941 | bkpinfo->tmpdir);
|
---|
[948] | 942 | }
|
---|
| 943 | if (g_getfacl) {
|
---|
| 944 | sprintf(curr_acl_list_fname, ACL_BIGGLST_FNAME_RAW_SZ,
|
---|
[128] | 945 | bkpinfo->tmpdir);
|
---|
[948] | 946 | }
|
---|
[128] | 947 | sprintf(comment, "Verifying all bigfiles.");
|
---|
| 948 | log_to_screen(comment);
|
---|
| 949 | sprintf(tmp, "%s/biggielist.txt", bkpinfo->tmpdir);
|
---|
[1] | 950 | // noof_biggiefiles = count_lines_in_file (tmp); // pointless
|
---|
[128] | 951 | res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr);
|
---|
| 952 | if (ctrl_chr != BLK_START_BIGGIEFILES) {
|
---|
| 953 | if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
|
---|
| 954 | iamhere("Grabbing the EXAT biggiefiles");
|
---|
| 955 | res =
|
---|
| 956 | read_EXAT_files_from_tape(bkpinfo, &size, orig_fname,
|
---|
| 957 | &ctrl_chr, curr_xattr_list_fname,
|
---|
| 958 | curr_acl_list_fname);
|
---|
| 959 | }
|
---|
[1] | 960 | }
|
---|
[128] | 961 | if (ctrl_chr != BLK_START_BIGGIEFILES) {
|
---|
| 962 | wrong_marker(BLK_START_BIGGIEFILES, ctrl_chr);
|
---|
[1] | 963 | }
|
---|
[128] | 964 | noof_biggiefiles = (long) size;
|
---|
| 965 | log_msg(1, "noof_biggiefiles = %ld", noof_biggiefiles);
|
---|
[541] | 966 | open_progress_form("Verifying big files", comment,
|
---|
| 967 | "Please wait. This may take some time.", "",
|
---|
[128] | 968 | noof_biggiefiles);
|
---|
| 969 | for (res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr);
|
---|
| 970 | ctrl_chr != BLK_STOP_BIGGIEFILES;
|
---|
| 971 | res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr))
|
---|
[1] | 972 | {
|
---|
[128] | 973 | if (ctrl_chr != BLK_START_A_NORMBIGGIE
|
---|
| 974 | && ctrl_chr != BLK_START_A_PIHBIGGIE) {
|
---|
| 975 | wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr);
|
---|
| 976 | }
|
---|
| 977 | p = strrchr(orig_fname, '/');
|
---|
| 978 | if (!p) {
|
---|
| 979 | p = orig_fname;
|
---|
| 980 | } else {
|
---|
| 981 | p++;
|
---|
| 982 | }
|
---|
[541] | 983 | sprintf(comment, "Verifying bigfile #%ld (%ld K)",
|
---|
[128] | 984 | current_biggiefile_number, (long) size >> 10);
|
---|
| 985 | update_progress_form(comment);
|
---|
| 986 | sprintf(logical_fname, "%s/%s", bkpinfo->restore_path, orig_fname);
|
---|
| 987 | res =
|
---|
| 988 | verify_a_biggiefile_from_stream(bkpinfo, logical_fname, size);
|
---|
| 989 | retval += res;
|
---|
| 990 | current_biggiefile_number++;
|
---|
| 991 | g_current_progress++;
|
---|
[1] | 992 | }
|
---|
[128] | 993 | close_progress_form();
|
---|
| 994 | paranoid_free(orig_fname);
|
---|
| 995 | paranoid_free(logical_fname);
|
---|
| 996 | paranoid_free(curr_xattr_list_fname);
|
---|
| 997 | paranoid_free(curr_acl_list_fname);
|
---|
| 998 | paranoid_free(comment);
|
---|
| 999 | paranoid_free(tmp);
|
---|
| 1000 | return (retval);
|
---|
[1] | 1001 | }
|
---|
| 1002 |
|
---|
| 1003 | /* @} - end of LLverifyGroup */
|
---|
| 1004 |
|
---|
| 1005 |
|
---|
| 1006 | /**
|
---|
| 1007 | * Verify the CD indicated by @c g_current_media_number.
|
---|
| 1008 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 1009 | * - @c bkpinfo->isodir
|
---|
[20] | 1010 | * - @c bkpinfo->prefix
|
---|
[1] | 1011 | * - @c bkpinfo->manual_cd_tray
|
---|
| 1012 | * - @c bkpinfo->media_device
|
---|
| 1013 | * - @c bkpinfo->nfs_remote_dir
|
---|
| 1014 | * - @c bkpinfo->tmpdir
|
---|
| 1015 | * - @c bkpinfo->verify_data
|
---|
| 1016 | *
|
---|
| 1017 | * @return 0 for success (even if differences are found), nonzero for failure.
|
---|
| 1018 | * @ingroup verifyGroup
|
---|
| 1019 | */
|
---|
[128] | 1020 | int verify_cd_image(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 1021 | {
|
---|
| 1022 |
|
---|
[128] | 1023 | /*@ int ************************************************************ */
|
---|
| 1024 | int retval = 0;
|
---|
[1] | 1025 |
|
---|
[128] | 1026 | /*@ buffers ******************************************************** */
|
---|
| 1027 | char *mountpoint;
|
---|
[1] | 1028 | char *command;
|
---|
| 1029 | char *tmp;
|
---|
| 1030 | char *fname;
|
---|
| 1031 | #ifdef __FreeBSD__
|
---|
[128] | 1032 | char mdd[32];
|
---|
[1] | 1033 | char *mddevice = mdd;
|
---|
[128] | 1034 | int ret = 0;
|
---|
| 1035 | int vndev = 2;
|
---|
[1] | 1036 | #else
|
---|
| 1037 | //skip
|
---|
| 1038 | #endif
|
---|
| 1039 |
|
---|
[128] | 1040 | command = malloc(2000);
|
---|
| 1041 | malloc_string(mountpoint);
|
---|
| 1042 | malloc_string(tmp);
|
---|
| 1043 | malloc_string(fname);
|
---|
[1] | 1044 |
|
---|
[128] | 1045 | assert(bkpinfo != NULL);
|
---|
[1] | 1046 |
|
---|
[128] | 1047 | sprintf(mountpoint, "%s/cdrom", bkpinfo->tmpdir);
|
---|
[543] | 1048 | sprintf(fname, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->nfs_remote_dir,
|
---|
| 1049 | bkpinfo->prefix, g_current_media_number);
|
---|
[128] | 1050 |
|
---|
| 1051 | mkdir(mountpoint, 1777);
|
---|
| 1052 | sync();
|
---|
| 1053 | if (!does_file_exist(fname)) {
|
---|
| 1054 | sprintf(tmp,
|
---|
| 1055 | "%s not found; assuming you backed up to CD; verifying CD...",
|
---|
| 1056 | fname);
|
---|
| 1057 | log_msg(2, tmp);
|
---|
| 1058 | if (bkpinfo->manual_cd_tray) {
|
---|
[541] | 1059 | popup_and_OK("Please push CD tray closed.");
|
---|
[128] | 1060 | }
|
---|
| 1061 | if (find_and_mount_actual_cd(bkpinfo, mountpoint)) {
|
---|
[541] | 1062 | log_to_screen("failed to mount actual CD");
|
---|
[128] | 1063 | return (1);
|
---|
| 1064 | }
|
---|
| 1065 | } else {
|
---|
| 1066 | sprintf(tmp, "%s found; verifying ISO...", fname);
|
---|
[1] | 1067 | #ifdef __FreeBSD__
|
---|
[128] | 1068 | ret = 0;
|
---|
| 1069 | vndev = 2;
|
---|
| 1070 | mddevice = make_vn(fname);
|
---|
| 1071 | if (ret) {
|
---|
[541] | 1072 | sprintf(tmp, "make_vn of %s failed; unable to verify ISO\n",
|
---|
[128] | 1073 | fname);
|
---|
| 1074 | log_to_screen(tmp);
|
---|
| 1075 | return (1);
|
---|
| 1076 | }
|
---|
| 1077 | sprintf(command, "mount_cd9660 %s %s", mddevice, mountpoint);
|
---|
[1] | 1078 | #else
|
---|
[128] | 1079 | sprintf(command, "mount -o loop,ro -t iso9660 %s %s", fname,
|
---|
| 1080 | mountpoint);
|
---|
[1] | 1081 | #endif
|
---|
[128] | 1082 | if (run_program_and_log_output(command, FALSE)) {
|
---|
[541] | 1083 | sprintf(tmp, "%s failed; unable to mount ISO image\n",
|
---|
[128] | 1084 | command);
|
---|
| 1085 | log_to_screen(tmp);
|
---|
| 1086 | return (1);
|
---|
| 1087 | }
|
---|
[1] | 1088 | }
|
---|
[128] | 1089 | log_msg(2, "OK, I've mounted the ISO/CD\n");
|
---|
| 1090 | sprintf(tmp, "%s/archives/NOT-THE-LAST", mountpoint);
|
---|
| 1091 | if (!does_file_exist(tmp)) {
|
---|
| 1092 | log_msg
|
---|
| 1093 | (2,
|
---|
| 1094 | "This is the last CD. I am therefore setting bkpinfo->verify_data to FALSE.");
|
---|
| 1095 | bkpinfo->verify_data = FALSE;
|
---|
[1] | 1096 | /*
|
---|
| 1097 | (a) It's an easy way to tell the calling subroutine that we've finished &
|
---|
| 1098 | there are no more CD's to be verified; (b) It stops the post-backup verifier
|
---|
| 1099 | from running after the per-CD verifier has run too.
|
---|
| 1100 | */
|
---|
[128] | 1101 | }
|
---|
| 1102 | verify_afioballs_on_CD(bkpinfo, mountpoint);
|
---|
| 1103 | iamhere("before verify_all_slices");
|
---|
| 1104 | verify_all_slices_on_CD(bkpinfo, mountpoint);
|
---|
[1] | 1105 |
|
---|
| 1106 | #ifdef __FreeBSD__
|
---|
[128] | 1107 | ret = 0;
|
---|
| 1108 | sprintf(command, "umount %s", mountpoint);
|
---|
| 1109 | ret += system(command);
|
---|
| 1110 | ret += kick_vn(mddevice);
|
---|
| 1111 | if (ret)
|
---|
[1] | 1112 | #else
|
---|
[128] | 1113 | sprintf(command, "umount %s", mountpoint);
|
---|
| 1114 | if (system(command))
|
---|
[1] | 1115 | #endif
|
---|
| 1116 | {
|
---|
[128] | 1117 | sprintf(tmp, "%s failed; unable to unmount ISO image\n", command);
|
---|
| 1118 | log_to_screen(tmp);
|
---|
| 1119 | retval++;
|
---|
| 1120 | } else {
|
---|
| 1121 | log_msg(2, "OK, I've unmounted the ISO file\n");
|
---|
[1] | 1122 | }
|
---|
[128] | 1123 | if (!does_file_exist(fname)) {
|
---|
| 1124 | sprintf(command, "umount %s", bkpinfo->media_device);
|
---|
| 1125 | run_program_and_log_output(command, 2);
|
---|
| 1126 | if (!bkpinfo->please_dont_eject
|
---|
| 1127 | && eject_device(bkpinfo->media_device)) {
|
---|
| 1128 | log_msg(2, "Failed to eject CD-ROM drive");
|
---|
| 1129 | }
|
---|
| 1130 | }
|
---|
| 1131 | paranoid_free(command);
|
---|
| 1132 | paranoid_free(mountpoint);
|
---|
| 1133 | paranoid_free(tmp);
|
---|
| 1134 | paranoid_free(fname);
|
---|
| 1135 | return (retval);
|
---|
[1] | 1136 | }
|
---|
| 1137 |
|
---|
| 1138 | /**
|
---|
| 1139 | * Verify all backups on tape.
|
---|
| 1140 | * This should be done after the backup process has already closed the tape.
|
---|
| 1141 | * @param bkpinfo The backup information structure. Passed to various helper functions.
|
---|
| 1142 | * @return 0 for success (even if thee were differences), nonzero for failure.
|
---|
| 1143 | * @ingroup verifyGroup
|
---|
| 1144 | */
|
---|
[128] | 1145 | int verify_tape_backups(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 1146 | {
|
---|
| 1147 |
|
---|
[128] | 1148 | /*@ int ************************************************************ */
|
---|
| 1149 | int retval = 0;
|
---|
[1] | 1150 |
|
---|
[128] | 1151 | /*@ buffers ******************************************************** */
|
---|
| 1152 | char tmp[MAX_STR_LEN];
|
---|
| 1153 | char changed_files_fname[MAX_STR_LEN];
|
---|
[1] | 1154 |
|
---|
[128] | 1155 | /*@ long *********************************************************** */
|
---|
| 1156 | long diffs = 0;
|
---|
[1] | 1157 |
|
---|
[128] | 1158 | assert(bkpinfo != NULL);
|
---|
[1] | 1159 |
|
---|
[128] | 1160 | log_msg(3, "verify_tape_backups --- starting");
|
---|
[541] | 1161 | log_to_screen("Verifying backups");
|
---|
[128] | 1162 | openin_tape(bkpinfo);
|
---|
[1] | 1163 | /* verify archives themselves */
|
---|
[128] | 1164 | retval += verify_afioballs_from_stream(bkpinfo);
|
---|
| 1165 | retval += verify_biggiefiles_from_stream(bkpinfo);
|
---|
[1] | 1166 | /* find the final blocks */
|
---|
[128] | 1167 | paranoid_system("sync");
|
---|
| 1168 | sleep(2);
|
---|
| 1169 | closein_tape(bkpinfo);
|
---|
[1] | 1170 | /* close tape; exit */
|
---|
| 1171 | // fclose(g_tape_stream); <-- not needed; is handled by closein_tape()
|
---|
[128] | 1172 | paranoid_system
|
---|
| 1173 | ("rm -f /tmp/biggies.changed /tmp/changed.files.[0-9]* 2> /dev/null");
|
---|
| 1174 | sprintf(changed_files_fname, "/tmp/changed.files.%d",
|
---|
| 1175 | (int) (random() % 32767));
|
---|
| 1176 | sprintf(tmp,
|
---|
[911] | 1177 | "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] | 1178 | (bkpinfo->use_star) ? "star" : "afio", MONDO_LOGFILE,
|
---|
[128] | 1179 | changed_files_fname);
|
---|
| 1180 | log_msg(2, "Running command to derive list of changed files");
|
---|
| 1181 | log_msg(2, tmp);
|
---|
| 1182 | if (system(tmp)) {
|
---|
| 1183 | if (does_file_exist(changed_files_fname)
|
---|
| 1184 | && length_of_file(changed_files_fname) > 2) {
|
---|
| 1185 | log_to_screen
|
---|
[541] | 1186 | ("Warning - unable to check logfile to derive list of changed files");
|
---|
[128] | 1187 | } else {
|
---|
| 1188 | log_to_screen
|
---|
[541] | 1189 | ("No differences found. Therefore, no 'changed.files' text file.");
|
---|
[128] | 1190 | }
|
---|
| 1191 | }
|
---|
| 1192 | sprintf(tmp, "cat /tmp/biggies.changed >> %s", changed_files_fname);
|
---|
| 1193 | paranoid_system(tmp);
|
---|
[1] | 1194 |
|
---|
[128] | 1195 | diffs = count_lines_in_file(changed_files_fname);
|
---|
| 1196 | if (diffs > 0) {
|
---|
| 1197 | sprintf(tmp, "cp -f %s %s", changed_files_fname,
|
---|
| 1198 | "/tmp/changed.files");
|
---|
| 1199 | run_program_and_log_output(tmp, FALSE);
|
---|
| 1200 | sprintf(tmp,
|
---|
| 1201 | "%ld files differed from live filesystem; type less %s or less %s to see",
|
---|
| 1202 | diffs, changed_files_fname, "/tmp/changed.files");
|
---|
| 1203 | log_msg(0, tmp);
|
---|
| 1204 | log_to_screen
|
---|
[541] | 1205 | ("See /tmp/changed.files for a list of nonmatching files.");
|
---|
[128] | 1206 | log_to_screen
|
---|
[541] | 1207 | ("The files probably changed on filesystem, not on backup media.");
|
---|
[128] | 1208 | // retval++;
|
---|
| 1209 | }
|
---|
| 1210 | return (retval);
|
---|
[1] | 1211 | }
|
---|
| 1212 |
|
---|
| 1213 |
|
---|
| 1214 |
|
---|
| 1215 | /**
|
---|
| 1216 | * Generate the filename of a tarball to verify.
|
---|
| 1217 | * @param bkpinfo The backup information structure. @c bkpinfo->zip_suffix is the only field used.
|
---|
| 1218 | * @param mountpoint The directory where the CD/DVD/ISO is mounted.
|
---|
| 1219 | * @param setno The afioball number to get the location of.
|
---|
| 1220 | * @return The absolute path to the afioball.
|
---|
| 1221 | * @note The returned string points to static data that will be overwritten with each call.
|
---|
| 1222 | * @ingroup stringGroup
|
---|
| 1223 | */
|
---|
[128] | 1224 | char *vfy_tball_fname(struct s_bkpinfo *bkpinfo, char *mountpoint,
|
---|
| 1225 | int setno)
|
---|
[1] | 1226 | {
|
---|
[128] | 1227 | /*@ buffers ******************************************************* */
|
---|
| 1228 | static char output[MAX_STR_LEN];
|
---|
[1] | 1229 |
|
---|
[128] | 1230 | assert(bkpinfo != NULL);
|
---|
| 1231 | assert_string_is_neither_NULL_nor_zerolength(mountpoint);
|
---|
| 1232 | sprintf(output, "%s/archives/%d.star.%s", mountpoint, setno,
|
---|
| 1233 | bkpinfo->zip_suffix);
|
---|
| 1234 | if (!does_file_exist(output)) {
|
---|
| 1235 | sprintf(output, "%s/archives/%d.afio.%s", mountpoint, setno,
|
---|
| 1236 | bkpinfo->zip_suffix);
|
---|
| 1237 | }
|
---|
| 1238 | return (output);
|
---|
[1] | 1239 | }
|
---|