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