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