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