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