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