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