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