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