1 | /* $Id: libmondo-verify.c 120 2005-11-09 01:44:43Z 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 120 2005-11-09 01:44:43Z 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; |
---|
611 | |
---|
612 | /*@ pointers ******************************************************** */ |
---|
613 | char *p; |
---|
614 | |
---|
615 | /*@ long long ******************************************************* */ |
---|
616 | long long slice_siz; |
---|
617 | |
---|
618 | malloc_string(slice_fnam); |
---|
619 | assert(bkpinfo != NULL); |
---|
620 | assert_string_is_neither_NULL_nor_zerolength(biggie_fname); |
---|
621 | |
---|
622 | p = strrchr(biggie_fname, '/'); |
---|
623 | if (!p) { |
---|
624 | p = biggie_fname; |
---|
625 | } else { |
---|
626 | p++; |
---|
627 | } |
---|
628 | asprintf(&test_file, "%s/temporary-%s", bkpinfo->tmpdir, p); |
---|
629 | /* BERLIOS: useless |
---|
630 | asprintf(&tmp, |
---|
631 | "Temporarily copying biggiefile %s's slices from tape to '%s'", |
---|
632 | p, test_file); |
---|
633 | log_it(tmp); |
---|
634 | paranoid_free(tmp); |
---|
635 | */ |
---|
636 | for (res = |
---|
637 | read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr); |
---|
638 | ctrl_chr != BLK_STOP_A_BIGGIE; |
---|
639 | res = |
---|
640 | read_header_block_from_stream(&slice_siz, slice_fnam, |
---|
641 | &ctrl_chr)) { |
---|
642 | if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) { |
---|
643 | wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); |
---|
644 | } |
---|
645 | res = read_file_from_stream_to_file(bkpinfo, test_file, slice_siz); |
---|
646 | unlink(test_file); |
---|
647 | res = |
---|
648 | read_header_block_from_stream(&slice_siz, slice_fnam, |
---|
649 | &ctrl_chr); |
---|
650 | if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) { |
---|
651 | log_msg(2, "test_file = %s", test_file); |
---|
652 | wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr); |
---|
653 | } |
---|
654 | current_slice_number++; |
---|
655 | retval += res; |
---|
656 | } |
---|
657 | paranoid_free(test_file); |
---|
658 | |
---|
659 | asprintf(&biggie_cksum, slice_fnam); |
---|
660 | paranoid_free(slice_fnam); |
---|
661 | |
---|
662 | if (biggie_cksum[0] != '\0') { |
---|
663 | asprintf(&orig_cksum, calc_checksum_of_file(biggie_fname)); |
---|
664 | if (strcmp(biggie_cksum, orig_cksum)) { |
---|
665 | asprintf(&tmp, "orig cksum=%s; curr cksum=%s", biggie_cksum, |
---|
666 | orig_cksum); |
---|
667 | log_msg(2, tmp); |
---|
668 | paranoid_free(tmp); |
---|
669 | |
---|
670 | asprintf(&tmp, "%s has changed on live filesystem", |
---|
671 | biggie_fname); |
---|
672 | log_to_screen(tmp); |
---|
673 | paranoid_free(tmp); |
---|
674 | |
---|
675 | asprintf(&tmp, "echo \"%s\" >> /tmp/biggies.changed", |
---|
676 | biggie_fname); |
---|
677 | system(tmp); |
---|
678 | paranoid_free(tmp); |
---|
679 | } |
---|
680 | paranoid_free(orig_cksum); |
---|
681 | } |
---|
682 | paranoid_free(biggie_cksum); |
---|
683 | |
---|
684 | return (retval); |
---|
685 | } |
---|
686 | |
---|
687 | |
---|
688 | /** |
---|
689 | * Verify all afioballs from the opened tape/CD stream. |
---|
690 | * @param bkpinfo The backup information structure. Fields used: |
---|
691 | * - @c bkpinfo->restore_path |
---|
692 | * - @c bkpinfo->tmpdir |
---|
693 | * |
---|
694 | * @return 0 for success (even if there are differences); nonzero for a tape error. |
---|
695 | */ |
---|
696 | int verify_afioballs_from_stream(struct s_bkpinfo *bkpinfo) |
---|
697 | { |
---|
698 | /*@ int ********************************************************** */ |
---|
699 | int retval = 0; |
---|
700 | int res = 0; |
---|
701 | long current_afioball_number = 0; |
---|
702 | int ctrl_chr = 0; |
---|
703 | int total_afioballs = 0; |
---|
704 | |
---|
705 | /*@ buffers ***************************************************** */ |
---|
706 | char *tmp; |
---|
707 | char *fname; |
---|
708 | char *curr_xattr_list_fname; |
---|
709 | char *curr_acl_list_fname; |
---|
710 | |
---|
711 | /*@ long long *************************************************** */ |
---|
712 | long long size = 0; |
---|
713 | |
---|
714 | assert(bkpinfo != NULL); |
---|
715 | malloc_string(fname); |
---|
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, fname, &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, fname, &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 | res = |
---|
754 | read_EXAT_files_from_tape(bkpinfo, &size, fname, &ctrl_chr, |
---|
755 | curr_xattr_list_fname, |
---|
756 | curr_acl_list_fname); |
---|
757 | } |
---|
758 | paranoid_free(curr_xattr_list_fname); |
---|
759 | paranoid_free(curr_acl_list_fname); |
---|
760 | |
---|
761 | if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) { |
---|
762 | wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); |
---|
763 | } |
---|
764 | asprintf(&tmp, "Verifying fileset #%ld", current_afioball_number); |
---|
765 | /*log_it(tmp); */ |
---|
766 | update_progress_form(tmp); |
---|
767 | paranoid_free(tmp); |
---|
768 | |
---|
769 | res = verify_an_afioball_from_stream(bkpinfo, fname, size); |
---|
770 | if (res) { |
---|
771 | asprintf(&tmp, "Afioball %ld differs from live filesystem", |
---|
772 | current_afioball_number); |
---|
773 | log_to_screen(tmp); |
---|
774 | paranoid_free(tmp); |
---|
775 | } |
---|
776 | retval += res; |
---|
777 | current_afioball_number++; |
---|
778 | g_current_progress++; |
---|
779 | res = read_header_block_from_stream(&size, fname, &ctrl_chr); |
---|
780 | if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) { |
---|
781 | wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr); |
---|
782 | } |
---|
783 | } |
---|
784 | log_msg(1, "All done with afioballs"); |
---|
785 | close_progress_form(); |
---|
786 | paranoid_free(fname); |
---|
787 | return (retval); |
---|
788 | } |
---|
789 | |
---|
790 | |
---|
791 | /** |
---|
792 | * Verify all biggiefiles on the opened CD/tape stream. |
---|
793 | * @param bkpinfo The backup information structure. Fields used: |
---|
794 | * - @c bkpinfo->restore_path |
---|
795 | * - @c bkpinfo->tmpdir |
---|
796 | * |
---|
797 | * @return 0 for success (even if there are differences); nonzero for a tape error. |
---|
798 | */ |
---|
799 | int verify_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo) |
---|
800 | { |
---|
801 | |
---|
802 | /*@ int ************************************************************ */ |
---|
803 | int retval = 0; |
---|
804 | int res = 0; |
---|
805 | int ctrl_chr = 0; |
---|
806 | |
---|
807 | /*@ long *********************************************************** */ |
---|
808 | long noof_biggiefiles = 0; |
---|
809 | long current_biggiefile_number = 0; |
---|
810 | |
---|
811 | /*@ buffers ******************************************************** */ |
---|
812 | char *orig_fname, *logical_fname; |
---|
813 | char *comment; |
---|
814 | char *curr_xattr_list_fname; |
---|
815 | char *curr_acl_list_fname; |
---|
816 | /*@ pointers ******************************************************* */ |
---|
817 | char *p; |
---|
818 | |
---|
819 | /*@ long long size ************************************************* */ |
---|
820 | long long size = 0; |
---|
821 | |
---|
822 | assert(bkpinfo != NULL); |
---|
823 | malloc_string(orig_fname); |
---|
824 | |
---|
825 | asprintf(&curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ, |
---|
826 | bkpinfo->tmpdir); |
---|
827 | asprintf(&curr_acl_list_fname, ACL_BIGGLST_FNAME_RAW_SZ, |
---|
828 | bkpinfo->tmpdir); |
---|
829 | asprintf(&comment, "Verifying all bigfiles."); |
---|
830 | log_to_screen(comment); |
---|
831 | /* |
---|
832 | asprintf(&tmp, "%s/biggielist.txt", bkpinfo->tmpdir); |
---|
833 | noof_biggiefiles = count_lines_in_file (tmp); // pointless |
---|
834 | paranoid_free(tmp); |
---|
835 | */ |
---|
836 | res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr); |
---|
837 | if (ctrl_chr != BLK_START_BIGGIEFILES) { |
---|
838 | if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) { |
---|
839 | iamhere("Grabbing the EXAT biggiefiles"); |
---|
840 | res = |
---|
841 | read_EXAT_files_from_tape(bkpinfo, &size, orig_fname, |
---|
842 | &ctrl_chr, curr_xattr_list_fname, |
---|
843 | curr_acl_list_fname); |
---|
844 | } |
---|
845 | } |
---|
846 | paranoid_free(curr_xattr_list_fname); |
---|
847 | paranoid_free(curr_acl_list_fname); |
---|
848 | |
---|
849 | if (ctrl_chr != BLK_START_BIGGIEFILES) { |
---|
850 | wrong_marker(BLK_START_BIGGIEFILES, ctrl_chr); |
---|
851 | } |
---|
852 | noof_biggiefiles = (long) size; |
---|
853 | log_msg(1, "noof_biggiefiles = %ld", noof_biggiefiles); |
---|
854 | open_progress_form("Verifying big files", comment, |
---|
855 | "Please wait. This may take some time.", "", |
---|
856 | noof_biggiefiles); |
---|
857 | paranoid_free(comment); |
---|
858 | |
---|
859 | for (res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr); |
---|
860 | ctrl_chr != BLK_STOP_BIGGIEFILES; |
---|
861 | res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr)) |
---|
862 | { |
---|
863 | if (ctrl_chr != BLK_START_A_NORMBIGGIE |
---|
864 | && ctrl_chr != BLK_START_A_PIHBIGGIE) { |
---|
865 | wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr); |
---|
866 | } |
---|
867 | p = strrchr(orig_fname, '/'); |
---|
868 | if (!p) { |
---|
869 | p = orig_fname; |
---|
870 | } else { |
---|
871 | p++; |
---|
872 | } |
---|
873 | asprintf(&comment, "Verifying bigfile #%ld (%ld K)", |
---|
874 | current_biggiefile_number, (long) size >> 10); |
---|
875 | update_progress_form(comment); |
---|
876 | paranoid_free(comment); |
---|
877 | |
---|
878 | asprintf(&logical_fname, "%s/%s", bkpinfo->restore_path, |
---|
879 | orig_fname); |
---|
880 | res = |
---|
881 | verify_a_biggiefile_from_stream(bkpinfo, logical_fname, size); |
---|
882 | paranoid_free(logical_fname); |
---|
883 | retval += res; |
---|
884 | current_biggiefile_number++; |
---|
885 | g_current_progress++; |
---|
886 | } |
---|
887 | close_progress_form(); |
---|
888 | paranoid_free(orig_fname); |
---|
889 | return (retval); |
---|
890 | } |
---|
891 | |
---|
892 | /* @} - end of LLverifyGroup */ |
---|
893 | |
---|
894 | |
---|
895 | /** |
---|
896 | * Verify the CD indicated by @c g_current_media_number. |
---|
897 | * @param bkpinfo The backup information structure. Fields used: |
---|
898 | * - @c bkpinfo->isodir |
---|
899 | * - @c bkpinfo->prefix |
---|
900 | * - @c bkpinfo->manual_cd_tray |
---|
901 | * - @c bkpinfo->media_device |
---|
902 | * - @c bkpinfo->nfs_remote_dir |
---|
903 | * - @c bkpinfo->tmpdir |
---|
904 | * - @c bkpinfo->verify_data |
---|
905 | * |
---|
906 | * @return 0 for success (even if differences are found), nonzero for failure. |
---|
907 | * @ingroup verifyGroup |
---|
908 | */ |
---|
909 | int verify_cd_image(struct s_bkpinfo *bkpinfo) |
---|
910 | { |
---|
911 | |
---|
912 | /*@ int ************************************************************ */ |
---|
913 | int retval = 0; |
---|
914 | |
---|
915 | /*@ buffers ******************************************************** */ |
---|
916 | char *mountpoint; |
---|
917 | char *command; |
---|
918 | char *tmp; |
---|
919 | char *fname; |
---|
920 | #ifdef __FreeBSD__ |
---|
921 | char mdd[32]; |
---|
922 | char *mddevice = mdd; |
---|
923 | int ret = 0; |
---|
924 | int vndev = 2; |
---|
925 | #else |
---|
926 | //skip |
---|
927 | #endif |
---|
928 | |
---|
929 | assert(bkpinfo != NULL); |
---|
930 | |
---|
931 | asprintf(&mountpoint, "%s/cdrom", bkpinfo->tmpdir); |
---|
932 | asprintf(&fname, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->prefix, |
---|
933 | bkpinfo->nfs_remote_dir, g_current_media_number); |
---|
934 | |
---|
935 | mkdir(mountpoint, 1777); |
---|
936 | sync(); |
---|
937 | if (!does_file_exist(fname)) { |
---|
938 | asprintf(&tmp, |
---|
939 | "%s not found; assuming you backed up to CD; verifying CD...", |
---|
940 | fname); |
---|
941 | log_msg(2, tmp); |
---|
942 | paranoid_free(tmp); |
---|
943 | |
---|
944 | if (bkpinfo->manual_cd_tray) { |
---|
945 | popup_and_OK("Please push CD tray closed."); |
---|
946 | } |
---|
947 | if (find_and_mount_actual_cd(bkpinfo, mountpoint)) { |
---|
948 | log_to_screen("failed to mount actual CD"); |
---|
949 | return (1); |
---|
950 | } |
---|
951 | } else { |
---|
952 | asprintf(&tmp, "%s found; verifying ISO...", fname); |
---|
953 | log_to_screen(tmp); |
---|
954 | paranoid_free(tmp); |
---|
955 | #ifdef __FreeBSD__ |
---|
956 | ret = 0; |
---|
957 | vndev = 2; |
---|
958 | mddevice = make_vn(fname); |
---|
959 | if (ret) { |
---|
960 | asprintf(&tmp, "make_vn of %s failed; unable to verify ISO\n", |
---|
961 | fname); |
---|
962 | log_to_screen(tmp); |
---|
963 | paranoid_free(tmp); |
---|
964 | return (1); |
---|
965 | } |
---|
966 | asprintf(&command, "mount_cd9660 %s %s", mddevice, mountpoint); |
---|
967 | #else |
---|
968 | asprintf(&command, "mount -o loop,ro -t iso9660 %s %s", fname, |
---|
969 | mountpoint); |
---|
970 | #endif |
---|
971 | if (run_program_and_log_output(command, FALSE)) { |
---|
972 | asprintf(&tmp, "%s failed; unable to mount ISO image\n", |
---|
973 | command); |
---|
974 | log_to_screen(tmp); |
---|
975 | paranoid_free(tmp); |
---|
976 | return (1); |
---|
977 | } |
---|
978 | paranoid_free(command); |
---|
979 | } |
---|
980 | log_msg(2, "OK, I've mounted the ISO/CD\n"); |
---|
981 | asprintf(&tmp, "%s/archives/NOT-THE-LAST", mountpoint); |
---|
982 | if (!does_file_exist(tmp)) { |
---|
983 | log_msg |
---|
984 | (2, |
---|
985 | "This is the last CD. I am therefore setting bkpinfo->verify_data to FALSE."); |
---|
986 | bkpinfo->verify_data = FALSE; |
---|
987 | /* |
---|
988 | (a) It's an easy way to tell the calling subroutine that we've finished & |
---|
989 | there are no more CD's to be verified; (b) It stops the post-backup verifier |
---|
990 | from running after the per-CD verifier has run too. |
---|
991 | */ |
---|
992 | } |
---|
993 | paranoid_free(tmp); |
---|
994 | |
---|
995 | verify_afioballs_on_CD(bkpinfo, mountpoint); |
---|
996 | iamhere("before verify_all_slices"); |
---|
997 | verify_all_slices_on_CD(bkpinfo, mountpoint); |
---|
998 | |
---|
999 | #ifdef __FreeBSD__ |
---|
1000 | ret = 0; |
---|
1001 | asprintf(&command, "umount %s", mountpoint); |
---|
1002 | ret += system(command); |
---|
1003 | |
---|
1004 | ret += kick_vn(mddevice); |
---|
1005 | if (ret) |
---|
1006 | #else |
---|
1007 | asprintf(&command, "umount %s", mountpoint); |
---|
1008 | |
---|
1009 | if (system(command)) |
---|
1010 | #endif |
---|
1011 | { |
---|
1012 | asprintf(&tmp, "%s failed; unable to unmount ISO image\n", |
---|
1013 | command); |
---|
1014 | log_to_screen(tmp); |
---|
1015 | paranoid_free(tmp); |
---|
1016 | retval++; |
---|
1017 | } else { |
---|
1018 | log_msg(2, "OK, I've unmounted the ISO file\n"); |
---|
1019 | } |
---|
1020 | paranoid_free(command); |
---|
1021 | paranoid_free(mountpoint); |
---|
1022 | |
---|
1023 | if (!does_file_exist(fname)) { |
---|
1024 | asprintf(&command, "umount %s", bkpinfo->media_device); |
---|
1025 | run_program_and_log_output(command, 2); |
---|
1026 | paranoid_free(command); |
---|
1027 | |
---|
1028 | if (!bkpinfo->please_dont_eject |
---|
1029 | && eject_device(bkpinfo->media_device)) { |
---|
1030 | log_msg(2, "Failed to eject CD-ROM drive"); |
---|
1031 | } |
---|
1032 | } |
---|
1033 | paranoid_free(fname); |
---|
1034 | return (retval); |
---|
1035 | } |
---|
1036 | |
---|
1037 | |
---|
1038 | /** |
---|
1039 | * Verify all backups on tape. |
---|
1040 | * This should be done after the backup process has already closed the tape. |
---|
1041 | * @param bkpinfo The backup information structure. Passed to various helper functions. |
---|
1042 | * @return 0 for success (even if thee were differences), nonzero for failure. |
---|
1043 | * @ingroup verifyGroup |
---|
1044 | */ |
---|
1045 | int verify_tape_backups(struct s_bkpinfo *bkpinfo) |
---|
1046 | { |
---|
1047 | |
---|
1048 | /*@ int ************************************************************ */ |
---|
1049 | int retval = 0; |
---|
1050 | |
---|
1051 | /*@ buffers ******************************************************** */ |
---|
1052 | char *tmp; |
---|
1053 | char *changed_files_fname; |
---|
1054 | |
---|
1055 | /*@ long *********************************************************** */ |
---|
1056 | long diffs = 0; |
---|
1057 | |
---|
1058 | assert(bkpinfo != NULL); |
---|
1059 | |
---|
1060 | log_msg(3, "verify_tape_backups --- starting"); |
---|
1061 | log_to_screen("Verifying backups"); |
---|
1062 | openin_tape(bkpinfo); |
---|
1063 | |
---|
1064 | /* verify archives themselves */ |
---|
1065 | retval += verify_afioballs_from_stream(bkpinfo); |
---|
1066 | retval += verify_biggiefiles_from_stream(bkpinfo); |
---|
1067 | |
---|
1068 | /* find the final blocks */ |
---|
1069 | paranoid_system("sync"); |
---|
1070 | sleep(2); |
---|
1071 | closein_tape(bkpinfo); |
---|
1072 | |
---|
1073 | /* close tape; exit */ |
---|
1074 | // fclose(g_tape_stream); <-- not needed; is handled by closein_tape() |
---|
1075 | paranoid_system |
---|
1076 | ("rm -f /tmp/biggies.changed /tmp/changed.files.[0-9]* 2> /dev/null"); |
---|
1077 | asprintf(&changed_files_fname, "/tmp/changed.files.%d", |
---|
1078 | (int) (random() % 32767)); |
---|
1079 | asprintf(&tmp, |
---|
1080 | "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", |
---|
1081 | MONDO_LOGFILE, (bkpinfo->use_star) ? "star" : "afio", |
---|
1082 | changed_files_fname); |
---|
1083 | log_msg(2, "Running command to derive list of changed files"); |
---|
1084 | log_msg(2, tmp); |
---|
1085 | if (system(tmp)) { |
---|
1086 | if (does_file_exist(changed_files_fname) |
---|
1087 | && length_of_file(changed_files_fname) > 2) { |
---|
1088 | log_to_screen |
---|
1089 | ("Warning - unable to check logfile to derive list of changed files"); |
---|
1090 | } else { |
---|
1091 | log_to_screen |
---|
1092 | ("No differences found. Therefore, no 'changed.files' text file."); |
---|
1093 | } |
---|
1094 | } |
---|
1095 | paranoid_free(tmp); |
---|
1096 | |
---|
1097 | asprintf(&tmp, "cat /tmp/biggies.changed >> %s", changed_files_fname); |
---|
1098 | paranoid_system(tmp); |
---|
1099 | paranoid_free(tmp); |
---|
1100 | |
---|
1101 | diffs = count_lines_in_file(changed_files_fname); |
---|
1102 | if (diffs > 0) { |
---|
1103 | asprintf(&tmp, "cp -f %s %s", changed_files_fname, |
---|
1104 | "/tmp/changed.files"); |
---|
1105 | run_program_and_log_output(tmp, FALSE); |
---|
1106 | paranoid_free(tmp); |
---|
1107 | |
---|
1108 | asprintf(&tmp, |
---|
1109 | "%ld files differed from live filesystem; type less %s or less %s to see", |
---|
1110 | diffs, changed_files_fname, "/tmp/changed.files"); |
---|
1111 | log_msg(0, tmp); |
---|
1112 | paranoid_free(tmp); |
---|
1113 | |
---|
1114 | log_to_screen |
---|
1115 | ("See /tmp/changed.files for a list of nonmatching files."); |
---|
1116 | log_to_screen |
---|
1117 | ("The files probably changed on filesystem, not on backup media."); |
---|
1118 | // retval++; |
---|
1119 | } |
---|
1120 | paranoid_free(changed_files_fname); |
---|
1121 | return (retval); |
---|
1122 | } |
---|
1123 | |
---|
1124 | |
---|
1125 | /** |
---|
1126 | * Generate the filename of a tarball to verify. |
---|
1127 | * @param bkpinfo The backup information structure. @c bkpinfo->zip_suffix is the only field used. |
---|
1128 | * @param mountpoint The directory where the CD/DVD/ISO is mounted. |
---|
1129 | * @param setno The afioball number to get the location of. |
---|
1130 | * @return The absolute path to the afioball. |
---|
1131 | * @note The returned string points to static data that will be overwritten with each call. |
---|
1132 | * @ingroup stringGroup |
---|
1133 | */ |
---|
1134 | char *vfy_tball_fname(struct s_bkpinfo *bkpinfo, char *mountpoint, |
---|
1135 | int setno) |
---|
1136 | { |
---|
1137 | /*@ buffers ******************************************************* */ |
---|
1138 | static char *output; |
---|
1139 | |
---|
1140 | assert(bkpinfo != NULL); |
---|
1141 | assert_string_is_neither_NULL_nor_zerolength(mountpoint); |
---|
1142 | asprintf(&output, "%s/archives/%d.star.%s", mountpoint, setno, |
---|
1143 | bkpinfo->zip_suffix); |
---|
1144 | if (!does_file_exist(output)) { |
---|
1145 | paranoid_free(output); |
---|
1146 | asprintf(&output, "%s/archives/%d.afio.%s", mountpoint, setno, |
---|
1147 | bkpinfo->zip_suffix); |
---|
1148 | } |
---|
1149 | return (output); |
---|
1150 | } |
---|