1 | /* libmondo-archive.c |
---|
2 | $Id: libmondo-archive.c 1977 2008-06-02 08:49:01Z bruno $ |
---|
3 | |
---|
4 | subroutines to handle the archiving of files |
---|
5 | */ |
---|
6 | |
---|
7 | /** |
---|
8 | * @file |
---|
9 | * Functions to handle backing up data. |
---|
10 | * This is the main file (at least the longest one) in libmondo. |
---|
11 | */ |
---|
12 | #include <sys/sem.h> |
---|
13 | #include <sys/types.h> |
---|
14 | #include <sys/ipc.h> |
---|
15 | #include <stdarg.h> |
---|
16 | #include <stdlib.h> |
---|
17 | #include <unistd.h> |
---|
18 | |
---|
19 | #include "my-stuff.h" |
---|
20 | #include "mondostructures.h" |
---|
21 | |
---|
22 | #include "mr_mem.h" |
---|
23 | #include "mr_msg.h" |
---|
24 | #include "mr_err.h" |
---|
25 | #include "mr_str.h" |
---|
26 | #include "mr_file.h" |
---|
27 | #include "mr_gettext.h" |
---|
28 | #include "mr_conf.h" |
---|
29 | |
---|
30 | #include "libmondo-string-EXT.h" |
---|
31 | #include "libmondo-stream-EXT.h" |
---|
32 | #include "libmondo-devices-EXT.h" |
---|
33 | #include "libmondo-tools-EXT.h" |
---|
34 | #include "newt-specific-EXT.h" |
---|
35 | #include "libmondo-fork-EXT.h" |
---|
36 | #include "libmondo-files-EXT.h" |
---|
37 | #include "libmondo-filelist-EXT.h" |
---|
38 | #include "libmondo-tools-EXT.h" |
---|
39 | #include "libmondo-verify-EXT.h" |
---|
40 | #include "libmondo-archive.h" |
---|
41 | |
---|
42 | #define DVDRWFORMAT 1 |
---|
43 | |
---|
44 | #ifndef _SEMUN_H |
---|
45 | #define _SEMUN_H |
---|
46 | |
---|
47 | /** |
---|
48 | * The semaphore union, provided only in case the user's system doesn't. |
---|
49 | */ |
---|
50 | union semun { |
---|
51 | int val; |
---|
52 | struct semid_ds *buf; |
---|
53 | unsigned short int *array; |
---|
54 | struct seminfo *__buf; |
---|
55 | }; |
---|
56 | #endif |
---|
57 | |
---|
58 | extern struct mr_ar_conf *mr_conf; |
---|
59 | |
---|
60 | /*@unused@*/ |
---|
61 | //static char cvsid[] = "$Id: libmondo-archive.c 1977 2008-06-02 08:49:01Z bruno $"; |
---|
62 | // |
---|
63 | extern char *get_non_rewind_dev(char *); |
---|
64 | |
---|
65 | /* *************************** external global vars ******************/ |
---|
66 | extern int g_current_media_number; |
---|
67 | extern int g_currentY; |
---|
68 | extern bool g_text_mode; |
---|
69 | extern bool g_exiting; |
---|
70 | extern long g_current_progress; |
---|
71 | extern FILE *g_tape_stream; |
---|
72 | extern long long g_tape_posK; |
---|
73 | extern char *g_tmpfs_mountpt; |
---|
74 | extern char *g_serial_string; |
---|
75 | extern char *g_getfacl; |
---|
76 | extern char *g_getfattr; |
---|
77 | extern char *MONDO_LOGFILE; |
---|
78 | |
---|
79 | /* Reference to global bkpinfo */ |
---|
80 | extern struct s_bkpinfo *bkpinfo; |
---|
81 | |
---|
82 | |
---|
83 | /** |
---|
84 | * @addtogroup globalGroup |
---|
85 | * @{ |
---|
86 | */ |
---|
87 | /** |
---|
88 | * The current backup media type in use. |
---|
89 | */ |
---|
90 | t_bkptype g_backup_media_type = none; |
---|
91 | char *g_backup_media_string = NULL; |
---|
92 | |
---|
93 | /** |
---|
94 | * Incremented by each archival thread when it starts up. After that, |
---|
95 | * this is the number of threads running. |
---|
96 | */ |
---|
97 | int g_current_thread_no = 0; |
---|
98 | |
---|
99 | /* @} - end of globalGroup */ |
---|
100 | |
---|
101 | extern int g_noof_rows; |
---|
102 | |
---|
103 | /* Semaphore-related code */ |
---|
104 | |
---|
105 | static int set_semvalue(void); |
---|
106 | static void del_semvalue(void); |
---|
107 | static int semaphore_p(void); |
---|
108 | static int semaphore_v(void); |
---|
109 | |
---|
110 | static int g_sem_id; |
---|
111 | static int g_sem_key; |
---|
112 | |
---|
113 | /** |
---|
114 | * Initialize the semaphore. |
---|
115 | * @see del_semvalue |
---|
116 | * @see semaphore_p |
---|
117 | * @see semaphore_v |
---|
118 | * @return 1 for success, 0 for failure. |
---|
119 | */ |
---|
120 | static int set_semvalue(void) // initializes semaphore |
---|
121 | { |
---|
122 | union semun sem_union; |
---|
123 | sem_union.val = 1; |
---|
124 | if (semctl(g_sem_id, 0, SETVAL, sem_union) == -1) { |
---|
125 | return (0); |
---|
126 | } |
---|
127 | return (1); |
---|
128 | } |
---|
129 | |
---|
130 | /** |
---|
131 | * Frees (deletes) the semaphore. Failure is indicated by a log |
---|
132 | * message. |
---|
133 | * @see set_semvalue |
---|
134 | */ |
---|
135 | static void del_semvalue(void) // deletes semaphore |
---|
136 | { |
---|
137 | union semun sem_union; |
---|
138 | |
---|
139 | if (semctl(g_sem_id, 0, IPC_RMID, sem_union) == -1) { |
---|
140 | mr_msg(3, "Failed to delete semaphore"); |
---|
141 | } |
---|
142 | } |
---|
143 | |
---|
144 | /** |
---|
145 | * Acquire (increment) the semaphore (change status to P). |
---|
146 | * @return 1 for success, 0 for failure. |
---|
147 | * @see semaphore_v |
---|
148 | */ |
---|
149 | static int semaphore_p(void) // changes status to 'P' (waiting) |
---|
150 | { |
---|
151 | struct sembuf sem_b; |
---|
152 | |
---|
153 | sem_b.sem_num = 0; |
---|
154 | sem_b.sem_op = -1; // P() |
---|
155 | sem_b.sem_flg = SEM_UNDO; |
---|
156 | if (semop(g_sem_id, &sem_b, 1) == -1) { |
---|
157 | mr_msg(3, "semaphore_p failed"); |
---|
158 | return (0); |
---|
159 | } |
---|
160 | return (1); |
---|
161 | } |
---|
162 | |
---|
163 | /** |
---|
164 | * Free (decrement) the semaphore (change status to V). |
---|
165 | * @return 1 for success, 0 for failure. |
---|
166 | */ |
---|
167 | static int semaphore_v(void) // changes status to 'V' (free) |
---|
168 | { |
---|
169 | struct sembuf sem_b; |
---|
170 | |
---|
171 | sem_b.sem_num = 0; |
---|
172 | sem_b.sem_op = 1; // V() |
---|
173 | sem_b.sem_flg = SEM_UNDO; |
---|
174 | if (semop(g_sem_id, &sem_b, 1) == -1) { |
---|
175 | mr_msg(3, "semaphore_v failed"); |
---|
176 | return (0); |
---|
177 | } |
---|
178 | return (1); |
---|
179 | } |
---|
180 | |
---|
181 | |
---|
182 | //------------------------------------------------------ |
---|
183 | |
---|
184 | |
---|
185 | /** |
---|
186 | * Size in megabytes of the buffer afforded to the executable "buffer". |
---|
187 | * This figure is used when we calculate how much data we have probably 'lost' |
---|
188 | * when writing off the end of tape N, so that we can then figure out how much |
---|
189 | * data we must recreate & write to the start of tape N+1. |
---|
190 | */ |
---|
191 | extern int g_tape_buffer_size_MB; |
---|
192 | |
---|
193 | |
---|
194 | |
---|
195 | |
---|
196 | int |
---|
197 | archive_this_fileset_with_star(char *filelist, char *fname, int setno) |
---|
198 | { |
---|
199 | int retval = 0; |
---|
200 | unsigned int res = 0; |
---|
201 | int tries = 0; |
---|
202 | char *command = NULL; |
---|
203 | char *tmp = NULL; |
---|
204 | char *p =NULL; |
---|
205 | char *tmp1 = NULL; |
---|
206 | |
---|
207 | malloc_string(tmp1); |
---|
208 | |
---|
209 | if (!does_file_exist(filelist)) { |
---|
210 | mr_asprintf(&tmp, |
---|
211 | "(archive_this_fileset) - filelist %s does not exist", |
---|
212 | filelist); |
---|
213 | log_to_screen(tmp); |
---|
214 | mr_free(tmp); |
---|
215 | return (1); |
---|
216 | } |
---|
217 | |
---|
218 | mr_asprintf(&tmp, "echo hi > %s 2> /dev/null", fname); |
---|
219 | if (system(tmp)) { |
---|
220 | fatal_error("Unable to write tarball to scratchdir"); |
---|
221 | } |
---|
222 | mr_free(tmp); |
---|
223 | |
---|
224 | mr_asprintf(&command, "star H=star list=%s -c " STAR_ACL_SZ " file=%s", |
---|
225 | filelist, fname); |
---|
226 | |
---|
227 | if (bkpinfo->compression_level > 0) { |
---|
228 | mr_asprintf(&tmp, "%s -bz", command); |
---|
229 | mr_free(command); |
---|
230 | command = tmp; |
---|
231 | } |
---|
232 | mr_asprintf(&tmp, "%s 2>> %s", command, MONDO_LOGFILE); |
---|
233 | mr_free(command); |
---|
234 | command = tmp; |
---|
235 | mr_msg(4, "command = '%s'", command); |
---|
236 | |
---|
237 | for (res = 99, tries = 0; tries < 3 && res != 0; tries++) { |
---|
238 | mr_msg(5, "command='%s'", command); |
---|
239 | res = system(command); |
---|
240 | strcpy(tmp1, last_line_of_file(MONDO_LOGFILE)); |
---|
241 | mr_msg(1, "res=%d; tmp='%s'", res, tmp); |
---|
242 | if (bkpinfo->use_star && (res == 254 || res == 65024) |
---|
243 | && strstr(tmp, "star: Processed all possible files") |
---|
244 | && tries > 0) { |
---|
245 | mr_msg(1, "Star returned nonfatal error"); |
---|
246 | res = 0; |
---|
247 | } |
---|
248 | if (res) { |
---|
249 | log_OS_error(command); |
---|
250 | p = strstr(command, "-acl "); |
---|
251 | if (p) { |
---|
252 | p[0] = p[1] = p[2] = p[3] = ' '; |
---|
253 | mr_msg(1, "new command = '%s'", command); |
---|
254 | } else { |
---|
255 | mr_msg(3, |
---|
256 | "Attempt #%d failed. Pausing 3 seconds and retrying...", |
---|
257 | tries + 1); |
---|
258 | sleep(3); |
---|
259 | } |
---|
260 | } |
---|
261 | } |
---|
262 | mr_free(command); |
---|
263 | |
---|
264 | retval += res; |
---|
265 | if (retval) { |
---|
266 | mr_msg(3, "Failed to write set %d", setno); |
---|
267 | } else if (tries > 1) { |
---|
268 | mr_msg(3, "Succeeded in writing set %d, on try #%d", setno, |
---|
269 | tries); |
---|
270 | } |
---|
271 | |
---|
272 | return (retval); |
---|
273 | } |
---|
274 | |
---|
275 | |
---|
276 | /** |
---|
277 | * Call @c afio to archive the filelist @c filelist to the file @c fname. |
---|
278 | * |
---|
279 | * @param bkpinfo The backup information structure. Fields used: |
---|
280 | * - @c compression_level |
---|
281 | * - @c scratchdir (only verifies existence) |
---|
282 | * - @c tmpdir (only verifies existence) |
---|
283 | * - @c compression_tool |
---|
284 | * - @c compression_suffix |
---|
285 | * @param filelist The path to a file containing a list of files to be archived |
---|
286 | * in this fileset. |
---|
287 | * @param fname The output file to archive to. |
---|
288 | * @param setno This fileset number. |
---|
289 | * @return The number of errors encountered (0 for success). |
---|
290 | * @ingroup LLarchiveGroup |
---|
291 | */ |
---|
292 | int |
---|
293 | archive_this_fileset(char *filelist, char *fname, int setno) |
---|
294 | { |
---|
295 | |
---|
296 | /*@ int ************************************************************ */ |
---|
297 | int retval = 0; |
---|
298 | int res = 0; |
---|
299 | int i = 0; |
---|
300 | int tries = 0; |
---|
301 | static int free_ramdisk_space = 9999; |
---|
302 | |
---|
303 | /*@ buffers ******************************************************** */ |
---|
304 | char *command = NULL; |
---|
305 | char *zipparams = NULL; |
---|
306 | char *tmp = NULL; |
---|
307 | char *tmp1 = NULL; |
---|
308 | |
---|
309 | assert(bkpinfo != NULL); |
---|
310 | assert_string_is_neither_NULL_nor_zerolength(filelist); |
---|
311 | assert_string_is_neither_NULL_nor_zerolength(fname); |
---|
312 | |
---|
313 | if (bkpinfo->compression_level > 0 && bkpinfo->use_star) { |
---|
314 | return (archive_this_fileset_with_star(filelist, fname, setno)); |
---|
315 | } |
---|
316 | |
---|
317 | if (!does_file_exist(filelist)) { |
---|
318 | mr_asprintf(&tmp, |
---|
319 | "(archive_this_fileset) - filelist %s does not exist", |
---|
320 | filelist); |
---|
321 | log_to_screen(tmp); |
---|
322 | mr_free(tmp); |
---|
323 | return (1); |
---|
324 | } |
---|
325 | mr_asprintf(&tmp, "echo hi > %s 2> /dev/null", fname); |
---|
326 | if (system(tmp)) { |
---|
327 | fatal_error("Unable to write tarball to scratchdir"); |
---|
328 | } |
---|
329 | mr_free(tmp); |
---|
330 | |
---|
331 | |
---|
332 | if (bkpinfo->compression_level > 0) { |
---|
333 | mr_asprintf(&zipparams, "-Z -P %s -G %d -T 3k", bkpinfo->compression_tool, |
---|
334 | bkpinfo->compression_level); |
---|
335 | mr_asprintf(&tmp, "%s/do-not-compress-these", MONDO_SHARE); |
---|
336 | if (does_file_exist(tmp)) { |
---|
337 | mr_asprintf(&tmp1, " -E +%s", tmp); |
---|
338 | mr_strcat(zipparams, tmp1); |
---|
339 | mr_free(tmp1); |
---|
340 | } else { |
---|
341 | mr_msg(3, "%s not found. Cannot exclude zipfiles, etc.", tmp); |
---|
342 | } |
---|
343 | mr_free(tmp); |
---|
344 | } else { |
---|
345 | mr_asprintf(&zipparams, " "); |
---|
346 | } |
---|
347 | |
---|
348 | // make_hole_for_file(fname); |
---|
349 | |
---|
350 | if (!does_file_exist(bkpinfo->tmpdir)) { |
---|
351 | log_OS_error("tmpdir not found"); |
---|
352 | fatal_error("tmpdir not found"); |
---|
353 | } |
---|
354 | if (!does_file_exist(bkpinfo->scratchdir)) { |
---|
355 | log_OS_error("scratchdir not found"); |
---|
356 | fatal_error("scratchdir not found"); |
---|
357 | } |
---|
358 | mr_asprintf(&command, "rm -f %s %s. %s.gz %s.%s", fname, fname, fname, |
---|
359 | fname, bkpinfo->compression_suffix); |
---|
360 | paranoid_system(command); |
---|
361 | mr_free(command); |
---|
362 | |
---|
363 | mr_asprintf(&command, "afio -o -b %ld -M 16m %s %s < %s 2>> %s", |
---|
364 | mr_conf->external_tape_blocksize, zipparams, fname, filelist, MONDO_LOGFILE); |
---|
365 | mr_free(zipparams); |
---|
366 | |
---|
367 | mr_asprintf(&tmp, "echo hi > %s 2> /dev/null", fname); |
---|
368 | if (system(tmp)) { |
---|
369 | fatal_error("Unable to write tarball to scratchdir"); |
---|
370 | } |
---|
371 | mr_free(tmp); |
---|
372 | |
---|
373 | for (res = 99, tries = 0; tries < 3 && res != 0; tries++) { |
---|
374 | mr_msg(5, "command='%s'", command); |
---|
375 | res = system(command); |
---|
376 | if (res) { |
---|
377 | log_OS_error(command); |
---|
378 | mr_msg(3, |
---|
379 | "Attempt #%d failed. Pausing 3 seconds and retrying...", |
---|
380 | tries + 1); |
---|
381 | sleep(3); |
---|
382 | } |
---|
383 | } |
---|
384 | mr_free(command); |
---|
385 | |
---|
386 | retval += res; |
---|
387 | if (retval) { |
---|
388 | mr_msg(3, "Failed to write set %d", setno); |
---|
389 | } else if (tries > 1) { |
---|
390 | mr_msg(3, "Succeeded in writing set %d, on try #%d", setno, |
---|
391 | tries); |
---|
392 | } |
---|
393 | |
---|
394 | if (g_tmpfs_mountpt[0] != '\0') { |
---|
395 | i = atoi(call_program_and_get_last_line_of_output |
---|
396 | ("df -m -P | grep dev/shm | grep -v none | tr -s ' ' '\t' | cut -f4")); |
---|
397 | if (i > 0) { |
---|
398 | if (free_ramdisk_space > i) { |
---|
399 | free_ramdisk_space = i; |
---|
400 | mr_msg(2, "min(free_ramdisk_space) is now %d", |
---|
401 | free_ramdisk_space); |
---|
402 | if (free_ramdisk_space < 10) { |
---|
403 | fatal_error |
---|
404 | ("Please increase PPCFG_RAMDISK_SIZE in my-stuff.h to increase size of ramdisk "); |
---|
405 | } |
---|
406 | } |
---|
407 | } |
---|
408 | } |
---|
409 | return (retval); |
---|
410 | } |
---|
411 | |
---|
412 | |
---|
413 | /** |
---|
414 | * Wrapper function for all the backup commands. |
---|
415 | * Calls these other functions: @c prepare_filelist(), |
---|
416 | * @c call_filelist_chopper(), @c copy_mondo_and_mindi_stuff_to_scratchdir(), |
---|
417 | * @c call_mindi_to_supply_boot_disks(), @c do_that_initial_phase(), |
---|
418 | * @c make_those_afios_phase(), @c make_those_slices_phase(), and |
---|
419 | * @c do_that_final_phase(). If anything fails before @c do_that_initial_phase(), |
---|
420 | * @c fatal_error is called with a suitable message. |
---|
421 | * @param bkpinfo The backup information structure. Uses most fields. |
---|
422 | * @return The number of non-fatal errors encountered (0 for success). |
---|
423 | * @ingroup archiveGroup |
---|
424 | */ |
---|
425 | int backup_data() |
---|
426 | { |
---|
427 | int retval = 0, res = 0; |
---|
428 | char *tmp = NULL; |
---|
429 | |
---|
430 | assert(bkpinfo != NULL); |
---|
431 | set_g_cdrom_and_g_dvd_to_bkpinfo_value(); |
---|
432 | |
---|
433 | if (bkpinfo->backup_media_type == dvd) { |
---|
434 | #ifdef DVDRWFORMAT |
---|
435 | if (!find_home_of_exe("dvd+rw-format")) { |
---|
436 | fatal_error |
---|
437 | ("Cannot find dvd+rw-format. Please install it or fix your PATH."); |
---|
438 | } |
---|
439 | #endif |
---|
440 | if (!find_home_of_exe("growisofs")) { |
---|
441 | fatal_error |
---|
442 | ("Cannot find growisofs. Please install it or fix your PATH."); |
---|
443 | } |
---|
444 | } |
---|
445 | |
---|
446 | if ((res = prepare_filelist())) { /* generate scratchdir/filelist.full */ |
---|
447 | fatal_error("Failed to generate filelist catalog"); |
---|
448 | } |
---|
449 | if (call_filelist_chopper()) { |
---|
450 | fatal_error("Failed to run filelist chopper"); |
---|
451 | } |
---|
452 | |
---|
453 | mr_asprintf(&tmp, "gzip -9 %s/archives/filelist.full", |
---|
454 | bkpinfo->scratchdir); |
---|
455 | if (run_program_and_log_output(tmp, 2)) { |
---|
456 | fatal_error("Failed to gzip filelist.full"); |
---|
457 | } |
---|
458 | mr_free(tmp); |
---|
459 | mr_asprintf(&tmp, "cp -f %s/archives/*list*.gz %s", bkpinfo->scratchdir, |
---|
460 | bkpinfo->tmpdir); |
---|
461 | if (run_program_and_log_output(tmp, 2)) { |
---|
462 | fatal_error("Failed to copy to tmpdir"); |
---|
463 | } |
---|
464 | mr_free(tmp); |
---|
465 | |
---|
466 | copy_mondo_and_mindi_stuff_to_scratchdir(); // payload, too, if it exists |
---|
467 | #if __FreeBSD__ == 5 |
---|
468 | mr_allocstr(bkpinfo->kernel_path, "/boot/kernel/kernel"); |
---|
469 | #elif __FreeBSD__ == 4 |
---|
470 | mr_allocstr(bkpinfo->kernel_path, "/kernel"); |
---|
471 | #elif linux |
---|
472 | if (figure_out_kernel_path_interactively_if_necessary |
---|
473 | (bkpinfo->kernel_path)) { |
---|
474 | fatal_error |
---|
475 | ("Kernel not found. Please specify manually with the '-k' switch."); |
---|
476 | } |
---|
477 | #else |
---|
478 | #error "I don't know about this system!" |
---|
479 | #endif |
---|
480 | if ((res = call_mindi_to_supply_boot_disks())) { |
---|
481 | fatal_error("Failed to generate boot+data disks"); |
---|
482 | } |
---|
483 | retval += do_that_initial_phase(); // prepare |
---|
484 | mr_asprintf(&tmp, "rm -f %s/images/*.iso", bkpinfo->scratchdir); |
---|
485 | run_program_and_log_output(tmp, 1); |
---|
486 | mr_free(tmp); |
---|
487 | retval += make_those_afios_phase(); // backup regular files |
---|
488 | retval += make_those_slices_phase(); // backup BIG files |
---|
489 | retval += do_that_final_phase(); // clean up |
---|
490 | mr_msg(1, "Creation of archives... complete."); |
---|
491 | if (bkpinfo->verify_data) { |
---|
492 | sleep(2); |
---|
493 | } |
---|
494 | return (retval); |
---|
495 | } |
---|
496 | |
---|
497 | |
---|
498 | /** |
---|
499 | * Call Mindi to generate boot and data disks. |
---|
500 | * @note This binds correctly to the new Perl version of mindi. |
---|
501 | * @param bkpinfo The backup information structure. Fields used: |
---|
502 | * - @c backup_media_type |
---|
503 | * - @c boot_loader |
---|
504 | * - @c boot_device |
---|
505 | * - @c compression_level |
---|
506 | * - @c differential |
---|
507 | * - @c exclude_paths |
---|
508 | * - @c image_devs |
---|
509 | * - @c kernel_path |
---|
510 | * - @c make_cd_use_lilo |
---|
511 | * - @c media_device |
---|
512 | * - @c media_size |
---|
513 | * - @c nonbootable_backup |
---|
514 | * - @c tmpdir |
---|
515 | * |
---|
516 | * @return The number of errors encountered (0 for success) |
---|
517 | * @bug The code to automagically determine the boot drive |
---|
518 | * is messy and system-dependent. In particular, it breaks |
---|
519 | * for Linux RAID and LVM users. |
---|
520 | * @ingroup MLarchiveGroup |
---|
521 | */ |
---|
522 | int call_mindi_to_supply_boot_disks() |
---|
523 | { |
---|
524 | /*@ buffer ************************************************************ */ |
---|
525 | char *tmp = NULL; |
---|
526 | char *tmp1 = NULL; |
---|
527 | char *tmp2 = NULL; |
---|
528 | char *command = NULL; |
---|
529 | char *bootldr_str = NULL; |
---|
530 | char *tape_device = NULL; |
---|
531 | char *last_filelist_number = NULL; |
---|
532 | char *broken_bios_sz = NULL; |
---|
533 | char *cd_recovery_sz = NULL; |
---|
534 | char *tape_size_sz = NULL; |
---|
535 | char *devs_to_exclude = NULL; |
---|
536 | char *use_lilo_sz = NULL; |
---|
537 | char *bootdev = NULL; |
---|
538 | char *ntapedev = NULL; |
---|
539 | |
---|
540 | /*@ char ************************************************************** */ |
---|
541 | char ch = '\0'; |
---|
542 | |
---|
543 | /*@ long ********************************************************** */ |
---|
544 | long lines_in_filelist = 0; |
---|
545 | |
---|
546 | /*@ int ************************************************************* */ |
---|
547 | int res = 0; |
---|
548 | long estimated_total_noof_slices = 0; |
---|
549 | |
---|
550 | FILE *fd = NULL; |
---|
551 | FILE *fd1 = NULL; |
---|
552 | |
---|
553 | assert(bkpinfo != NULL); |
---|
554 | malloc_string(last_filelist_number); |
---|
555 | malloc_string(devs_to_exclude); |
---|
556 | malloc_string(bootdev); |
---|
557 | |
---|
558 | mr_asprintf(&tmp, |
---|
559 | "echo '%s' | tr -s ' ' '\n' | grep -E '^/dev/.*$' | tr -s '\n' ' ' | awk '{print $0\"\\n\";}'", |
---|
560 | bkpinfo->exclude_paths); |
---|
561 | |
---|
562 | strcpy(devs_to_exclude, call_program_and_get_last_line_of_output(tmp)); |
---|
563 | mr_free(tmp); |
---|
564 | |
---|
565 | mr_asprintf(&tmp, "devs_to_exclude = '%s'", devs_to_exclude); |
---|
566 | mr_msg(2, tmp); |
---|
567 | mr_free(tmp); |
---|
568 | mvaddstr_and_log_it(g_currentY, 0, |
---|
569 | "Calling MINDI to create boot+data disks"); |
---|
570 | mr_asprintf(&tmp, "%s/filelist.full", bkpinfo->tmpdir); |
---|
571 | if (!does_file_exist(tmp)) { |
---|
572 | mr_free(tmp); |
---|
573 | mr_asprintf(&tmp, "%s/tmpfs/filelist.full", bkpinfo->tmpdir); |
---|
574 | if (!does_file_exist(tmp)) { |
---|
575 | fatal_error |
---|
576 | ("Cannot find filelist.full, so I cannot count its lines"); |
---|
577 | } |
---|
578 | } |
---|
579 | lines_in_filelist = count_lines_in_file(tmp); |
---|
580 | strcpy(last_filelist_number, last_line_of_file(tmp)); |
---|
581 | mr_free(tmp); |
---|
582 | |
---|
583 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { |
---|
584 | mr_asprintf(&tape_size_sz, "%ld", bkpinfo->media_size); |
---|
585 | ntapedev = get_non_rewind_dev(bkpinfo->media_device); |
---|
586 | if ((bkpinfo->use_obdr) && (ntapedev != NULL)) { |
---|
587 | mr_free(bkpinfo->media_device); |
---|
588 | bkpinfo->media_device = ntapedev; |
---|
589 | } else { |
---|
590 | if (ntapedev == NULL) { |
---|
591 | log_it("Not able to create OBDR - Restore will have to be done manually"); |
---|
592 | } |
---|
593 | } |
---|
594 | mr_asprintf(&tape_device, bkpinfo->media_device); |
---|
595 | } else { |
---|
596 | mr_asprintf(&tape_size_sz, " "); |
---|
597 | mr_asprintf(&tape_device, " "); |
---|
598 | } |
---|
599 | /* BERLIOS: This parameter is not used after? */ |
---|
600 | mr_free(tape_size_sz); |
---|
601 | |
---|
602 | mr_asprintf(&broken_bios_sz, "yes"); /* assume so */ |
---|
603 | if (g_cd_recovery) { |
---|
604 | mr_asprintf(&cd_recovery_sz, "yes"); |
---|
605 | } else { |
---|
606 | mr_asprintf(&cd_recovery_sz, "no"); |
---|
607 | } |
---|
608 | |
---|
609 | if (!bkpinfo->nonbootable_backup |
---|
610 | && (bkpinfo->boot_loader == '\0' |
---|
611 | || bkpinfo->boot_device[0] == '\0')) { |
---|
612 | |
---|
613 | #ifdef __FreeBSD__ |
---|
614 | strcpy(bootdev, call_program_and_get_last_line_of_output |
---|
615 | ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'")); |
---|
616 | if (!bootdev[0]) { |
---|
617 | strcpy(bootdev, call_program_and_get_last_line_of_output |
---|
618 | ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'")); |
---|
619 | } |
---|
620 | #else |
---|
621 | #ifdef __IA64__ |
---|
622 | strcpy(bootdev, call_program_and_get_last_line_of_output |
---|
623 | ("mount | grep ' /boot/efi ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'")); |
---|
624 | #else |
---|
625 | strcpy(bootdev, call_program_and_get_last_line_of_output |
---|
626 | ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'")); |
---|
627 | #endif |
---|
628 | if (strstr(bootdev, "/dev/cciss/")) { |
---|
629 | #ifdef __IA64__ |
---|
630 | strcpy(bootdev, call_program_and_get_last_line_of_output |
---|
631 | ("mount | grep ' /boot/efi ' | head -1 | cut -d' ' -f1 | cut -dp -f1")); |
---|
632 | #else |
---|
633 | strcpy(bootdev, call_program_and_get_last_line_of_output |
---|
634 | ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | cut -dp -f1")); |
---|
635 | #endif |
---|
636 | } |
---|
637 | if (!bootdev[0]) { |
---|
638 | strcpy(bootdev, call_program_and_get_last_line_of_output |
---|
639 | ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'")); |
---|
640 | if (strstr(bootdev, "/dev/cciss/")) { |
---|
641 | strcpy(bootdev, call_program_and_get_last_line_of_output |
---|
642 | ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | cut -dp -f1")); |
---|
643 | } |
---|
644 | } |
---|
645 | #endif |
---|
646 | if (bootdev[0]) |
---|
647 | ch = which_boot_loader(bootdev); |
---|
648 | else |
---|
649 | ch = 'U'; |
---|
650 | |
---|
651 | if (bkpinfo->boot_loader != '\0') { |
---|
652 | mr_asprintf(&tmp, "User specified boot loader. It is '%c'.", |
---|
653 | bkpinfo->boot_loader); |
---|
654 | mr_msg(2, tmp); |
---|
655 | mr_free(tmp); |
---|
656 | } else { |
---|
657 | bkpinfo->boot_loader = ch; |
---|
658 | } |
---|
659 | if (bkpinfo->boot_device[0] != '\0') { |
---|
660 | mr_asprintf(&tmp, "User specified boot device. It is '%s'.", |
---|
661 | bkpinfo->boot_device); |
---|
662 | mr_msg(2, tmp); |
---|
663 | mr_free(tmp); |
---|
664 | } else { |
---|
665 | strcpy(bkpinfo->boot_device, bootdev); |
---|
666 | } |
---|
667 | } |
---|
668 | |
---|
669 | if ( |
---|
670 | #ifdef __FreeBSD__ |
---|
671 | bkpinfo->boot_loader != 'B' && bkpinfo->boot_loader != 'D' && |
---|
672 | #endif |
---|
673 | #ifdef __IA64__ |
---|
674 | bkpinfo->boot_loader != 'E' && |
---|
675 | #endif |
---|
676 | bkpinfo->boot_loader != 'L' && bkpinfo->boot_loader != 'G' |
---|
677 | && bkpinfo->boot_loader != 'R' && !bkpinfo->nonbootable_backup) |
---|
678 | { |
---|
679 | fatal_error |
---|
680 | ("Please specify your boot loader and device, e.g. -l GRUB -f /dev/hda.\nType 'man mondoarchive' to read the manual."); |
---|
681 | } |
---|
682 | if (bkpinfo->boot_loader == 'L') { |
---|
683 | mr_asprintf(&bootldr_str, "LILO"); |
---|
684 | if (!does_file_exist("/etc/lilo.conf")) { |
---|
685 | fatal_error |
---|
686 | ("The de facto standard location for your boot loader's config file is /etc/lilo.conf.\nBut I cannot find it there. What is wrong with your Linux distribution?"); |
---|
687 | } |
---|
688 | } else if (bkpinfo->boot_loader == 'G') { |
---|
689 | mr_asprintf(&bootldr_str, "GRUB"); |
---|
690 | if (!does_file_exist("/etc/grub.conf") |
---|
691 | && does_file_exist("/boot/grub/grub.conf")) { |
---|
692 | run_program_and_log_output |
---|
693 | ("ln -sf /boot/grub/grub.conf /etc/grub.conf", 5); |
---|
694 | } |
---|
695 | /* Detect Debian's grub config file */ |
---|
696 | else if (!does_file_exist("/etc/grub.conf") |
---|
697 | && does_file_exist("/boot/grub/menu.lst")) { |
---|
698 | run_program_and_log_output |
---|
699 | ("ln -s /boot/grub/menu.lst /etc/grub.conf", 5); |
---|
700 | } |
---|
701 | if (!does_file_exist("/etc/grub.conf")) { |
---|
702 | fatal_error |
---|
703 | ("The de facto standard location for your boot loader's config file is /etc/grub.conf.\nBut I cannot find it there. What is wrong with your Linux distribution?\nTry 'ln -s /boot/grub/menu.lst /etc/grub.conf'..."); |
---|
704 | } |
---|
705 | } else if (bkpinfo->boot_loader == 'E') { |
---|
706 | mr_asprintf(&bootldr_str, "ELILO"); |
---|
707 | /* BERLIOS: fix it for Debian, Mandrake, ... */ |
---|
708 | if (!does_file_exist("/etc/elilo.conf") |
---|
709 | && does_file_exist("/boot/efi/efi/redhat/elilo.conf")) { |
---|
710 | run_program_and_log_output |
---|
711 | ("ln -sf /boot/efi/efi/redhat/elilo.conf /etc/elilo.conf", |
---|
712 | 5); |
---|
713 | } |
---|
714 | if (!does_file_exist("/etc/elilo.conf") |
---|
715 | && does_file_exist("/boot/efi/efi/SuSE/elilo.conf")) { |
---|
716 | run_program_and_log_output |
---|
717 | ("ln -sf /boot/efi/efi/SuSE/elilo.conf /etc/elilo.conf", |
---|
718 | 5); |
---|
719 | } |
---|
720 | if (!does_file_exist("/etc/elilo.conf") |
---|
721 | && does_file_exist("/boot/efi/efi/debian/elilo.conf")) { |
---|
722 | run_program_and_log_output |
---|
723 | ("ln -sf /boot/efi/efi/debian/elilo.conf /etc/elilo.conf", |
---|
724 | 5); |
---|
725 | } |
---|
726 | if (!does_file_exist("/etc/elilo.conf") |
---|
727 | && does_file_exist("/boot/efi/debian/elilo.conf")) { |
---|
728 | run_program_and_log_output |
---|
729 | ("ln -sf /boot/efi/debian/elilo.conf /etc/elilo.conf", |
---|
730 | 5); |
---|
731 | } |
---|
732 | if (!does_file_exist("/etc/elilo.conf")) { |
---|
733 | fatal_error |
---|
734 | ("The de facto mondo standard location for your boot loader's config file is /etc/elilo.conf\nBut I cannot find it there. What is wrong with your Linux distribution?\nTry finding it under /boot/efi and do 'ln -s /boot/efi/..../elilo.conf /etc/elilo.conf'"); |
---|
735 | } |
---|
736 | } else if (bkpinfo->boot_loader == 'R') { |
---|
737 | mr_asprintf(&bootldr_str, "RAW"); |
---|
738 | } |
---|
739 | #ifdef __FreeBSD__ |
---|
740 | else if (bkpinfo->boot_loader == 'D') { |
---|
741 | mr_asprintf(&bootldr_str, "DD"); |
---|
742 | } |
---|
743 | |
---|
744 | else if (bkpinfo->boot_loader == 'B') { |
---|
745 | mr_asprintf(&bootldr_str, "BOOT0"); |
---|
746 | } |
---|
747 | #endif |
---|
748 | else { |
---|
749 | mr_asprintf(&bootldr_str, "unknown"); |
---|
750 | } |
---|
751 | mr_asprintf(&tmp, "Your boot loader is %s and it boots from %s", |
---|
752 | bootldr_str, bkpinfo->boot_device); |
---|
753 | log_to_screen(tmp); |
---|
754 | mr_free(tmp); |
---|
755 | mr_asprintf(&tmp, "%s/BOOTLOADER.DEVICE", bkpinfo->tmpdir); |
---|
756 | if (write_one_liner_data_file(tmp, bkpinfo->boot_device)) { |
---|
757 | mr_msg(1, "Unable to write one-liner boot device"); |
---|
758 | } |
---|
759 | |
---|
760 | estimated_total_noof_slices = |
---|
761 | size_of_all_biggiefiles_K(bkpinfo) / bkpinfo->optimal_set_size + 1; |
---|
762 | mr_asprintf(&command, "mkdir -p %s/images", bkpinfo->scratchdir); |
---|
763 | if (system(command)) { |
---|
764 | res++; |
---|
765 | log_OS_error("Unable to make images directory"); |
---|
766 | } |
---|
767 | mr_free(command); |
---|
768 | |
---|
769 | /* Prepare interface with mindi through a configuration file |
---|
770 | * under /var/cache/mondo by default |
---|
771 | * and the mondorestore configuration file at the same time that |
---|
772 | * will be included by mindi on the initrd */ |
---|
773 | |
---|
774 | fd = mr_fopen(MONDO_CACHE"/mindi.conf", "w"); |
---|
775 | fd1 = mr_fopen(MONDORESTORECFG, "a"); |
---|
776 | |
---|
777 | mr_fprintf(fd, "mindi_use_own_kernel=yes\n"); |
---|
778 | if (strcmp(mr_conf->mondo_kernel,"FAILSAFE") == 0) { |
---|
779 | } else { |
---|
780 | } |
---|
781 | mr_fprintf(fd, "mindi_kernel=%s\n", bkpinfo->kernel_path); |
---|
782 | mr_fprintf(fd, "mindi_additional_mods=%s\n", mr_conf->additional_modules); |
---|
783 | |
---|
784 | mr_fprintf(fd1, "files-in-filelist=%ld\n", lines_in_filelist); |
---|
785 | mr_fprintf(fd1, "internal-tape-block-size=%ld\n", bkpinfo->internal_tape_block_size); |
---|
786 | mr_fprintf(fd1, "total-slices=%ld\n", estimated_total_noof_slices); |
---|
787 | mr_fprintf(fd1, "excluded-devs=%s\n", devs_to_exclude); |
---|
788 | mr_fprintf(fd1, "image-devs=%s\n", bkpinfo->image_devs); |
---|
789 | mr_fprintf(fd1, "last-filelist-number=%s\n", last_filelist_number); |
---|
790 | mr_fprintf(fd1, "bootloader.name=%s\n", bootldr_str); |
---|
791 | mr_fprintf(fd1, "bootloader.device=%s\n", bkpinfo->boot_device); |
---|
792 | |
---|
793 | mr_free(bootldr_str); |
---|
794 | |
---|
795 | switch (bkpinfo->backup_media_type) { |
---|
796 | case cdr: |
---|
797 | mr_fprintf(fd1, "backup-media-type=cdr\n"); |
---|
798 | break; |
---|
799 | case cdrw: |
---|
800 | mr_fprintf(fd1, "backup-media-type=cdrw\n"); |
---|
801 | break; |
---|
802 | case cdstream: |
---|
803 | mr_fprintf(fd1, "backup-media-type=cdstream\n"); |
---|
804 | break; |
---|
805 | case tape: |
---|
806 | mr_fprintf(fd1, "backup-media-type=tape\n"); |
---|
807 | break; |
---|
808 | case udev: |
---|
809 | mr_fprintf(fd1, "backup-media-type=udev\n"); |
---|
810 | break; |
---|
811 | case iso: |
---|
812 | mr_fprintf(fd1, "backup-media-type=iso\n"); |
---|
813 | break; |
---|
814 | case nfs: |
---|
815 | mr_fprintf(fd1, "backup-media-type=nfs\n"); |
---|
816 | break; |
---|
817 | case dvd: |
---|
818 | mr_fprintf(fd1, "backup-media-type=dvd\n"); |
---|
819 | break; |
---|
820 | case usb: |
---|
821 | mr_fprintf(fd1, "backup-media-type=usb\n"); |
---|
822 | break; |
---|
823 | default: |
---|
824 | fatal_error("Unknown backup_media_type"); |
---|
825 | } |
---|
826 | |
---|
827 | if (bkpinfo->backup_media_type == usb) { |
---|
828 | mr_fprintf(fd, "mindi_write_usb=yes\n"); |
---|
829 | mr_fprintf(fd, "mindi_usb_device=%s\n", bkpinfo->media_device); |
---|
830 | } |
---|
831 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { |
---|
832 | mr_fprintf(fd, "mindi_write_tape=yes\n"); |
---|
833 | mr_fprintf(fd, "mindi_tape_device=%s\n", bkpinfo->media_device); |
---|
834 | mr_fprintf(fd1, "media-dev=%s\n", bkpinfo->media_device); |
---|
835 | mr_fprintf(fd1, "media-size=%ld\n", bkpinfo->media_size); |
---|
836 | } |
---|
837 | if (bkpinfo->compression_level > 0) { |
---|
838 | mr_fprintf(fd1, "use-comp=yes\n"); |
---|
839 | } else { |
---|
840 | mr_fprintf(fd1, "use-comp=no\n"); |
---|
841 | } |
---|
842 | if (bkpinfo->compression_tool) { |
---|
843 | mr_fprintf(fd1, "compression_tool=%s\n",bkpinfo->compression_tool); |
---|
844 | } |
---|
845 | if (bkpinfo->compression_suffix) { |
---|
846 | mr_fprintf(fd1, "compression_suffix=%s\n",bkpinfo->compression_suffix); |
---|
847 | } |
---|
848 | if (bkpinfo->compression_type != none) { |
---|
849 | mr_fprintf(fd1, "compression_type=%d\n",bkpinfo->compression_type); |
---|
850 | } |
---|
851 | if (bkpinfo->use_star) { |
---|
852 | mr_fprintf(fd1, "use-star=yes\n"); |
---|
853 | } else { |
---|
854 | mr_fprintf(fd1, "use-star=no\n"); |
---|
855 | } |
---|
856 | if (g_getfattr) { |
---|
857 | mr_fprintf(fd1, "xattr=yes\n"); |
---|
858 | } else { |
---|
859 | mr_fprintf(fd1, "xattr=no\n"); |
---|
860 | } |
---|
861 | if (g_getfacl) { |
---|
862 | mr_fprintf(fd1, "acl=yes\n"); |
---|
863 | } else { |
---|
864 | mr_fprintf(fd1, "acl=no\n"); |
---|
865 | } |
---|
866 | if (bkpinfo->use_obdr) { |
---|
867 | asprintf(&tmp1, "%s/OBDR", bkpinfo->tmpdir); |
---|
868 | if (write_one_liner_data_file(tmp1, "TRUE")) { |
---|
869 | log_msg(1, "%ld: Unable to write one-liner OBDR", |
---|
870 | __LINE__); |
---|
871 | } |
---|
872 | paranoid_free(tmp1); |
---|
873 | } |
---|
874 | |
---|
875 | if (g_cd_recovery) { |
---|
876 | mr_fprintf(fd1, "use-cdrecovery=yes\n"); |
---|
877 | } else { |
---|
878 | mr_fprintf(fd1, "use-cdrecovery=no\n"); |
---|
879 | } |
---|
880 | |
---|
881 | if (bkpinfo->make_cd_use_lilo) { |
---|
882 | mr_fprintf(fd1, "use-lilo=yes\n"); |
---|
883 | } else { |
---|
884 | mr_fprintf(fd1, "use-lilo=no\n"); |
---|
885 | } |
---|
886 | if (bkpinfo->nonbootable_backup) { |
---|
887 | mr_fprintf(fd1, "non-bootable=yes\n"); |
---|
888 | } else { |
---|
889 | mr_fprintf(fd1, "non-bootable=no\n"); |
---|
890 | } |
---|
891 | if (bkpinfo->differential) { |
---|
892 | mr_fprintf(fd1, "differential=yes\n"); |
---|
893 | } else { |
---|
894 | mr_fprintf(fd1, "differential=no\n"); |
---|
895 | } |
---|
896 | if (mr_conf->mondo_create_mindi_cd) { |
---|
897 | mr_fprintf(fd1, "mindi_write_cd=yes\n"); |
---|
898 | } else { |
---|
899 | mr_fprintf(fd1, "mindi_write_cd=no\n"); |
---|
900 | } |
---|
901 | |
---|
902 | mr_fclose(fd); |
---|
903 | mr_fprintf(fd1, "datestamp=%s\n", mr_date()); |
---|
904 | mr_fclose(fd1); |
---|
905 | |
---|
906 | mr_asprintf(&command, "mindi --custom '%s' '%s/images'", |
---|
907 | bkpinfo->tmpdir, bkpinfo->scratchdir); |
---|
908 | //bkpinfo->tmpdir, // parameter #2 |
---|
909 | //bkpinfo->scratchdir, // parameter #3 |
---|
910 | //bkpinfo->kernel_path, // parameter #4 |
---|
911 | //tape_device, // parameter #5 |
---|
912 | //tape_size_sz, // parameter #6 |
---|
913 | //lines_in_filelist, // parameter #7 (INT) |
---|
914 | //use_lzo_sz, // parameter #8 |
---|
915 | //cd_recovery_sz, // parameter #9 |
---|
916 | //bkpinfo->image_devs, // parameter #10 |
---|
917 | //broken_bios_sz, // parameter #11 always yes |
---|
918 | //last_filelist_number, // parameter #12 (STRING) |
---|
919 | //estimated_total_noof_slices, // parameter #13 (INT) |
---|
920 | //devs_to_exclude, // parameter #14 |
---|
921 | //use_comp_sz, // parameter #15 |
---|
922 | //use_lilo_sz, // parameter #16 |
---|
923 | //use_star_sz, // parameter #17 |
---|
924 | //bkpinfo->internal_tape_block_size, // parameter #18 (LONG) |
---|
925 | //bkpinfo->differential, // parameter #19 (INT) |
---|
926 | //use_gzip_sz); // parameter #20 (STRING) |
---|
927 | |
---|
928 | mr_msg(2, command); |
---|
929 | |
---|
930 | res = run_program_and_log_to_screen(command, "Generating boot+data disks"); |
---|
931 | mr_free(command); |
---|
932 | if (bkpinfo->nonbootable_backup) { |
---|
933 | res = 0; |
---|
934 | } // hack |
---|
935 | if (!res) { |
---|
936 | log_to_screen("Boot+data disks were created OK"); |
---|
937 | mr_asprintf(&command, "mkdir -p "MINDI_CACHE); |
---|
938 | mr_msg(2, command); |
---|
939 | run_program_and_log_output(command, FALSE); |
---|
940 | mr_free(command); |
---|
941 | |
---|
942 | mr_asprintf(&command, |
---|
943 | "cp -f %s/images/mindi.iso %s/mondorescue.iso", |
---|
944 | bkpinfo->scratchdir, MINDI_CACHE); |
---|
945 | mr_msg(2, command); |
---|
946 | run_program_and_log_output(command, FALSE); |
---|
947 | mr_free(command); |
---|
948 | |
---|
949 | if (bkpinfo->nonbootable_backup) { |
---|
950 | mr_asprintf(&command, "cp -f %s/all.tar.gz %s/images", |
---|
951 | bkpinfo->tmpdir, bkpinfo->scratchdir); |
---|
952 | if (system(command)) { |
---|
953 | fatal_error("Unable to create temporary all tarball"); |
---|
954 | } |
---|
955 | mr_free(command); |
---|
956 | |
---|
957 | } |
---|
958 | /* BERLIOS: Not executed ? |
---|
959 | sprintf(command, "cp -f %s/mindi-*oot*.img %s/images", |
---|
960 | */ |
---|
961 | /* For USB we already have everything on the key */ |
---|
962 | if (bkpinfo->backup_media_type == usb) { |
---|
963 | mr_asprintf(&command, "rm -rf %s/images", bkpinfo->scratchdir); |
---|
964 | run_program_and_log_output(command, FALSE); |
---|
965 | mr_free(command); |
---|
966 | } else { |
---|
967 | mr_asprintf(&tmp, "cp -f %s/images/all.tar.gz %s", |
---|
968 | bkpinfo->scratchdir, bkpinfo->tmpdir); |
---|
969 | if (system(tmp)) { |
---|
970 | fatal_error("Cannot find all.tar.gz in tmpdir"); |
---|
971 | mr_free(tmp); |
---|
972 | } |
---|
973 | } |
---|
974 | |
---|
975 | if (res) { |
---|
976 | mvaddstr_and_log_it(g_currentY++, 74, "Errors."); |
---|
977 | } else { |
---|
978 | mvaddstr_and_log_it(g_currentY++, 74, "Done."); |
---|
979 | } |
---|
980 | } else { |
---|
981 | log_to_screen("Mindi failed to create your boot+data disks."); |
---|
982 | mr_asprintf(&command, "grep 'Fatal error' /var/log/mindi.log"); |
---|
983 | malloc_string(tmp); |
---|
984 | strcpy(tmp,call_program_and_get_last_line_of_output(command)); |
---|
985 | mr_free(command); |
---|
986 | if (strlen(tmp) > 1) { |
---|
987 | popup_and_OK(tmp); |
---|
988 | } |
---|
989 | mr_free(tmp); |
---|
990 | } |
---|
991 | mr_free(last_filelist_number); |
---|
992 | mr_free(devs_to_exclude); |
---|
993 | mr_free(bootdev); |
---|
994 | return (res); |
---|
995 | } |
---|
996 | |
---|
997 | |
---|
998 | /** |
---|
999 | * Maximum number of filesets allowed in this function. |
---|
1000 | */ |
---|
1001 | #define MAX_NOOF_SETS_HERE 32767 |
---|
1002 | |
---|
1003 | /** |
---|
1004 | * Offset of the bkpinfo pointer (in bytes) from the |
---|
1005 | * buffer passed to create_afio_files_in_background. |
---|
1006 | */ |
---|
1007 | #define BKPINFO_LOC_OFFSET (16+MAX_NOOF_SETS_HERE/8+16) |
---|
1008 | |
---|
1009 | /** |
---|
1010 | * Main function for each @c afio thread. |
---|
1011 | * @param inbuf A transfer block containing: |
---|
1012 | * - @c p_last_set_archived: [offset 0] pointer to an @c int |
---|
1013 | * containing the last set archived. |
---|
1014 | * - @c p_archival_threads_running: [offset 4] pointer to an @c int |
---|
1015 | * containing the number of archival threads currently running. |
---|
1016 | * - @c p_next_set_to_archive: [offset 8] pointer to an @c int containing |
---|
1017 | * the next set that should be archived. |
---|
1018 | * - @c p_list_of_fileset_flags: [offset 12] @c char pointer pointing to a |
---|
1019 | * bit array, where each bit corresponds to a filelist (1=needs |
---|
1020 | * to be archived, 0=archived). |
---|
1021 | * - @c bkpinfo: [offset BKPINFO_LOC_OFFSET] pointer to backup information |
---|
1022 | * structure. Fields used: |
---|
1023 | * - @c tmpdir |
---|
1024 | * - @c compression_suffix |
---|
1025 | * |
---|
1026 | * Any of the above may be modified by the caller at any time. |
---|
1027 | * |
---|
1028 | * @bug Assumes @c int pointers are 4 bytes. |
---|
1029 | * @see archive_this_fileset |
---|
1030 | * @see make_afioballs_and_images |
---|
1031 | * @return NULL, always. |
---|
1032 | * @ingroup LLarchiveGroup |
---|
1033 | */ |
---|
1034 | void *create_afio_files_in_background(void *inbuf) |
---|
1035 | { |
---|
1036 | long int archiving_set_no; |
---|
1037 | char *archiving_filelist_fname; |
---|
1038 | char *archiving_afioball_fname; |
---|
1039 | char *curr_xattr_list_fname = NULL; |
---|
1040 | char *curr_acl_list_fname; |
---|
1041 | |
---|
1042 | struct s_bkpinfo *bkpinfo_bis; |
---|
1043 | char *tmp = NULL; |
---|
1044 | int res = 0, retval = 0; |
---|
1045 | int *p_archival_threads_running; |
---|
1046 | int *p_last_set_archived; |
---|
1047 | int *p_next_set_to_archive; |
---|
1048 | char *p_list_of_fileset_flags; |
---|
1049 | int this_thread_no = g_current_thread_no++; |
---|
1050 | |
---|
1051 | malloc_string(archiving_filelist_fname); |
---|
1052 | malloc_string(archiving_afioball_fname); |
---|
1053 | p_last_set_archived = (int *) inbuf; |
---|
1054 | p_archival_threads_running = (int *) (inbuf + 4); |
---|
1055 | p_next_set_to_archive = (int *) (inbuf + 8); |
---|
1056 | p_list_of_fileset_flags = (char *) (inbuf + 12); |
---|
1057 | bkpinfo_bis = (struct s_bkpinfo *) (inbuf + BKPINFO_LOC_OFFSET); |
---|
1058 | |
---|
1059 | sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ, |
---|
1060 | bkpinfo->tmpdir, 0L); |
---|
1061 | for (archiving_set_no = 0; does_file_exist(archiving_filelist_fname); |
---|
1062 | sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ, |
---|
1063 | bkpinfo->tmpdir, archiving_set_no)) { |
---|
1064 | if (g_exiting) { |
---|
1065 | fatal_error("Execution run aborted (pthread)"); |
---|
1066 | } |
---|
1067 | if (archiving_set_no >= MAX_NOOF_SETS_HERE) { |
---|
1068 | fatal_error |
---|
1069 | ("Maximum number of filesets exceeded. Adjust MAX_NOOF_SETS_HERE, please."); |
---|
1070 | } |
---|
1071 | if (!semaphore_p()) { |
---|
1072 | mr_msg(3, "P sem failed (pid=%d)", (int) getpid()); |
---|
1073 | fatal_error("Cannot get semaphore P"); |
---|
1074 | } |
---|
1075 | if (archiving_set_no < *p_next_set_to_archive) { |
---|
1076 | archiving_set_no = *p_next_set_to_archive; |
---|
1077 | } |
---|
1078 | *p_next_set_to_archive = *p_next_set_to_archive + 1; |
---|
1079 | if (!semaphore_v()) { |
---|
1080 | fatal_error("Cannot get semaphore V"); |
---|
1081 | } |
---|
1082 | |
---|
1083 | /* backup this set of files */ |
---|
1084 | sprintf(archiving_afioball_fname, AFIOBALL_FNAME_RAW_SZ, |
---|
1085 | bkpinfo->tmpdir, archiving_set_no, bkpinfo->compression_suffix); |
---|
1086 | sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ, |
---|
1087 | bkpinfo->tmpdir, archiving_set_no); |
---|
1088 | if (!does_file_exist(archiving_filelist_fname)) { |
---|
1089 | mr_msg(3, |
---|
1090 | "[%d:%d] - well, I would archive %d, except that it doesn't exist. I'll stop now.", |
---|
1091 | getpid(), this_thread_no, |
---|
1092 | archiving_set_no); |
---|
1093 | break; |
---|
1094 | } |
---|
1095 | |
---|
1096 | mr_asprintf(&tmp, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir, |
---|
1097 | archiving_set_no - ARCH_BUFFER_NUM, bkpinfo->compression_suffix); |
---|
1098 | if (does_file_exist(tmp)) { |
---|
1099 | mr_msg(4, "[%d:%d] - waiting for storer", |
---|
1100 | getpid(), this_thread_no); |
---|
1101 | while (does_file_exist(tmp)) { |
---|
1102 | sleep(1); |
---|
1103 | } |
---|
1104 | mr_msg(4, "[%d] - continuing", getpid()); |
---|
1105 | } |
---|
1106 | mr_free(tmp); |
---|
1107 | |
---|
1108 | mr_msg(4, "[%d:%d] - EXATing %d...", getpid(), |
---|
1109 | this_thread_no, archiving_set_no); |
---|
1110 | if (g_getfattr) { |
---|
1111 | mr_asprintf(&curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, |
---|
1112 | bkpinfo->tmpdir, archiving_set_no); |
---|
1113 | get_fattr_list(archiving_filelist_fname, curr_xattr_list_fname); |
---|
1114 | mr_free(curr_xattr_list_fname); |
---|
1115 | } |
---|
1116 | if (g_getfacl) { |
---|
1117 | mr_asprintf(&curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, |
---|
1118 | bkpinfo->tmpdir, archiving_set_no); |
---|
1119 | get_acl_list(archiving_filelist_fname, curr_acl_list_fname); |
---|
1120 | mr_free(curr_acl_list_fname); |
---|
1121 | } |
---|
1122 | |
---|
1123 | mr_msg(4, "[%d:%d] - archiving %d...", getpid(), |
---|
1124 | this_thread_no, archiving_set_no); |
---|
1125 | res = |
---|
1126 | archive_this_fileset(archiving_filelist_fname, |
---|
1127 | archiving_afioball_fname, |
---|
1128 | archiving_set_no); |
---|
1129 | retval += res; |
---|
1130 | |
---|
1131 | if (res) { |
---|
1132 | mr_asprintf(&tmp, |
---|
1133 | "Errors occurred while archiving set %ld. Please review logs.", |
---|
1134 | archiving_set_no); |
---|
1135 | log_to_screen(tmp); |
---|
1136 | mr_free(tmp); |
---|
1137 | } |
---|
1138 | if (!semaphore_p()) { |
---|
1139 | fatal_error("Cannot get semaphore P"); |
---|
1140 | } |
---|
1141 | |
---|
1142 | set_bit_N_of_array(p_list_of_fileset_flags, archiving_set_no, 5); |
---|
1143 | |
---|
1144 | if (*p_last_set_archived < archiving_set_no) { |
---|
1145 | *p_last_set_archived = archiving_set_no; |
---|
1146 | } // finished archiving this one |
---|
1147 | |
---|
1148 | if (!semaphore_v()) { |
---|
1149 | fatal_error("Cannot get semaphore V"); |
---|
1150 | } |
---|
1151 | mr_msg(4, "[%d:%d] - archived %d OK", getpid(), |
---|
1152 | this_thread_no, archiving_set_no); |
---|
1153 | archiving_set_no++; |
---|
1154 | } |
---|
1155 | if (!semaphore_p()) { |
---|
1156 | fatal_error("Cannot get semaphore P"); |
---|
1157 | } |
---|
1158 | (*p_archival_threads_running)--; |
---|
1159 | if (!semaphore_v()) { |
---|
1160 | fatal_error("Cannot get semaphore V"); |
---|
1161 | } |
---|
1162 | mr_msg(3, "[%d:%d] - exiting", getpid(), |
---|
1163 | this_thread_no); |
---|
1164 | mr_free(archiving_filelist_fname); |
---|
1165 | mr_free(archiving_afioball_fname); |
---|
1166 | pthread_exit(NULL); |
---|
1167 | } |
---|
1168 | |
---|
1169 | |
---|
1170 | /** |
---|
1171 | * Finalize the backup. |
---|
1172 | * For streaming backups, this writes the closing block |
---|
1173 | * to the stream. For CD-based backups, this creates |
---|
1174 | * the final ISO image. |
---|
1175 | * @param bkpinfo The backup information structure, used only |
---|
1176 | * for the @c backup_media_type. |
---|
1177 | * @ingroup MLarchiveGroup |
---|
1178 | */ |
---|
1179 | int do_that_final_phase() |
---|
1180 | { |
---|
1181 | |
---|
1182 | /*@ int ************************************** */ |
---|
1183 | int res = 0; |
---|
1184 | int retval = 0; |
---|
1185 | |
---|
1186 | /*@ buffers ********************************** */ |
---|
1187 | |
---|
1188 | assert(bkpinfo != NULL); |
---|
1189 | mvaddstr_and_log_it(g_currentY, 0, |
---|
1190 | "Writing any remaining data to media "); |
---|
1191 | |
---|
1192 | mr_msg(1, "Closing tape/CD/USB ... "); |
---|
1193 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { |
---|
1194 | /* write tape/cdstream */ |
---|
1195 | closeout_tape(); |
---|
1196 | } else { |
---|
1197 | /* write final ISO/USB */ |
---|
1198 | res = write_final_iso_if_necessary(); |
---|
1199 | retval += res; |
---|
1200 | if (res) { |
---|
1201 | mr_msg(1, "write_final_iso_if_necessary returned an error"); |
---|
1202 | } |
---|
1203 | } |
---|
1204 | mr_msg(2, "Fork is exiting ... "); |
---|
1205 | |
---|
1206 | mvaddstr_and_log_it(g_currentY++, 74, "Done."); |
---|
1207 | |
---|
1208 | /* final stuff */ |
---|
1209 | if (retval) { |
---|
1210 | mvaddstr_and_log_it(g_currentY++, 74, "Errors."); |
---|
1211 | } else { |
---|
1212 | mvaddstr_and_log_it(g_currentY++, 74, "Done."); |
---|
1213 | } |
---|
1214 | |
---|
1215 | return (retval); |
---|
1216 | } |
---|
1217 | |
---|
1218 | |
---|
1219 | /** |
---|
1220 | * Initialize the backup. |
---|
1221 | * Does the following: |
---|
1222 | * - Sets up the serial number. |
---|
1223 | * - For streaming backups, opens the tape stream and writes the data disks |
---|
1224 | * and backup headers. |
---|
1225 | * - For CD-based backups, wipes the ISOs in the target directory. |
---|
1226 | * |
---|
1227 | * @param bkpinfo The backup information structure. Fields used: |
---|
1228 | * - @c backup_media_type |
---|
1229 | * - @c writer_speed |
---|
1230 | * - @c prefix |
---|
1231 | * - @c isodir |
---|
1232 | * - @c media_device |
---|
1233 | * - @c scratchdir |
---|
1234 | * - @c tmpdir |
---|
1235 | * @return The number of errors encountered (0 for success). |
---|
1236 | * @ingroup MLarchiveGroup |
---|
1237 | */ |
---|
1238 | int do_that_initial_phase() |
---|
1239 | { |
---|
1240 | /*@ int *************************************** */ |
---|
1241 | int retval = 0; |
---|
1242 | |
---|
1243 | /*@ buffers *********************************** */ |
---|
1244 | char *command, *tmp_file, *data_disks_file; |
---|
1245 | |
---|
1246 | assert(bkpinfo != NULL); |
---|
1247 | malloc_string(command); |
---|
1248 | |
---|
1249 | mr_asprintf(&data_disks_file, "%s/all.tar.gz", bkpinfo->tmpdir); |
---|
1250 | |
---|
1251 | snprintf(g_serial_string, MAX_STR_LEN - 1, |
---|
1252 | call_program_and_get_last_line_of_output("dd \ |
---|
1253 | if=/dev/urandom bs=16 count=1 2> /dev/null | \ |
---|
1254 | hexdump | tr -s ' ' '0' | head -n1")); |
---|
1255 | mr_strip_spaces(g_serial_string); |
---|
1256 | strcat(g_serial_string, "...word."); |
---|
1257 | mr_msg(2, "g_serial_string = '%s'", g_serial_string); |
---|
1258 | assert(strlen(g_serial_string) < MAX_STR_LEN); |
---|
1259 | |
---|
1260 | mr_asprintf(&tmp_file, "%s/archives/SERIAL-STRING", bkpinfo->scratchdir); |
---|
1261 | if (write_one_liner_data_file(tmp_file, g_serial_string)) { |
---|
1262 | mr_msg(1, "%ld: Failed to write serial string", __LINE__); |
---|
1263 | } |
---|
1264 | mr_free(tmp_file); |
---|
1265 | |
---|
1266 | mvaddstr_and_log_it(g_currentY, 0, "Preparing to archive your data"); |
---|
1267 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { |
---|
1268 | if (bkpinfo->backup_media_type == cdstream) { |
---|
1269 | openout_cdstream(bkpinfo->media_device, bkpinfo->writer_speed); |
---|
1270 | } else { |
---|
1271 | openout_tape(); /* sets g_tape_stream */ |
---|
1272 | } |
---|
1273 | if (!g_tape_stream) { |
---|
1274 | fatal_error("Cannot open backup (streaming) device"); |
---|
1275 | } |
---|
1276 | mr_msg(1, "Backup (stream) opened OK"); |
---|
1277 | write_data_disks_to_stream(data_disks_file); |
---|
1278 | } else { |
---|
1279 | if (bkpinfo->backup_media_type == usb) { |
---|
1280 | mr_msg(1, "Backing up to USB's"); |
---|
1281 | } else { |
---|
1282 | mr_msg(1, "Backing up to CD's"); |
---|
1283 | } |
---|
1284 | } |
---|
1285 | mr_free(data_disks_file); |
---|
1286 | |
---|
1287 | mr_asprintf(&command, "rm -f %s/%s/%s-[1-9]*.iso", bkpinfo->isodir, |
---|
1288 | bkpinfo->nfs_remote_dir, bkpinfo->prefix); |
---|
1289 | paranoid_system(command); |
---|
1290 | mr_free(command); |
---|
1291 | |
---|
1292 | wipe_archives(bkpinfo->scratchdir); |
---|
1293 | mvaddstr_and_log_it(g_currentY++, 74, "Done."); |
---|
1294 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { |
---|
1295 | write_header_block_to_stream((off_t)0, "start-of-tape", |
---|
1296 | BLK_START_OF_TAPE); |
---|
1297 | write_header_block_to_stream((off_t)0, "start-of-backup", |
---|
1298 | BLK_START_OF_BACKUP); |
---|
1299 | } |
---|
1300 | return (retval); |
---|
1301 | } |
---|
1302 | |
---|
1303 | |
---|
1304 | /** |
---|
1305 | * Get the <tt>N</tt>th bit of @c array. |
---|
1306 | * @param array The bit-array (as a @c char pointer). |
---|
1307 | * @param N The number of the bit you want. |
---|
1308 | * @return TRUE (bit is set) or FALSE (bit is not set). |
---|
1309 | * @see set_bit_N_of_array |
---|
1310 | * @ingroup utilityGroup |
---|
1311 | */ |
---|
1312 | bool get_bit_N_of_array(char *array, int N) |
---|
1313 | { |
---|
1314 | int element_number; |
---|
1315 | int bit_number; |
---|
1316 | int mask; |
---|
1317 | |
---|
1318 | element_number = N / 8; |
---|
1319 | bit_number = N % 8; |
---|
1320 | mask = 1 << bit_number; |
---|
1321 | if (array[element_number] & mask) { |
---|
1322 | return (TRUE); |
---|
1323 | } else { |
---|
1324 | return (FALSE); |
---|
1325 | } |
---|
1326 | } |
---|
1327 | |
---|
1328 | |
---|
1329 | /** |
---|
1330 | * @addtogroup LLarchiveGroup |
---|
1331 | * @{ |
---|
1332 | */ |
---|
1333 | /** |
---|
1334 | * Start up threads to archive your files. |
---|
1335 | * |
---|
1336 | * This function starts @c ARCH_THREADS threads, |
---|
1337 | * each starting execution in @c create_afio_files_in_background(). |
---|
1338 | * Each thread will archive individual filesets, based on the |
---|
1339 | * pointers passed to it and continually updated, until all files |
---|
1340 | * have been backed up. This function coordinates the threads |
---|
1341 | * and copies their output to the @c scratchdir. |
---|
1342 | * |
---|
1343 | * @param bkpinfo The backup information structure. Fields used: |
---|
1344 | * - @c backup_media_type |
---|
1345 | * - @c scratchdir |
---|
1346 | * - @c tmpdir |
---|
1347 | * - @c compression_suffix |
---|
1348 | * |
---|
1349 | * @return The number of errors encountered (0 for success) |
---|
1350 | */ |
---|
1351 | int make_afioballs_and_images() |
---|
1352 | { |
---|
1353 | |
---|
1354 | /*@ int ************************************************** */ |
---|
1355 | int retval = 0; |
---|
1356 | long int storing_set_no = 0; |
---|
1357 | int res = 0; |
---|
1358 | bool done_storing = FALSE; |
---|
1359 | char *result_str; |
---|
1360 | char *transfer_block; |
---|
1361 | void *vp; |
---|
1362 | void **pvp; |
---|
1363 | |
---|
1364 | /*@ buffers ********************************************** */ |
---|
1365 | char *storing_filelist_fname; |
---|
1366 | char *storing_afioball_fname; |
---|
1367 | char *tmp = NULL; |
---|
1368 | char *media_usage_comment; |
---|
1369 | pthread_t archival_thread[ARCH_THREADS]; |
---|
1370 | char *p_list_of_fileset_flags; |
---|
1371 | int *p_archival_threads_running; |
---|
1372 | int *p_last_set_archived; |
---|
1373 | int *p_next_set_to_archive; |
---|
1374 | int noof_threads; |
---|
1375 | int i; |
---|
1376 | char *curr_xattr_list_fname = NULL; |
---|
1377 | char *curr_acl_list_fname = NULL; |
---|
1378 | int misc_counter_that_is_not_important = 0; |
---|
1379 | |
---|
1380 | mr_msg(8, "here"); |
---|
1381 | assert(bkpinfo != NULL); |
---|
1382 | /* BERLIOS: To be removed */ |
---|
1383 | malloc_string(result_str); |
---|
1384 | malloc_string(curr_xattr_list_fname); |
---|
1385 | malloc_string(curr_acl_list_fname); |
---|
1386 | malloc_string(storing_filelist_fname); |
---|
1387 | malloc_string(media_usage_comment); |
---|
1388 | malloc_string(storing_afioball_fname); |
---|
1389 | transfer_block = |
---|
1390 | mr_malloc(sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64); |
---|
1391 | memset((void *) transfer_block, 0, |
---|
1392 | sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64); |
---|
1393 | p_last_set_archived = (int *) transfer_block; |
---|
1394 | p_archival_threads_running = (int *) (transfer_block + 4); |
---|
1395 | p_next_set_to_archive = (int *) (transfer_block + 8); |
---|
1396 | p_list_of_fileset_flags = (char *) (transfer_block + 12); |
---|
1397 | memcpy((void *) (transfer_block + BKPINFO_LOC_OFFSET), |
---|
1398 | (void *) bkpinfo, sizeof(struct s_bkpinfo)); |
---|
1399 | pvp = &vp; |
---|
1400 | vp = (void *) result_str; |
---|
1401 | *p_archival_threads_running = 0; |
---|
1402 | *p_last_set_archived = -1; |
---|
1403 | *p_next_set_to_archive = 0; |
---|
1404 | log_to_screen("Archiving regular files"); |
---|
1405 | open_progress_form(_("Backing up filesystem"), |
---|
1406 | _("I am backing up your live filesystem now."), |
---|
1407 | _("Please wait. This may take a couple of hours."), |
---|
1408 | _("Working..."), |
---|
1409 | get_last_filelist_number() + 1); |
---|
1410 | |
---|
1411 | srand((unsigned int) getpid()); |
---|
1412 | g_sem_key = 1234 + random() % 30000; |
---|
1413 | if ((g_sem_id = |
---|
1414 | semget((key_t) g_sem_key, 1, |
---|
1415 | IPC_CREAT | S_IREAD | S_IWRITE)) == -1) { |
---|
1416 | fatal_error("MABAI - unable to semget"); |
---|
1417 | } |
---|
1418 | if (!set_semvalue()) { |
---|
1419 | fatal_error("Unable to init semaphore"); |
---|
1420 | } // initialize semaphore |
---|
1421 | for (noof_threads = 0; noof_threads < ARCH_THREADS; noof_threads++) { |
---|
1422 | mr_msg(8, "Creating thread #%d", noof_threads); |
---|
1423 | (*p_archival_threads_running)++; |
---|
1424 | if ((res = |
---|
1425 | pthread_create(&archival_thread[noof_threads], NULL, |
---|
1426 | create_afio_files_in_background, |
---|
1427 | (void *) transfer_block))) { |
---|
1428 | fatal_error("Unable to create an archival thread"); |
---|
1429 | } |
---|
1430 | } |
---|
1431 | |
---|
1432 | mr_msg(8, "About to enter while() loop"); |
---|
1433 | while (!done_storing) { |
---|
1434 | if (g_exiting) { |
---|
1435 | fatal_error("Execution run aborted (main loop)"); |
---|
1436 | } |
---|
1437 | if (*p_archival_threads_running == 0 |
---|
1438 | && *p_last_set_archived == storing_set_no - 1) { |
---|
1439 | mr_msg(2, |
---|
1440 | "No archival threads are running. The last stored set was %d and I'm looking for %d. Take off your make-up; the party's over... :-)", |
---|
1441 | *p_last_set_archived, storing_set_no); |
---|
1442 | done_storing = TRUE; |
---|
1443 | } else |
---|
1444 | if (!get_bit_N_of_array |
---|
1445 | (p_list_of_fileset_flags, storing_set_no)) { |
---|
1446 | misc_counter_that_is_not_important = |
---|
1447 | (misc_counter_that_is_not_important + 1) % 5; |
---|
1448 | if (!misc_counter_that_is_not_important) { |
---|
1449 | update_progress_form(media_usage_comment); |
---|
1450 | } |
---|
1451 | sleep(1); |
---|
1452 | } else { |
---|
1453 | // store set N |
---|
1454 | sprintf(storing_filelist_fname, FILELIST_FNAME_RAW_SZ, |
---|
1455 | bkpinfo->tmpdir, storing_set_no); |
---|
1456 | sprintf(storing_afioball_fname, AFIOBALL_FNAME_RAW_SZ, |
---|
1457 | bkpinfo->tmpdir, storing_set_no, bkpinfo->compression_suffix); |
---|
1458 | if (g_getfattr) { |
---|
1459 | sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, |
---|
1460 | bkpinfo->tmpdir, storing_set_no); |
---|
1461 | } |
---|
1462 | if (g_getfacl) { |
---|
1463 | sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, |
---|
1464 | bkpinfo->tmpdir, storing_set_no); |
---|
1465 | } |
---|
1466 | |
---|
1467 | mr_msg(2, "Storing set %d", storing_set_no); |
---|
1468 | while (!does_file_exist(storing_filelist_fname) |
---|
1469 | || !does_file_exist(storing_afioball_fname)) { |
---|
1470 | mr_msg(2, |
---|
1471 | "Warning - either %s or %s doesn't exist yet. I'll pause 5 secs.", |
---|
1472 | storing_filelist_fname, storing_afioball_fname); |
---|
1473 | sleep(5); |
---|
1474 | } |
---|
1475 | strcpy(media_usage_comment, percent_media_full_comment()); |
---|
1476 | /* copy to CD (scratchdir) ... and an actual CD-R if necessary */ |
---|
1477 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { |
---|
1478 | register_in_tape_catalog(fileset, storing_set_no, -1, |
---|
1479 | storing_afioball_fname); |
---|
1480 | maintain_collection_of_recent_archives(bkpinfo->tmpdir, |
---|
1481 | storing_afioball_fname); |
---|
1482 | iamhere("Writing EXAT files"); |
---|
1483 | res += write_EXAT_files_to_tape(curr_xattr_list_fname, |
---|
1484 | curr_acl_list_fname); |
---|
1485 | // archives themselves |
---|
1486 | res += |
---|
1487 | write_EXAT_files_to_tape(curr_xattr_list_fname, |
---|
1488 | curr_acl_list_fname); |
---|
1489 | // archives themselves |
---|
1490 | res += |
---|
1491 | move_files_to_stream(storing_afioball_fname, |
---|
1492 | NULL); |
---|
1493 | } else { |
---|
1494 | if (g_getfacl) { |
---|
1495 | if (g_getfattr) { |
---|
1496 | res = move_files_to_cd(storing_filelist_fname, |
---|
1497 | curr_xattr_list_fname, |
---|
1498 | curr_acl_list_fname, |
---|
1499 | storing_afioball_fname, NULL); |
---|
1500 | } else { |
---|
1501 | res = move_files_to_cd(storing_filelist_fname, |
---|
1502 | curr_acl_list_fname, |
---|
1503 | storing_afioball_fname, NULL); |
---|
1504 | } |
---|
1505 | } else { |
---|
1506 | if (g_getfattr) { |
---|
1507 | res = move_files_to_cd(storing_filelist_fname, |
---|
1508 | curr_xattr_list_fname, |
---|
1509 | storing_afioball_fname, NULL); |
---|
1510 | } else { |
---|
1511 | res = move_files_to_cd(storing_filelist_fname, |
---|
1512 | storing_afioball_fname, NULL); |
---|
1513 | } |
---|
1514 | } |
---|
1515 | } |
---|
1516 | retval += res; |
---|
1517 | g_current_progress++; |
---|
1518 | update_progress_form(media_usage_comment); |
---|
1519 | if (res) { |
---|
1520 | mr_asprintf(&tmp, |
---|
1521 | "Failed to add archive %ld's files to CD dir\n", |
---|
1522 | storing_set_no); |
---|
1523 | log_to_screen(tmp); |
---|
1524 | mr_free(tmp); |
---|
1525 | fatal_error |
---|
1526 | ("Is your hard disk full? If not, please send the author the logfile."); |
---|
1527 | } |
---|
1528 | storing_set_no++; |
---|
1529 | // sleep(2); |
---|
1530 | } |
---|
1531 | } |
---|
1532 | close_progress_form(); |
---|
1533 | |
---|
1534 | mr_msg(2, "Joining background threads to foreground thread"); |
---|
1535 | for (i = 0; i < noof_threads; i++) { |
---|
1536 | pthread_join(archival_thread[i], pvp); |
---|
1537 | mr_msg(3, "Thread %d of %d: closed OK", i + 1, noof_threads); |
---|
1538 | } |
---|
1539 | del_semvalue(); |
---|
1540 | mr_msg(2, "Done."); |
---|
1541 | if (retval) { |
---|
1542 | mr_asprintf(&tmp, |
---|
1543 | "Your regular files have been archived (with errors)."); |
---|
1544 | } else { |
---|
1545 | mr_asprintf(&tmp, |
---|
1546 | "Your regular files have been archived successfully"); |
---|
1547 | } |
---|
1548 | log_to_screen(tmp); |
---|
1549 | mr_free(tmp); |
---|
1550 | mr_free(transfer_block); |
---|
1551 | mr_free(result_str); |
---|
1552 | mr_free(storing_filelist_fname); |
---|
1553 | mr_free(media_usage_comment); |
---|
1554 | mr_free(storing_afioball_fname); |
---|
1555 | mr_free(curr_xattr_list_fname); |
---|
1556 | mr_free(curr_acl_list_fname); |
---|
1557 | return (retval); |
---|
1558 | } |
---|
1559 | |
---|
1560 | |
---|
1561 | void pause_for_N_seconds(int how_long, char *msg) |
---|
1562 | { |
---|
1563 | int i; |
---|
1564 | open_evalcall_form(msg); |
---|
1565 | for (i = 0; i < how_long; i++) { |
---|
1566 | update_evalcall_form((int) ((100.0 / (float) (how_long) * i))); |
---|
1567 | sleep(1); |
---|
1568 | } |
---|
1569 | close_evalcall_form(); |
---|
1570 | } |
---|
1571 | |
---|
1572 | |
---|
1573 | /** |
---|
1574 | * Create a USB image in @c destfile, from files in @c bkpinfo->scratchdir. |
---|
1575 | * |
---|
1576 | * @param bkpinfo The backup information structure. Fields used: |
---|
1577 | * - @c backup_media_type |
---|
1578 | * - @c nonbootable_backup |
---|
1579 | * - @c scratchdir |
---|
1580 | * |
---|
1581 | * @param destfile Where to put the generated USB image. |
---|
1582 | * @return The number of errors encountered (0 for success) |
---|
1583 | */ |
---|
1584 | int make_usb_fs() |
---|
1585 | { |
---|
1586 | /*@ int ********************************************** */ |
---|
1587 | int retval = 0; |
---|
1588 | int res; |
---|
1589 | |
---|
1590 | /*@ buffers ****************************************** */ |
---|
1591 | char *tmp = NULL; |
---|
1592 | char *tmp1 = NULL; |
---|
1593 | char *result_sz = NULL; |
---|
1594 | char *message_to_screen = NULL; |
---|
1595 | char *old_pwd; |
---|
1596 | |
---|
1597 | malloc_string(old_pwd); |
---|
1598 | assert(bkpinfo != NULL); |
---|
1599 | |
---|
1600 | log_msg(2, "make_usb_fs --- scratchdir=%s", bkpinfo->scratchdir); |
---|
1601 | (void) getcwd(old_pwd, MAX_STR_LEN - 1); |
---|
1602 | asprintf(&tmp, "chmod 755 %s", bkpinfo->scratchdir); |
---|
1603 | run_program_and_log_output(tmp, FALSE); |
---|
1604 | paranoid_free(tmp); |
---|
1605 | chdir(bkpinfo->scratchdir); |
---|
1606 | |
---|
1607 | asprintf(&message_to_screen, "Copying data to make %s #%d", |
---|
1608 | media_descriptor_string(bkpinfo->backup_media_type), |
---|
1609 | g_current_media_number); |
---|
1610 | log_msg(1, message_to_screen); |
---|
1611 | |
---|
1612 | asprintf(&tmp1, "%s1", bkpinfo->media_device); |
---|
1613 | if (is_this_device_mounted(tmp1)) { |
---|
1614 | log_msg(1, "USB device mounted. Remounting it at the right place"); |
---|
1615 | asprintf(&tmp, "umount %s", tmp1); |
---|
1616 | run_program_and_log_output(tmp, FALSE); |
---|
1617 | paranoid_free(tmp); |
---|
1618 | } |
---|
1619 | paranoid_free(tmp); |
---|
1620 | |
---|
1621 | log_msg(1, "Mounting USB device."); |
---|
1622 | asprintf(&tmp1, "%s/usb", bkpinfo->tmpdir); |
---|
1623 | asprintf(&tmp, "mkdir -p %s", tmp1); |
---|
1624 | run_program_and_log_output(tmp, FALSE); |
---|
1625 | paranoid_free(tmp); |
---|
1626 | /* Mindi always create one single parition on the USB dev */ |
---|
1627 | asprintf(&tmp, "mount %s1 %s", bkpinfo->media_device, tmp1); |
---|
1628 | run_program_and_log_output(tmp, FALSE); |
---|
1629 | paranoid_free(tmp); |
---|
1630 | |
---|
1631 | if (bkpinfo->nonbootable_backup) { |
---|
1632 | log_msg(1, "Making nonbootable USB backup not implemented yet"); |
---|
1633 | } else { |
---|
1634 | log_msg(1, "Making bootable backup"); |
---|
1635 | |
---|
1636 | /* Command to execute */ |
---|
1637 | asprintf(&tmp,"mv %s/* %s", bkpinfo->scratchdir, tmp1); |
---|
1638 | res = eval_call_to_make_USB(tmp, message_to_screen); |
---|
1639 | if (res) { |
---|
1640 | asprintf(&result_sz, "%s ...failed",tmp); |
---|
1641 | } else { |
---|
1642 | asprintf(&result_sz, "%s ...OK",tmp); |
---|
1643 | } |
---|
1644 | log_to_screen(result_sz); |
---|
1645 | paranoid_free(result_sz); |
---|
1646 | paranoid_free(tmp); |
---|
1647 | retval += res; |
---|
1648 | } |
---|
1649 | paranoid_free(message_to_screen); |
---|
1650 | paranoid_free(tmp1); |
---|
1651 | |
---|
1652 | if (is_this_device_mounted(bkpinfo->media_device)) { |
---|
1653 | asprintf(&tmp, "umount %s1", bkpinfo->media_device); |
---|
1654 | run_program_and_log_output(tmp, FALSE); |
---|
1655 | paranoid_free(tmp); |
---|
1656 | } |
---|
1657 | |
---|
1658 | chdir(old_pwd); |
---|
1659 | if (retval) { |
---|
1660 | log_msg(1, "WARNING - make_usb_fs returned an error"); |
---|
1661 | } |
---|
1662 | paranoid_free(old_pwd); |
---|
1663 | return (retval); |
---|
1664 | } |
---|
1665 | |
---|
1666 | |
---|
1667 | /** |
---|
1668 | * Create an ISO image in @c destfile, from files in @c bkpinfo->scratchdir. |
---|
1669 | * |
---|
1670 | * @param bkpinfo The backup information structure. Fields used: |
---|
1671 | * - @c backup_media_type |
---|
1672 | * - @c call_after_iso |
---|
1673 | * - @c call_before_iso |
---|
1674 | * - @c call_burn_iso |
---|
1675 | * - @c call_make_iso |
---|
1676 | * - @c manual_tray |
---|
1677 | * - @c nonbootable_backup |
---|
1678 | * - @c scratchdir |
---|
1679 | * |
---|
1680 | * @param destfile Where to put the generated ISO image. |
---|
1681 | * @return The number of errors encountered (0 for success) |
---|
1682 | */ |
---|
1683 | int make_iso_fs(char *destfile) |
---|
1684 | { |
---|
1685 | /*@ int ********************************************** */ |
---|
1686 | int retval = 0; |
---|
1687 | int res; |
---|
1688 | |
---|
1689 | /*@ buffers ****************************************** */ |
---|
1690 | char *tmp = NULL; |
---|
1691 | char *old_pwd; |
---|
1692 | char *message_to_screen = NULL; |
---|
1693 | char *sz_blank_disk = NULL; |
---|
1694 | char *tmp2 = NULL; |
---|
1695 | char *tmp3 = NULL; |
---|
1696 | |
---|
1697 | malloc_string(old_pwd); |
---|
1698 | assert(bkpinfo != NULL); |
---|
1699 | assert_string_is_neither_NULL_nor_zerolength(destfile); |
---|
1700 | |
---|
1701 | mr_asprintf(&tmp, "%s/isolinux.bin", bkpinfo->scratchdir); |
---|
1702 | mr_asprintf(&tmp2, "%s/isolinux.bin", bkpinfo->tmpdir); |
---|
1703 | if (does_file_exist(tmp)) { |
---|
1704 | mr_asprintf(&tmp3, "cp -f %s %s", tmp, tmp2); |
---|
1705 | paranoid_system(tmp3); |
---|
1706 | mr_free(tmp3); |
---|
1707 | } |
---|
1708 | if (!does_file_exist(tmp) && does_file_exist(tmp2)) { |
---|
1709 | mr_asprintf(&tmp3, "cp -f %s %s", tmp2, tmp); |
---|
1710 | paranoid_system(tmp3); |
---|
1711 | mr_free(tmp3); |
---|
1712 | } |
---|
1713 | mr_free(tmp2); |
---|
1714 | mr_free(tmp); |
---|
1715 | |
---|
1716 | if (bkpinfo->backup_media_type != iso && bkpinfo->manual_tray) { |
---|
1717 | popup_and_OK(_("Please insert new media and press Enter.")); |
---|
1718 | } |
---|
1719 | |
---|
1720 | mr_msg(2, "make_iso_fs --- scratchdir=%s --- destfile=%s", |
---|
1721 | bkpinfo->scratchdir, destfile); |
---|
1722 | /* BERLIOS: Do not ignore getcwd result */ |
---|
1723 | (void) getcwd(old_pwd, MAX_STR_LEN - 1); |
---|
1724 | chmod(bkpinfo->scratchdir,0755); |
---|
1725 | chdir(bkpinfo->scratchdir); |
---|
1726 | |
---|
1727 | if (bkpinfo->call_before_iso[0] != '\0') { |
---|
1728 | mr_asprintf(&message_to_screen, "Running pre-ISO call for CD#%d", |
---|
1729 | g_current_media_number); |
---|
1730 | res = eval_call_to_make_ISO(bkpinfo->call_before_iso, |
---|
1731 | destfile, g_current_media_number, |
---|
1732 | MONDO_LOGFILE, message_to_screen); |
---|
1733 | if (res) { |
---|
1734 | log_to_screen("%s...failed", message_to_screen); |
---|
1735 | } else { |
---|
1736 | log_to_screen("%s...OK", message_to_screen); |
---|
1737 | } |
---|
1738 | mr_free(message_to_screen); |
---|
1739 | retval += res; |
---|
1740 | } |
---|
1741 | |
---|
1742 | if (bkpinfo->call_make_iso[0] != '\0') { |
---|
1743 | mr_msg(2, "bkpinfo->call_make_iso = %s", bkpinfo->call_make_iso); |
---|
1744 | mr_asprintf(&message_to_screen, "Making an ISO (%s #%d)", |
---|
1745 | bkpinfo->backup_media_string, |
---|
1746 | g_current_media_number); |
---|
1747 | |
---|
1748 | /* if g_current_media_number >= 2 then pause & ask */ |
---|
1749 | if (bkpinfo->backup_media_type != iso) { |
---|
1750 | pause_and_ask_for_cdr(2); |
---|
1751 | } |
---|
1752 | if (retval) { |
---|
1753 | log_to_screen |
---|
1754 | ("Serious error(s) occurred already. I shan't try to write to media."); |
---|
1755 | } else { |
---|
1756 | res = eval_call_to_make_ISO(bkpinfo->call_make_iso, |
---|
1757 | destfile, g_current_media_number, |
---|
1758 | MONDO_LOGFILE, message_to_screen); |
---|
1759 | if (res) { |
---|
1760 | log_to_screen("%s...failed to write", message_to_screen); |
---|
1761 | } else { |
---|
1762 | log_to_screen("%s...OK", message_to_screen); |
---|
1763 | mr_asprintf(&tmp, "tail -n10 %s | grep -F ':-('", MONDO_LOGFILE); |
---|
1764 | if (!run_program_and_log_output(tmp, 1)) { |
---|
1765 | log_to_screen |
---|
1766 | ("Despite nonfatal errors, growisofs confirms the write was successful."); |
---|
1767 | } |
---|
1768 | mr_free(tmp); |
---|
1769 | } |
---|
1770 | retval += res; |
---|
1771 | #ifdef DVDRWFORMAT |
---|
1772 | mr_asprintf(&tmp, |
---|
1773 | "tail -n8 %s | grep 'blank=full.*dvd-compat.*DAO'", |
---|
1774 | MONDO_LOGFILE); |
---|
1775 | if (g_backup_media_type == dvd |
---|
1776 | && (res || !run_program_and_log_output(tmp, 1))) { |
---|
1777 | log_to_screen |
---|
1778 | ("Failed to write to disk. I shall blank it and then try again."); |
---|
1779 | sleep(5); |
---|
1780 | sync(); |
---|
1781 | pause_for_N_seconds(5, "Letting DVD drive settle"); |
---|
1782 | |
---|
1783 | // dvd+rw-format --- OPTION 2 |
---|
1784 | if (!bkpinfo->please_dont_eject) { |
---|
1785 | log_to_screen("Ejecting media to clear drive status."); |
---|
1786 | eject_device(bkpinfo->media_device); |
---|
1787 | inject_device(bkpinfo->media_device); |
---|
1788 | } |
---|
1789 | pause_for_N_seconds(5, "Letting DVD drive settle"); |
---|
1790 | mr_asprintf(&sz_blank_disk, "dvd+rw-format -force %s", |
---|
1791 | bkpinfo->media_device); |
---|
1792 | mr_msg(3, "sz_blank_disk = '%s'", sz_blank_disk); |
---|
1793 | res = run_external_binary_with_percentage_indicator_NEW |
---|
1794 | ("Blanking DVD disk", sz_blank_disk); |
---|
1795 | if (res) { |
---|
1796 | log_to_screen |
---|
1797 | ("Warning - format failed. (Was it a DVD-R?) Sleeping for 5 seconds to take a breath..."); |
---|
1798 | pause_for_N_seconds(5, |
---|
1799 | "Letting DVD drive settle... and trying again."); |
---|
1800 | res = run_external_binary_with_percentage_indicator_NEW |
---|
1801 | ("Blanking DVD disk", sz_blank_disk); |
---|
1802 | if (res) { |
---|
1803 | log_to_screen("Format failed a second time."); |
---|
1804 | } |
---|
1805 | } else { |
---|
1806 | log_to_screen |
---|
1807 | ("Format succeeded. Sleeping for 5 seconds to take a breath..."); |
---|
1808 | } |
---|
1809 | mr_free(sz_blank_disk); |
---|
1810 | pause_for_N_seconds(5, "Letting DVD drive settle"); |
---|
1811 | if (!bkpinfo->please_dont_eject) { |
---|
1812 | log_to_screen("Ejecting media to clear drive status."); |
---|
1813 | eject_device(bkpinfo->media_device); |
---|
1814 | inject_device(bkpinfo->media_device); |
---|
1815 | } |
---|
1816 | pause_for_N_seconds(5, "Letting DVD drive settle"); |
---|
1817 | res = |
---|
1818 | eval_call_to_make_ISO(bkpinfo->call_make_iso, |
---|
1819 | destfile, |
---|
1820 | g_current_media_number, |
---|
1821 | MONDO_LOGFILE, |
---|
1822 | message_to_screen); |
---|
1823 | retval += res; |
---|
1824 | if (!bkpinfo->please_dont_eject) { |
---|
1825 | log_to_screen("Ejecting media."); |
---|
1826 | eject_device(bkpinfo->media_device); |
---|
1827 | } |
---|
1828 | if (res) { |
---|
1829 | log_to_screen("Dagnabbit. It still failed."); |
---|
1830 | } else { |
---|
1831 | log_to_screen |
---|
1832 | ("OK, this time I successfully backed up to DVD."); |
---|
1833 | } |
---|
1834 | } |
---|
1835 | mr_free(tmp); |
---|
1836 | #endif |
---|
1837 | if (g_backup_media_type == dvd && !bkpinfo->please_dont_eject) { |
---|
1838 | eject_device(bkpinfo->media_device); |
---|
1839 | } |
---|
1840 | } |
---|
1841 | mr_free(message_to_screen); |
---|
1842 | } else { |
---|
1843 | fatal_error("call_make_iso undefined. Not normal in this case"); |
---|
1844 | } |
---|
1845 | |
---|
1846 | if (bkpinfo->backup_media_type == cdr |
---|
1847 | || bkpinfo->backup_media_type == cdrw) { |
---|
1848 | if (is_this_device_mounted(bkpinfo->media_device)) { |
---|
1849 | mr_msg(2, |
---|
1850 | "Warning - %s mounted. I'm unmounting it before I burn to it.", |
---|
1851 | bkpinfo->media_device); |
---|
1852 | mr_asprintf(&tmp, "umount %s", bkpinfo->media_device); |
---|
1853 | run_program_and_log_output(tmp, FALSE); |
---|
1854 | mr_free(tmp); |
---|
1855 | } |
---|
1856 | } |
---|
1857 | |
---|
1858 | if (bkpinfo->call_after_iso != NULL) { |
---|
1859 | mr_asprintf(&message_to_screen, "Running post-ISO call (%s #%d)", |
---|
1860 | bkpinfo->backup_media_string, |
---|
1861 | g_current_media_number); |
---|
1862 | res = eval_call_to_make_ISO(bkpinfo->call_after_iso, |
---|
1863 | destfile, g_current_media_number, |
---|
1864 | MONDO_LOGFILE, message_to_screen); |
---|
1865 | if (res) { |
---|
1866 | log_to_screen("%s...failed", message_to_screen); |
---|
1867 | } else { |
---|
1868 | log_to_screen("%s...OK", message_to_screen); |
---|
1869 | } |
---|
1870 | mr_free(message_to_screen); |
---|
1871 | retval += res; |
---|
1872 | } |
---|
1873 | |
---|
1874 | chdir(old_pwd); |
---|
1875 | if (retval) { |
---|
1876 | mr_msg(1, "WARNING - make_iso_fs returned an error"); |
---|
1877 | } |
---|
1878 | mr_free(old_pwd); |
---|
1879 | return (retval); |
---|
1880 | } |
---|
1881 | |
---|
1882 | |
---|
1883 | bool is_dev_an_NTFS_dev(char *bigfile_fname) |
---|
1884 | { |
---|
1885 | char *tmp; |
---|
1886 | char *command; |
---|
1887 | malloc_string(tmp); |
---|
1888 | bool ret = TRUE; |
---|
1889 | mr_asprintf(&command, |
---|
1890 | "dd if=%s bs=512 count=1 2> /dev/null | strings | head -n1", |
---|
1891 | bigfile_fname); |
---|
1892 | mr_msg(1, "command = '%s'", command); |
---|
1893 | strcpy(tmp, call_program_and_get_last_line_of_output(command)); |
---|
1894 | mr_msg(1, "--> tmp = '%s'", tmp); |
---|
1895 | mr_free(command); |
---|
1896 | if (strstr(tmp, "NTFS")) { |
---|
1897 | iamhere("TRUE"); |
---|
1898 | } else { |
---|
1899 | iamhere("FALSE"); |
---|
1900 | ret = FALSE; |
---|
1901 | } |
---|
1902 | return(ret); |
---|
1903 | } |
---|
1904 | |
---|
1905 | |
---|
1906 | /** |
---|
1907 | * Back up big files by chopping them up. |
---|
1908 | * This function backs up all "big" files (where "big" depends |
---|
1909 | * on your backup media) in "chunks" (whose size again depends |
---|
1910 | * on your media). |
---|
1911 | * |
---|
1912 | * @param bkpinfo The backup information structure. Fields used: |
---|
1913 | * - @c backup_media_type |
---|
1914 | * - @c optimal_set_size |
---|
1915 | * @param biggielist_fname The path to a file containing a list of |
---|
1916 | * all "big" files. |
---|
1917 | * @return The number of errors encountered (0 for success) |
---|
1918 | * @see slice_up_file_etc |
---|
1919 | */ |
---|
1920 | int |
---|
1921 | make_slices_and_images(char *biggielist_fname) |
---|
1922 | { |
---|
1923 | |
---|
1924 | /*@ pointers ******************************************* */ |
---|
1925 | FILE *fin = NULL; |
---|
1926 | char *p = NULL; |
---|
1927 | |
---|
1928 | /*@ buffers ******************************************** */ |
---|
1929 | char *tmp = NULL; |
---|
1930 | char *bigfile_fname = NULL; |
---|
1931 | char *sz_devfile = NULL; |
---|
1932 | char *ntfsprog_fifo = NULL; |
---|
1933 | /*@ long *********************************************** */ |
---|
1934 | long biggie_file_number = 0; |
---|
1935 | long noof_biggie_files = 0; |
---|
1936 | long estimated_total_noof_slices = 0; |
---|
1937 | |
---|
1938 | /*@ int ************************************************ */ |
---|
1939 | int retval = 0; |
---|
1940 | int res = 0; |
---|
1941 | size_t n = 0; |
---|
1942 | pid_t pid; |
---|
1943 | FILE *ftmp = NULL; |
---|
1944 | bool delete_when_done; |
---|
1945 | bool use_ntfsprog; |
---|
1946 | off_t biggie_fsize; |
---|
1947 | |
---|
1948 | assert(bkpinfo != NULL); |
---|
1949 | assert_string_is_neither_NULL_nor_zerolength(biggielist_fname); |
---|
1950 | |
---|
1951 | estimated_total_noof_slices = |
---|
1952 | size_of_all_biggiefiles_K() / bkpinfo->optimal_set_size + 1; |
---|
1953 | |
---|
1954 | mr_msg(1, "size of all biggiefiles = %ld", |
---|
1955 | size_of_all_biggiefiles_K()); |
---|
1956 | mr_msg(1, "estimated_total_noof_slices = %ld KB / %ld KB = %ld", |
---|
1957 | size_of_all_biggiefiles_K(), bkpinfo->optimal_set_size, |
---|
1958 | estimated_total_noof_slices); |
---|
1959 | |
---|
1960 | if (length_of_file(biggielist_fname) < 6) { |
---|
1961 | mr_msg(1, "No biggiefiles; fair enough..."); |
---|
1962 | return (0); |
---|
1963 | } |
---|
1964 | mr_asprintf(&tmp, "I am now backing up all large files."); |
---|
1965 | log_to_screen(tmp); |
---|
1966 | noof_biggie_files = count_lines_in_file(biggielist_fname); |
---|
1967 | open_progress_form("Backing up big files", tmp, |
---|
1968 | "Please wait. This may take some time.", "", |
---|
1969 | estimated_total_noof_slices); |
---|
1970 | mr_free(tmp); |
---|
1971 | |
---|
1972 | if (!(fin = fopen(biggielist_fname, "r"))) { |
---|
1973 | log_OS_error("Unable to openin biggielist"); |
---|
1974 | return (1); |
---|
1975 | } |
---|
1976 | for (mr_getline(&bigfile_fname, &n, fin); !feof(fin); |
---|
1977 | mr_getline(&bigfile_fname, &n, fin), biggie_file_number++) { |
---|
1978 | use_ntfsprog = FALSE; |
---|
1979 | if (bigfile_fname[strlen(bigfile_fname) - 1] < 32) { |
---|
1980 | bigfile_fname[strlen(bigfile_fname) - 1] = '\0'; |
---|
1981 | } |
---|
1982 | biggie_fsize = length_of_file(bigfile_fname); |
---|
1983 | delete_when_done = FALSE; |
---|
1984 | |
---|
1985 | if (!does_file_exist(bigfile_fname)) { |
---|
1986 | ftmp = fopen(bigfile_fname, "w"); |
---|
1987 | if (ftmp == NULL) { |
---|
1988 | mr_msg(3, "Unable to write to %s", bigfile_fname); |
---|
1989 | // So skip it as it doesn't exist |
---|
1990 | continue; |
---|
1991 | } else { |
---|
1992 | paranoid_fclose(ftmp); |
---|
1993 | } |
---|
1994 | delete_when_done = TRUE; |
---|
1995 | } else { |
---|
1996 | // Call ntfsclone (formerly partimagehack) if it's a /dev entry |
---|
1997 | // (i.e. a partition to be imaged) |
---|
1998 | mr_msg(2, "bigfile_fname = %s", bigfile_fname); |
---|
1999 | use_ntfsprog = FALSE; |
---|
2000 | if (!strncmp(bigfile_fname, "/dev/", 5) |
---|
2001 | && is_dev_an_NTFS_dev(bigfile_fname)) { |
---|
2002 | use_ntfsprog = TRUE; |
---|
2003 | mr_msg(2, |
---|
2004 | "Calling ntfsclone in background because %s is an NTFS partition", |
---|
2005 | bigfile_fname); |
---|
2006 | mr_asprintf(&sz_devfile, "%s/%d.%d.000", |
---|
2007 | bkpinfo->tmpdir, |
---|
2008 | (int) (random() % 32768), |
---|
2009 | (int) (random() % 32768)); |
---|
2010 | mkfifo(sz_devfile, 0x770); |
---|
2011 | ntfsprog_fifo = sz_devfile; |
---|
2012 | switch (pid = fork()) { |
---|
2013 | case -1: |
---|
2014 | fatal_error("Fork failure"); |
---|
2015 | case 0: |
---|
2016 | mr_msg(2, |
---|
2017 | "CHILD - fip - calling feed_into_ntfsprog(%s, %s)", |
---|
2018 | bigfile_fname, sz_devfile); |
---|
2019 | res = feed_into_ntfsprog(bigfile_fname, sz_devfile); |
---|
2020 | mr_free(sz_devfile); |
---|
2021 | exit(res); |
---|
2022 | break; |
---|
2023 | default: |
---|
2024 | mr_msg(2, |
---|
2025 | "feed_into_ntfsprog() called in background --- pid=%ld", |
---|
2026 | (long int) (pid)); |
---|
2027 | mr_free(sz_devfile); |
---|
2028 | break; |
---|
2029 | } |
---|
2030 | } |
---|
2031 | // Otherwise, use good old 'dd' and 'bzip2' |
---|
2032 | else { |
---|
2033 | ntfsprog_fifo = NULL; |
---|
2034 | } |
---|
2035 | |
---|
2036 | // Whether partition or biggiefile, just do your thang :-) |
---|
2037 | mr_msg(5, "Bigfile #%ld is '%s' (%ld KB)", |
---|
2038 | biggie_file_number + 1, bigfile_fname, |
---|
2039 | (long) biggie_fsize >> 10); |
---|
2040 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { |
---|
2041 | write_header_block_to_stream(biggie_fsize, bigfile_fname, |
---|
2042 | use_ntfsprog ? |
---|
2043 | BLK_START_A_PIHBIGGIE : |
---|
2044 | BLK_START_A_NORMBIGGIE); |
---|
2045 | } |
---|
2046 | res = |
---|
2047 | slice_up_file_etc(bigfile_fname, |
---|
2048 | ntfsprog_fifo, biggie_file_number, |
---|
2049 | noof_biggie_files, use_ntfsprog); |
---|
2050 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { |
---|
2051 | write_header_block_to_stream((off_t)0, |
---|
2052 | calc_checksum_of_file |
---|
2053 | (bigfile_fname), |
---|
2054 | BLK_STOP_A_BIGGIE); |
---|
2055 | } |
---|
2056 | retval += res; |
---|
2057 | p = strrchr(bigfile_fname, '/'); |
---|
2058 | if (p) { |
---|
2059 | p++; |
---|
2060 | } else { |
---|
2061 | p = bigfile_fname; |
---|
2062 | } |
---|
2063 | if (res) { |
---|
2064 | mr_asprintf(&tmp, "Archiving %s ... Failed!", bigfile_fname); |
---|
2065 | } else { |
---|
2066 | mr_asprintf(&tmp, "Archiving %s ... OK!", bigfile_fname); |
---|
2067 | } |
---|
2068 | mr_msg(4,tmp); |
---|
2069 | mr_free(tmp); |
---|
2070 | if (delete_when_done) { |
---|
2071 | unlink(bigfile_fname); |
---|
2072 | delete_when_done = FALSE; |
---|
2073 | } |
---|
2074 | } |
---|
2075 | if (!g_text_mode) { |
---|
2076 | newtDrawRootText(0, g_noof_rows - 2, tmp); |
---|
2077 | newtRefresh(); |
---|
2078 | } |
---|
2079 | } |
---|
2080 | mr_free(bigfile_fname); |
---|
2081 | paranoid_fclose(fin); |
---|
2082 | |
---|
2083 | mr_msg(1, "Finished backing up bigfiles"); |
---|
2084 | mr_msg(1, "estimated slices = %ld; actual slices = %ld", |
---|
2085 | estimated_total_noof_slices, g_current_progress); |
---|
2086 | close_progress_form(); |
---|
2087 | return (retval); |
---|
2088 | } |
---|
2089 | |
---|
2090 | |
---|
2091 | /** |
---|
2092 | * Single-threaded version of @c make_afioballs_and_images(). |
---|
2093 | * @see make_afioballs_and_images |
---|
2094 | */ |
---|
2095 | int make_afioballs_and_images_OLD() |
---|
2096 | { |
---|
2097 | |
---|
2098 | /*@ int ************************************************** */ |
---|
2099 | int retval = 0; |
---|
2100 | long int curr_set_no = 0; |
---|
2101 | int res = 0; |
---|
2102 | |
---|
2103 | /*@ buffers ********************************************** */ |
---|
2104 | char *curr_filelist_fname = NULL; |
---|
2105 | char *curr_afioball_fname = NULL; |
---|
2106 | char *curr_xattr_list_fname = NULL; |
---|
2107 | char *curr_acl_list_fname = NULL; |
---|
2108 | char *media_usage_comment = NULL; |
---|
2109 | char *tmp= mr_malloc(MAX_STR_LEN * 2); |
---|
2110 | |
---|
2111 | /* BERLIOS: Useless ? |
---|
2112 | mr_asprintf(&tmp, "%s/archives/filelist.full", bkpinfo->scratchdir); |
---|
2113 | */ |
---|
2114 | malloc_string(media_usage_comment); |
---|
2115 | log_to_screen("Archiving regular files"); |
---|
2116 | |
---|
2117 | open_progress_form(_("Backing up filesystem"), |
---|
2118 | _("I am backing up your live filesystem now."), |
---|
2119 | _("Please wait. This may take a couple of hours."), |
---|
2120 | _("Working..."), |
---|
2121 | get_last_filelist_number() + 1); |
---|
2122 | |
---|
2123 | mr_asprintf(&curr_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir, |
---|
2124 | 0L); |
---|
2125 | |
---|
2126 | curr_set_no = 0; |
---|
2127 | while (does_file_exist(curr_filelist_fname)) { |
---|
2128 | /* backup this set of files */ |
---|
2129 | mr_asprintf(&curr_afioball_fname, AFIOBALL_FNAME_RAW_SZ, |
---|
2130 | bkpinfo->tmpdir, curr_set_no, bkpinfo->compression_suffix); |
---|
2131 | |
---|
2132 | mr_msg(1, "EXAT'g set %ld", curr_set_no); |
---|
2133 | if (g_getfattr) { |
---|
2134 | mr_asprintf(&curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, |
---|
2135 | bkpinfo->tmpdir, curr_set_no); |
---|
2136 | get_fattr_list(curr_filelist_fname, curr_xattr_list_fname); |
---|
2137 | } |
---|
2138 | if (g_getfacl) { |
---|
2139 | mr_asprintf(&curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, |
---|
2140 | bkpinfo->tmpdir, curr_set_no); |
---|
2141 | get_acl_list(curr_filelist_fname, curr_acl_list_fname); |
---|
2142 | } |
---|
2143 | |
---|
2144 | mr_msg(1, "Archiving set %ld", curr_set_no); |
---|
2145 | res = archive_this_fileset(curr_filelist_fname, |
---|
2146 | curr_afioball_fname, curr_set_no); |
---|
2147 | retval += res; |
---|
2148 | if (res) { |
---|
2149 | mr_asprintf(&tmp, |
---|
2150 | "Errors occurred while archiving set %ld. Perhaps your live filesystem changed?", |
---|
2151 | curr_set_no); |
---|
2152 | log_to_screen(tmp); |
---|
2153 | mr_free(tmp); |
---|
2154 | } |
---|
2155 | |
---|
2156 | strcpy(media_usage_comment, percent_media_full_comment()); |
---|
2157 | |
---|
2158 | /* copy to CD (scratchdir) ... and an actual CD-R if necessary */ |
---|
2159 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { |
---|
2160 | register_in_tape_catalog(fileset, curr_set_no, -1, curr_afioball_fname); |
---|
2161 | maintain_collection_of_recent_archives(bkpinfo->tmpdir, curr_afioball_fname); |
---|
2162 | iamhere("Writing EXAT files"); |
---|
2163 | res += |
---|
2164 | write_EXAT_files_to_tape(curr_xattr_list_fname, |
---|
2165 | curr_acl_list_fname); |
---|
2166 | // archives themselves |
---|
2167 | res = move_files_to_stream(curr_afioball_fname, NULL); |
---|
2168 | } else { |
---|
2169 | if (g_getfacl) { |
---|
2170 | if (g_getfattr) { |
---|
2171 | res = move_files_to_cd(curr_filelist_fname, |
---|
2172 | curr_xattr_list_fname, |
---|
2173 | curr_acl_list_fname, |
---|
2174 | curr_afioball_fname, NULL); |
---|
2175 | } else { |
---|
2176 | res = move_files_to_cd(curr_filelist_fname, |
---|
2177 | curr_acl_list_fname, |
---|
2178 | curr_afioball_fname, NULL); |
---|
2179 | } |
---|
2180 | } else { |
---|
2181 | if (g_getfattr) { |
---|
2182 | res = move_files_to_cd(curr_filelist_fname, |
---|
2183 | curr_xattr_list_fname, |
---|
2184 | curr_afioball_fname, NULL); |
---|
2185 | } else { |
---|
2186 | res = move_files_to_cd(curr_filelist_fname, |
---|
2187 | curr_afioball_fname, NULL); |
---|
2188 | } |
---|
2189 | } |
---|
2190 | } |
---|
2191 | retval += res; |
---|
2192 | g_current_progress++; |
---|
2193 | update_progress_form(media_usage_comment); |
---|
2194 | |
---|
2195 | if (res) { |
---|
2196 | mr_asprintf(&tmp, "Failed to add archive %ld's files to CD dir\n", |
---|
2197 | curr_set_no); |
---|
2198 | log_to_screen(tmp); |
---|
2199 | mr_free(tmp); |
---|
2200 | fatal_error |
---|
2201 | ("Is your hard disk is full? If not, please send the author the logfile."); |
---|
2202 | } |
---|
2203 | mr_free(curr_filelist_fname); |
---|
2204 | mr_free(curr_afioball_fname); |
---|
2205 | mr_free(curr_xattr_list_fname); |
---|
2206 | mr_free(curr_acl_list_fname); |
---|
2207 | mr_asprintf(&curr_filelist_fname, FILELIST_FNAME_RAW_SZ, |
---|
2208 | bkpinfo->tmpdir, ++curr_set_no); |
---|
2209 | } |
---|
2210 | mr_free(curr_filelist_fname); |
---|
2211 | close_progress_form(); |
---|
2212 | if (retval) { |
---|
2213 | log_to_screen |
---|
2214 | ("Your regular files have been archived (with errors)."); |
---|
2215 | } else { |
---|
2216 | log_to_screen |
---|
2217 | ("Your regular files have been archived successfully."); |
---|
2218 | } |
---|
2219 | mr_free(media_usage_comment); |
---|
2220 | return (retval); |
---|
2221 | } |
---|
2222 | |
---|
2223 | /* @} - end of LLarchiveGroup */ |
---|
2224 | |
---|
2225 | |
---|
2226 | /** |
---|
2227 | * Wrapper around @c make_afioballs_and_images(). |
---|
2228 | * @param bkpinfo the backup information structure. Only the |
---|
2229 | * @c backup_media_type field is used within this function. |
---|
2230 | * @return return code of make_afioballs_and_images |
---|
2231 | * @see make_afioballs_and_images |
---|
2232 | * @ingroup MLarchiveGroup |
---|
2233 | */ |
---|
2234 | int make_those_afios_phase() |
---|
2235 | { |
---|
2236 | /*@ int ******************************************* */ |
---|
2237 | int res = 0; |
---|
2238 | int retval = 0; |
---|
2239 | |
---|
2240 | assert(bkpinfo != NULL); |
---|
2241 | |
---|
2242 | mvaddstr_and_log_it(g_currentY, 0, |
---|
2243 | "Archiving regular files to media "); |
---|
2244 | |
---|
2245 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { |
---|
2246 | write_header_block_to_stream((off_t)0, "start-of-afioballs", |
---|
2247 | BLK_START_AFIOBALLS); |
---|
2248 | #if __FreeBSD__ == 5 |
---|
2249 | mr_msg(1, |
---|
2250 | "Using single-threaded make_afioballs_and_images() to suit b0rken FreeBSD 5.0"); |
---|
2251 | res = make_afioballs_and_images_OLD(); |
---|
2252 | #else |
---|
2253 | res = make_afioballs_and_images_OLD(); |
---|
2254 | #endif |
---|
2255 | write_header_block_to_stream((off_t)0, "stop-afioballs", |
---|
2256 | BLK_STOP_AFIOBALLS); |
---|
2257 | } else { |
---|
2258 | res = make_afioballs_and_images(); |
---|
2259 | } |
---|
2260 | |
---|
2261 | retval += res; |
---|
2262 | if (res) { |
---|
2263 | mvaddstr_and_log_it(g_currentY++, 74, "Errors."); |
---|
2264 | mr_msg(1, "make_afioballs_and_images returned an error"); |
---|
2265 | } else { |
---|
2266 | mvaddstr_and_log_it(g_currentY++, 74, "Done."); |
---|
2267 | } |
---|
2268 | return (retval); |
---|
2269 | } |
---|
2270 | |
---|
2271 | /** |
---|
2272 | * Wrapper around @c make_slices_and_images(). |
---|
2273 | * @param bkpinfo The backup information structure. Fields used: |
---|
2274 | * - @c backup_media_type |
---|
2275 | * - @c scratchdir |
---|
2276 | * - @c tmpdir |
---|
2277 | * @return The number of errors encountered (0 for success) |
---|
2278 | * @ingroup MLarchiveGroup |
---|
2279 | */ |
---|
2280 | int make_those_slices_phase() |
---|
2281 | { |
---|
2282 | |
---|
2283 | /*@ int ***************************************************** */ |
---|
2284 | int res = 0; |
---|
2285 | int retval = 0; |
---|
2286 | |
---|
2287 | /*@ buffers ************************************************** */ |
---|
2288 | char *biggielist = NULL; |
---|
2289 | char *command = NULL; |
---|
2290 | char *blah = NULL; |
---|
2291 | char *xattr_fname = NULL; |
---|
2292 | char *acl_fname = NULL; |
---|
2293 | |
---|
2294 | assert(bkpinfo != NULL); |
---|
2295 | /* slice big files */ |
---|
2296 | mvaddstr_and_log_it(g_currentY, 0, |
---|
2297 | "Archiving large files to media "); |
---|
2298 | mr_asprintf(&biggielist, "%s/archives/biggielist.txt", bkpinfo->scratchdir); |
---|
2299 | if (g_getfattr) { |
---|
2300 | mr_asprintf(&xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); |
---|
2301 | } |
---|
2302 | if (g_getfacl) { |
---|
2303 | mr_asprintf(&acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); |
---|
2304 | } |
---|
2305 | |
---|
2306 | mr_asprintf(&command, "cp %s/biggielist.txt %s", bkpinfo->tmpdir, biggielist); |
---|
2307 | paranoid_system(command); |
---|
2308 | mr_free(command); |
---|
2309 | |
---|
2310 | mr_asprintf(&blah, "biggielist = %s", biggielist); |
---|
2311 | mr_msg(2, blah); |
---|
2312 | mr_free(blah); |
---|
2313 | |
---|
2314 | if (!does_file_exist(biggielist)) { |
---|
2315 | mr_msg(1, "BTW, the biggielist does not exist"); |
---|
2316 | } |
---|
2317 | |
---|
2318 | if (g_getfattr) { |
---|
2319 | get_fattr_list(biggielist, xattr_fname); |
---|
2320 | mr_asprintf(&command, "cp %s %s/archives/", xattr_fname, bkpinfo->scratchdir); |
---|
2321 | paranoid_system(command); |
---|
2322 | mr_free(command); |
---|
2323 | } |
---|
2324 | if (g_getfacl) { |
---|
2325 | get_acl_list(biggielist, acl_fname); |
---|
2326 | mr_asprintf(&command, "cp %s %s/archives/", acl_fname, bkpinfo->scratchdir); |
---|
2327 | paranoid_system(command); |
---|
2328 | mr_free(command); |
---|
2329 | } |
---|
2330 | |
---|
2331 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { |
---|
2332 | res += write_EXAT_files_to_tape(xattr_fname, acl_fname); |
---|
2333 | mr_asprintf(&blah, "%ld", count_lines_in_file(biggielist)); |
---|
2334 | write_header_block_to_stream((off_t)0, blah, BLK_START_BIGGIEFILES); |
---|
2335 | mr_free(blah); |
---|
2336 | } |
---|
2337 | if (g_getfattr) { |
---|
2338 | mr_free(xattr_fname); |
---|
2339 | } |
---|
2340 | if (g_getfacl) { |
---|
2341 | mr_free(acl_fname); |
---|
2342 | } |
---|
2343 | |
---|
2344 | res = make_slices_and_images(biggielist); |
---|
2345 | mr_free(biggielist); |
---|
2346 | |
---|
2347 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { |
---|
2348 | write_header_block_to_stream((off_t)0, "end-of-biggiefiles", |
---|
2349 | BLK_STOP_BIGGIEFILES); |
---|
2350 | } |
---|
2351 | retval += res; |
---|
2352 | if (res) { |
---|
2353 | mr_msg(1, "make_slices_and_images returned an error"); |
---|
2354 | mvaddstr_and_log_it(g_currentY++, 74, "Errors."); |
---|
2355 | } else { |
---|
2356 | mvaddstr_and_log_it(g_currentY++, 74, "Done."); |
---|
2357 | } |
---|
2358 | return (retval); |
---|
2359 | } |
---|
2360 | |
---|
2361 | |
---|
2362 | /** |
---|
2363 | * @addtogroup LLarchiveGroup |
---|
2364 | * @{ |
---|
2365 | */ |
---|
2366 | /** |
---|
2367 | * Function pointer to an appropriate @c move_files_to_cd routine. |
---|
2368 | * You can set this to your own function (for example, one to |
---|
2369 | * transfer files over the network) or leave it as is. |
---|
2370 | */ |
---|
2371 | int (*move_files_to_cd) (char *, ...) = |
---|
2372 | _move_files_to_cd; |
---|
2373 | |
---|
2374 | /** |
---|
2375 | * Move some files to the ISO scratch directory. |
---|
2376 | * This function moves files specified as parameters, into the directory |
---|
2377 | * @c bkpinfo->scratchdir, where the files that will be stored on the next |
---|
2378 | * CD are waiting. |
---|
2379 | * |
---|
2380 | * @param bkpinfo The backup information structure. Fields used: |
---|
2381 | * - @c media_size |
---|
2382 | * - @c scratchdir |
---|
2383 | * @param files_to_add The files to add to the scratchdir. |
---|
2384 | * @warning The list of @c files_to_add must be terminated with @c NULL. |
---|
2385 | * @note If and when the space occupied by the scratchdir would exceed |
---|
2386 | * the capacity of the current CD, |
---|
2387 | * <tt>write_iso_and_go_on(bkpinfo, FALSE)</tt> is called and the |
---|
2388 | * scratchdir is emptied. |
---|
2389 | * |
---|
2390 | * @return The number of errors encountered (0 for success) |
---|
2391 | */ |
---|
2392 | int _move_files_to_cd(char *files_to_add, ...) |
---|
2393 | { |
---|
2394 | |
---|
2395 | /*@ int ************************************************************ */ |
---|
2396 | int retval = 0; |
---|
2397 | int res = 0; |
---|
2398 | |
---|
2399 | /*@ buffers ******************************************************** */ |
---|
2400 | char *tmp = NULL; |
---|
2401 | char *curr_file = NULL; |
---|
2402 | char *cf = NULL; |
---|
2403 | |
---|
2404 | /*@ long ************************************************************ */ |
---|
2405 | va_list ap; |
---|
2406 | long long would_occupy; |
---|
2407 | |
---|
2408 | assert(bkpinfo != NULL); |
---|
2409 | would_occupy = space_occupied_by_cd(bkpinfo->scratchdir); |
---|
2410 | va_start(ap, files_to_add); // initialize the variable arguments |
---|
2411 | for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) { |
---|
2412 | if (!cf) { |
---|
2413 | continue; |
---|
2414 | } |
---|
2415 | mr_asprintf(&curr_file, cf); |
---|
2416 | if (!does_file_exist(curr_file)) { |
---|
2417 | mr_msg(1, |
---|
2418 | "Warning - you're trying to add a non-existent file - '%s' to the CD", |
---|
2419 | curr_file); |
---|
2420 | } else { |
---|
2421 | mr_msg(8, "Trying to add file %s to CD", curr_file); |
---|
2422 | would_occupy += length_of_file(curr_file) / 1024; |
---|
2423 | } |
---|
2424 | mr_free(curr_file); |
---|
2425 | } |
---|
2426 | va_end(ap); |
---|
2427 | |
---|
2428 | if (bkpinfo->media_size <= 0L) { |
---|
2429 | fatal_error("move_files_to_cd() - unknown media size"); |
---|
2430 | } |
---|
2431 | if (would_occupy / 1024 > bkpinfo->media_size) { |
---|
2432 | /* FALSE because this is not the last CD we'll write */ |
---|
2433 | res = write_iso_and_go_on(FALSE); |
---|
2434 | retval += res; |
---|
2435 | if (res) { |
---|
2436 | mr_msg(1, "WARNING - write_iso_and_go_on returned an error"); |
---|
2437 | } |
---|
2438 | } |
---|
2439 | |
---|
2440 | va_start(ap, files_to_add); // initialize the variable arguments |
---|
2441 | for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) { |
---|
2442 | if (!cf) { |
---|
2443 | continue; |
---|
2444 | } |
---|
2445 | mr_asprintf(&curr_file, cf); |
---|
2446 | |
---|
2447 | mr_asprintf(&tmp, "mv -f %s %s/archives/", curr_file, |
---|
2448 | bkpinfo->scratchdir); |
---|
2449 | res = run_program_and_log_output(tmp, 5); |
---|
2450 | retval += res; |
---|
2451 | if (res) { |
---|
2452 | mr_msg(1, "(move_files_to_cd) '%s' failed", tmp); |
---|
2453 | } else { |
---|
2454 | mr_msg(8, "Moved %s to CD OK", tmp); |
---|
2455 | } |
---|
2456 | mr_free(tmp); |
---|
2457 | mr_free(curr_file); |
---|
2458 | // unlink (curr_file); |
---|
2459 | } |
---|
2460 | va_end(ap); |
---|
2461 | |
---|
2462 | if (retval) { |
---|
2463 | mr_msg(1, |
---|
2464 | "Warning - errors occurred while I was adding files to CD dir"); |
---|
2465 | } |
---|
2466 | return (retval); |
---|
2467 | } |
---|
2468 | |
---|
2469 | /* @} - end of LLarchiveGroup */ |
---|
2470 | |
---|
2471 | |
---|
2472 | /** |
---|
2473 | * @addtogroup LLarchiveGroup |
---|
2474 | * @{ |
---|
2475 | */ |
---|
2476 | /** |
---|
2477 | * Function pointer to an appropriate @c move_files_to_stream routine. |
---|
2478 | * You can set this to your own function (for example, one to |
---|
2479 | * transfer files over the network) or leave it as is. |
---|
2480 | */ |
---|
2481 | int (*move_files_to_stream) (char *, ...) = |
---|
2482 | _move_files_to_stream; |
---|
2483 | |
---|
2484 | /** |
---|
2485 | * Copy some files to tape. |
---|
2486 | * This function copies the files specified as parameters into the tape stream. |
---|
2487 | * |
---|
2488 | * @param bkpinfo The backup information structure. Used only in the call to |
---|
2489 | * @c write_file_to_stream_from_file(). |
---|
2490 | * |
---|
2491 | * @param files_to_add The files to copy to the tape stream. |
---|
2492 | * @warning The list of @c files_to_add must be terminated with @c NULL. |
---|
2493 | * @note Files may be split across multiple tapes if necessary. |
---|
2494 | * |
---|
2495 | * @return The number of errors encountered (0 for success) |
---|
2496 | */ |
---|
2497 | int |
---|
2498 | _move_files_to_stream(char *files_to_add, ...) |
---|
2499 | { |
---|
2500 | |
---|
2501 | /*@ int ************************************************************ */ |
---|
2502 | int retval = 0; |
---|
2503 | int res = 0; |
---|
2504 | /*@ buffers ******************************************************** */ |
---|
2505 | |
---|
2506 | /*@ char *********************************************************** */ |
---|
2507 | char start_chr; |
---|
2508 | char stop_chr; |
---|
2509 | char *curr_file = NULL; |
---|
2510 | char *cf = NULL; |
---|
2511 | /*@ long long ****************************************************** */ |
---|
2512 | off_t length_of_incoming_file = (off_t)0; |
---|
2513 | t_archtype type; |
---|
2514 | va_list ap; |
---|
2515 | |
---|
2516 | assert(bkpinfo != NULL); |
---|
2517 | va_start(ap, files_to_add); |
---|
2518 | for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) { |
---|
2519 | if (!cf) { |
---|
2520 | continue; |
---|
2521 | } |
---|
2522 | mr_asprintf(&curr_file, cf); |
---|
2523 | if (!does_file_exist(curr_file)) { |
---|
2524 | mr_msg(1, |
---|
2525 | "Warning - you're trying to add a non-existent file - '%s' to the tape", |
---|
2526 | curr_file); |
---|
2527 | } |
---|
2528 | /* create header chars */ |
---|
2529 | start_chr = BLK_START_AN_AFIO_OR_SLICE; |
---|
2530 | stop_chr = BLK_STOP_AN_AFIO_OR_SLICE; |
---|
2531 | /* ask for new tape if necessary */ |
---|
2532 | length_of_incoming_file = length_of_file(curr_file); |
---|
2533 | write_header_block_to_stream(length_of_incoming_file, curr_file, |
---|
2534 | start_chr); |
---|
2535 | if (strstr(curr_file, ".afio.") || strstr(curr_file, ".star.")) { |
---|
2536 | type = fileset; |
---|
2537 | } else if (strstr(curr_file, "slice")) { |
---|
2538 | type = biggieslice; |
---|
2539 | } else { |
---|
2540 | type = other; |
---|
2541 | } |
---|
2542 | res = write_file_to_stream_from_file(curr_file); |
---|
2543 | retval += res; |
---|
2544 | unlink(curr_file); |
---|
2545 | mr_free(curr_file); |
---|
2546 | /* write closing header */ |
---|
2547 | write_header_block_to_stream((off_t)0, "finished-writing-file", stop_chr); |
---|
2548 | } |
---|
2549 | va_end(ap); |
---|
2550 | |
---|
2551 | if (retval) { |
---|
2552 | mr_msg(1, |
---|
2553 | "Warning - errors occurred while I was adding file to tape"); |
---|
2554 | } |
---|
2555 | return (retval); |
---|
2556 | } |
---|
2557 | |
---|
2558 | /* @} - end of LLarchiveGroup */ |
---|
2559 | |
---|
2560 | |
---|
2561 | /** |
---|
2562 | * @addtogroup utilityGroup |
---|
2563 | * @{ |
---|
2564 | */ |
---|
2565 | /** |
---|
2566 | * Make sure the user has a valid CD-R(W) in the CD drive. |
---|
2567 | * @param cdrw_dev Set to the CD-R(W) device checked. |
---|
2568 | * @param keep_looping If TRUE, keep pestering user until they insist |
---|
2569 | * or insert a correct CD; if FALSE, only check once. |
---|
2570 | * @return 0 (there was an OK CD in the drive) or 1 (there wasn't). |
---|
2571 | */ |
---|
2572 | int interrogate_disk_currently_in_cdrw_drive(char *cdrw_dev, |
---|
2573 | bool keep_looping) |
---|
2574 | { |
---|
2575 | int res = 0; |
---|
2576 | char *bkp = NULL; |
---|
2577 | char *cdrecord = NULL; |
---|
2578 | |
---|
2579 | malloc_string(bkp); |
---|
2580 | strcpy(bkp, cdrw_dev); |
---|
2581 | if (find_cdrw_device(cdrw_dev)) { |
---|
2582 | strcpy(cdrw_dev, bkp); |
---|
2583 | } else { |
---|
2584 | if (!system("which cdrecord > /dev/null 2> /dev/null")) { |
---|
2585 | mr_asprintf(&cdrecord, "cdrecord dev=%s -atip", cdrw_dev); |
---|
2586 | } else if (!system("which dvdrecord > /dev/null 2> /dev/null")) { |
---|
2587 | mr_asprintf(&cdrecord, "dvdrecord dev=%s -atip", cdrw_dev); |
---|
2588 | } else { |
---|
2589 | mr_msg(2, "Oh well. I guess I'll just pray then."); |
---|
2590 | } |
---|
2591 | if (cdrecord != NULL) { |
---|
2592 | if (!keep_looping) { |
---|
2593 | retract_CD_tray_and_defeat_autorun(); |
---|
2594 | res = run_program_and_log_output(cdrecord, 5); |
---|
2595 | } else { |
---|
2596 | while ((res = run_program_and_log_output(cdrecord, 5))) { |
---|
2597 | retract_CD_tray_and_defeat_autorun(); |
---|
2598 | if (ask_me_yes_or_no |
---|
2599 | ("Unable to examine CD. Are you sure this is a valid CD-R(W) CD?")) |
---|
2600 | { |
---|
2601 | mr_msg(1, "Well, he insisted..."); |
---|
2602 | break; |
---|
2603 | } |
---|
2604 | } |
---|
2605 | } |
---|
2606 | } |
---|
2607 | mr_free(cdrecord); |
---|
2608 | } |
---|
2609 | // retract_CD_tray_and_defeat_autorun(); |
---|
2610 | mr_free(bkp); |
---|
2611 | return (res); |
---|
2612 | } |
---|
2613 | |
---|
2614 | |
---|
2615 | /** |
---|
2616 | * Asks the user to put a CD-R(W) in the drive. |
---|
2617 | * @param ask_for_one_if_more_than_this (unused) |
---|
2618 | */ |
---|
2619 | void |
---|
2620 | pause_and_ask_for_cdr(int ask_for_one_if_more_than_this) |
---|
2621 | { |
---|
2622 | |
---|
2623 | /*@ buffers ********************************************* */ |
---|
2624 | char *tmp = NULL; |
---|
2625 | char *szmsg = NULL; |
---|
2626 | char *cdrom_dev = NULL; |
---|
2627 | char *cdrw_dev = NULL; |
---|
2628 | char *our_serial_str = NULL; |
---|
2629 | bool ok_go_ahead_burn_it; |
---|
2630 | int cd_number = -1; |
---|
2631 | int attempt_to_mount_returned_this = 999; |
---|
2632 | char *mtpt = NULL; |
---|
2633 | char *szcdno = NULL; |
---|
2634 | char *szserfname = NULL; |
---|
2635 | char *szunmount = NULL; |
---|
2636 | |
---|
2637 | malloc_string(szmsg); |
---|
2638 | malloc_string(cdrom_dev); |
---|
2639 | malloc_string(cdrw_dev); |
---|
2640 | malloc_string(mtpt); |
---|
2641 | malloc_string(szcdno); |
---|
2642 | malloc_string(szserfname); |
---|
2643 | malloc_string(our_serial_str); |
---|
2644 | malloc_string(szunmount); |
---|
2645 | |
---|
2646 | sprintf(szmsg, "I am about to burn %s #%d", |
---|
2647 | media_descriptor_string(g_backup_media_type), |
---|
2648 | g_current_media_number); |
---|
2649 | log_to_screen(szmsg); |
---|
2650 | if (g_current_media_number < ask_for_one_if_more_than_this) { |
---|
2651 | return; |
---|
2652 | } |
---|
2653 | log_to_screen("Scanning CD-ROM drive..."); |
---|
2654 | sprintf(mtpt, "%s/cd.mtpt", bkpinfo->tmpdir); |
---|
2655 | make_hole_for_dir(mtpt); |
---|
2656 | |
---|
2657 | gotos_make_me_puke: |
---|
2658 | ok_go_ahead_burn_it = TRUE; |
---|
2659 | if (!find_cdrom_device(cdrom_dev, FALSE)) { |
---|
2660 | /* When enabled, it made CD eject-and-retract when wrong CD inserted.. Weird |
---|
2661 | mr_msg(2, "paafcd: Retracting CD-ROM drive if possible" ); |
---|
2662 | retract_CD_tray_and_defeat_autorun(); |
---|
2663 | */ |
---|
2664 | mr_asprintf(&tmp, "umount %s", cdrom_dev); |
---|
2665 | run_program_and_log_output(tmp, 1); |
---|
2666 | mr_free(tmp); |
---|
2667 | sprintf(szcdno, "%s/archives/THIS-CD-NUMBER", mtpt); |
---|
2668 | sprintf(szserfname, "%s/archives/SERIAL-STRING", mtpt); |
---|
2669 | sprintf(szunmount, "umount %s", mtpt); |
---|
2670 | cd_number = -1; |
---|
2671 | our_serial_str[0] = '\0'; |
---|
2672 | mr_asprintf(&tmp, "mount %s %s", cdrom_dev, mtpt); |
---|
2673 | attempt_to_mount_returned_this = run_program_and_log_output(tmp, 1); |
---|
2674 | mr_free(tmp); |
---|
2675 | if (attempt_to_mount_returned_this) { |
---|
2676 | mr_msg(4, "Failed to mount %s at %s", cdrom_dev, mtpt); |
---|
2677 | log_to_screen("If there's a CD/DVD in the drive, it's blank."); |
---|
2678 | } else if (!does_file_exist(szcdno) |
---|
2679 | || !does_file_exist(szserfname)) { |
---|
2680 | log_to_screen |
---|
2681 | ("%s has data on it but it's probably not a Mondo CD.", |
---|
2682 | media_descriptor_string(g_backup_media_type)); |
---|
2683 | } else { |
---|
2684 | log_to_screen("%s found in drive. It's a Mondo disk.", |
---|
2685 | media_descriptor_string(g_backup_media_type)); |
---|
2686 | cd_number = atoi(last_line_of_file(szcdno)); |
---|
2687 | mr_asprintf(&tmp, "cat %s 2> /dev/null", szserfname); |
---|
2688 | strcpy(our_serial_str, |
---|
2689 | call_program_and_get_last_line_of_output(tmp)); |
---|
2690 | mr_free(tmp); |
---|
2691 | // FIXME - should be able to use last_line_of_file(), surely? |
---|
2692 | } |
---|
2693 | run_program_and_log_output(szunmount, 1); |
---|
2694 | mr_msg(2, "paafcd: cd_number = %d", cd_number); |
---|
2695 | mr_msg(2, "our serial str = %s; g_serial_string = %s", |
---|
2696 | our_serial_str, g_serial_string); |
---|
2697 | if (cd_number > 0 && !strcmp(our_serial_str, g_serial_string)) { |
---|
2698 | mr_msg(2, "This %s is part of this backup set!", |
---|
2699 | media_descriptor_string(g_backup_media_type)); |
---|
2700 | ok_go_ahead_burn_it = FALSE; |
---|
2701 | if (cd_number == g_current_media_number - 1) { |
---|
2702 | log_to_screen |
---|
2703 | ("I think you've left the previous %s in the drive.", |
---|
2704 | media_descriptor_string(g_backup_media_type)); |
---|
2705 | } else { |
---|
2706 | log_to_screen |
---|
2707 | ("Please remove this %s. It is part of the backup set you're making now.", |
---|
2708 | media_descriptor_string(g_backup_media_type)); |
---|
2709 | } |
---|
2710 | } else { |
---|
2711 | log_to_screen("...but not part of _our_ backup set."); |
---|
2712 | } |
---|
2713 | } else { |
---|
2714 | mr_msg(2, |
---|
2715 | "paafcd: Can't find CD-ROM drive. Perhaps it has a blank %s in it?", |
---|
2716 | media_descriptor_string(g_backup_media_type)); |
---|
2717 | if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE)) { |
---|
2718 | ok_go_ahead_burn_it = FALSE; |
---|
2719 | log_to_screen("There isn't a writable %s in the drive.", |
---|
2720 | media_descriptor_string(g_backup_media_type)); |
---|
2721 | } |
---|
2722 | } |
---|
2723 | |
---|
2724 | if (!ok_go_ahead_burn_it) { |
---|
2725 | eject_device(cdrom_dev); |
---|
2726 | mr_asprintf(&tmp, |
---|
2727 | "I am about to burn %s #%d of the backup set. Please insert %s and press Enter.", |
---|
2728 | media_descriptor_string(g_backup_media_type), |
---|
2729 | g_current_media_number, |
---|
2730 | media_descriptor_string(g_backup_media_type)); |
---|
2731 | popup_and_OK(tmp); |
---|
2732 | mr_free(tmp); |
---|
2733 | goto gotos_make_me_puke; |
---|
2734 | } else { |
---|
2735 | mr_msg(2, "paafcd: OK, going ahead and burning it."); |
---|
2736 | } |
---|
2737 | |
---|
2738 | mr_msg(2, |
---|
2739 | "paafcd: OK, I assume I have a blank/reusable %s in the drive...", |
---|
2740 | media_descriptor_string(g_backup_media_type)); |
---|
2741 | |
---|
2742 | // if (ask_for_one_if_more_than_this>1) { popup_and_OK(szmsg); } |
---|
2743 | |
---|
2744 | log_to_screen("Proceeding w/ %s in drive.", |
---|
2745 | media_descriptor_string(g_backup_media_type)); |
---|
2746 | mr_free(szmsg); |
---|
2747 | mr_free(cdrom_dev); |
---|
2748 | mr_free(cdrw_dev); |
---|
2749 | mr_free(mtpt); |
---|
2750 | mr_free(szcdno); |
---|
2751 | mr_free(szserfname); |
---|
2752 | mr_free(our_serial_str); |
---|
2753 | mr_free(szunmount); |
---|
2754 | } |
---|
2755 | |
---|
2756 | |
---|
2757 | /** |
---|
2758 | * Set the <tt>N</tt>th bit of @c array to @c true_or_false. |
---|
2759 | * @param array The bit array (as a @c char pointer). |
---|
2760 | * @param N The bit number to set or reset. |
---|
2761 | * @param true_or_false If TRUE then set bit @c N, if FALSE then reset bit @c N. |
---|
2762 | * @see get_bit_N_of_array |
---|
2763 | */ |
---|
2764 | void set_bit_N_of_array(char *array, int N, bool true_or_false) |
---|
2765 | { |
---|
2766 | int bit_number; |
---|
2767 | int mask, orig_val, to_add; |
---|
2768 | int element_number; |
---|
2769 | |
---|
2770 | assert(array != NULL); |
---|
2771 | |
---|
2772 | element_number = N / 8; |
---|
2773 | bit_number = N % 8; |
---|
2774 | to_add = (1 << bit_number); |
---|
2775 | mask = 255 - to_add; |
---|
2776 | orig_val = array[element_number] & mask; |
---|
2777 | // log_it("array[%d]=%02x; %02x&%02x = %02x", element_number, array[element_number], mask, orig_val); |
---|
2778 | if (true_or_false) { |
---|
2779 | array[element_number] = orig_val | to_add; |
---|
2780 | } |
---|
2781 | } |
---|
2782 | |
---|
2783 | /* @} - end of utilityGroup */ |
---|
2784 | |
---|
2785 | |
---|
2786 | /** |
---|
2787 | * Chop up @c filename. |
---|
2788 | * @param bkpinfo The backup information structure. Fields used: |
---|
2789 | * - @c backup_media_type |
---|
2790 | * - @c compression_level |
---|
2791 | * - @c optimal_set_size |
---|
2792 | * - @c tmpdir |
---|
2793 | * - @c use_lzo |
---|
2794 | * - @c compression_tool |
---|
2795 | * - @c compression_suffix |
---|
2796 | * |
---|
2797 | * @param biggie_filename The file to chop up. |
---|
2798 | * @param ntfsprog_fifo The FIFO to ntfsclone if this is an imagedev, NULL otherwise. |
---|
2799 | * @param biggie_file_number The sequence number of this biggie file (starting from 0). |
---|
2800 | * @param noof_biggie_files The number of biggie files there are total. |
---|
2801 | * @return The number of errors encountered (0 for success) |
---|
2802 | * @see make_slices_and_images |
---|
2803 | * @ingroup LLarchiveGroup |
---|
2804 | */ |
---|
2805 | int |
---|
2806 | slice_up_file_etc(char *biggie_filename, |
---|
2807 | char *ntfsprog_fifo, long biggie_file_number, |
---|
2808 | long noof_biggie_files, bool use_ntfsprog) |
---|
2809 | { |
---|
2810 | |
---|
2811 | /*@ buffers ************************************************** */ |
---|
2812 | char *tmp = NULL; |
---|
2813 | char *checksum_line = NULL; |
---|
2814 | char *command = NULL; |
---|
2815 | char *tempblock = NULL; |
---|
2816 | char *curr_slice_fname_uncompressed = NULL; |
---|
2817 | char *curr_slice_fname_compressed = NULL; |
---|
2818 | char *file_to_archive = NULL; |
---|
2819 | char *file_to_openin = NULL; |
---|
2820 | /*@ pointers ************************************************** */ |
---|
2821 | char *pB = NULL; |
---|
2822 | FILE *fin = NULL; |
---|
2823 | FILE *fout = NULL; |
---|
2824 | |
---|
2825 | /*@ bool ****************************************************** */ |
---|
2826 | bool finished = FALSE; |
---|
2827 | |
---|
2828 | /*@ long ****************************************************** */ |
---|
2829 | size_t blksize = 0; |
---|
2830 | long slice_num = 0; |
---|
2831 | long i; |
---|
2832 | long optimal_set_size; |
---|
2833 | bool should_I_compress_slices; |
---|
2834 | char *suffix = NULL; // for compressed slices |
---|
2835 | |
---|
2836 | /*@ long long ************************************************** */ |
---|
2837 | off_t totalread = (off_t)0; |
---|
2838 | off_t totallength = (off_t)0; |
---|
2839 | off_t length; |
---|
2840 | |
---|
2841 | /*@ int ******************************************************** */ |
---|
2842 | int retval = 0; |
---|
2843 | int res = 0; |
---|
2844 | size_t n = 0; |
---|
2845 | |
---|
2846 | /*@ structures ************************************************** */ |
---|
2847 | struct s_filename_and_lstat_info biggiestruct; |
---|
2848 | // struct stat statbuf; |
---|
2849 | |
---|
2850 | assert(bkpinfo != NULL); |
---|
2851 | assert_string_is_neither_NULL_nor_zerolength(biggie_filename); |
---|
2852 | |
---|
2853 | biggiestruct.for_backward_compatibility = '\n'; |
---|
2854 | biggiestruct.use_ntfsprog = use_ntfsprog; |
---|
2855 | optimal_set_size = bkpinfo->optimal_set_size; |
---|
2856 | |
---|
2857 | if (optimal_set_size < 999) { |
---|
2858 | fatal_error("bkpinfo->optimal_set_size is insanely small"); |
---|
2859 | } |
---|
2860 | if (ntfsprog_fifo) { |
---|
2861 | file_to_openin = ntfsprog_fifo; |
---|
2862 | mr_asprintf(&checksum_line, "IGNORE"); |
---|
2863 | mr_msg(2, |
---|
2864 | "Not calculating checksum for %s: it would take too long", |
---|
2865 | biggie_filename); |
---|
2866 | if ( !find_home_of_exe("ntfsresize")) { |
---|
2867 | fatal_error("ntfsresize not found"); |
---|
2868 | } |
---|
2869 | mr_asprintf(&command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", biggie_filename); |
---|
2870 | log_it("command = %s", command); |
---|
2871 | mr_asprintf(&tmp, call_program_and_get_last_line_of_output(command)); |
---|
2872 | mr_free(command); |
---|
2873 | |
---|
2874 | log_it("res of it = %s", tmp); |
---|
2875 | totallength = (off_t)atoll(tmp); |
---|
2876 | mr_free(tmp); |
---|
2877 | } else { |
---|
2878 | file_to_openin = biggie_filename; |
---|
2879 | if (strchr(biggie_filename,'\'') != NULL) { |
---|
2880 | mr_asprintf(&command, "md5sum \"%s\"", biggie_filename); |
---|
2881 | } else { |
---|
2882 | mr_asprintf(&command, "md5sum '%s'", biggie_filename); |
---|
2883 | } |
---|
2884 | if (!(fin = popen(command, "r"))) { |
---|
2885 | log_OS_error("Unable to popen-in command"); |
---|
2886 | mr_free(command); |
---|
2887 | return (1); |
---|
2888 | } |
---|
2889 | mr_free(command); |
---|
2890 | mr_getline(&checksum_line, &n, fin); |
---|
2891 | pclose(fin); |
---|
2892 | totallength = length_of_file (biggie_filename); |
---|
2893 | } |
---|
2894 | lstat(biggie_filename, &biggiestruct.properties); |
---|
2895 | if (strlen(biggie_filename) <= MAX_STR_LEN) { |
---|
2896 | strcpy(biggiestruct.filename, biggie_filename); |
---|
2897 | } else { |
---|
2898 | fatal_error("biggie_filename too big"); |
---|
2899 | } |
---|
2900 | pB = strchr(checksum_line, ' '); |
---|
2901 | if (!pB) { |
---|
2902 | pB = strchr(checksum_line, '\t'); |
---|
2903 | } |
---|
2904 | if (pB) { |
---|
2905 | *pB = '\0'; |
---|
2906 | } |
---|
2907 | if (strlen(checksum_line) <= 64) { |
---|
2908 | strcpy(biggiestruct.checksum, checksum_line); |
---|
2909 | } else { |
---|
2910 | fatal_error("checksum_line too big"); |
---|
2911 | } |
---|
2912 | mr_free(checksum_line); |
---|
2913 | |
---|
2914 | mr_asprintf(&tmp, slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, "")); |
---|
2915 | fout = mr_fopen(tmp, "w"); |
---|
2916 | mr_free(tmp); |
---|
2917 | |
---|
2918 | (void) fwrite((void *) &biggiestruct, 1, sizeof(biggiestruct), fout); |
---|
2919 | if (fout) { |
---|
2920 | mr_fclose(fout); |
---|
2921 | } |
---|
2922 | length = totallength / optimal_set_size / 1024; |
---|
2923 | mr_msg(1, "Opening in %s; slicing it and writing to CD/tape", |
---|
2924 | file_to_openin); |
---|
2925 | if (!(fin = fopen(file_to_openin, "r"))) { |
---|
2926 | log_OS_error("Unable to openin biggie_filename"); |
---|
2927 | mr_asprintf(&tmp, "Cannot archive bigfile '%s': not found", |
---|
2928 | biggie_filename); |
---|
2929 | log_to_screen(tmp); |
---|
2930 | mr_free(tmp); |
---|
2931 | return (1); |
---|
2932 | } |
---|
2933 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { |
---|
2934 | res = |
---|
2935 | move_files_to_stream(slice_fname(biggie_file_number, 0, |
---|
2936 | bkpinfo->tmpdir, ""), NULL); |
---|
2937 | } else { |
---|
2938 | res = |
---|
2939 | move_files_to_cd(slice_fname(biggie_file_number, 0, |
---|
2940 | bkpinfo->tmpdir, ""), NULL); |
---|
2941 | } |
---|
2942 | if (is_this_file_compressed(biggie_filename) |
---|
2943 | || bkpinfo->compression_level == 0) { |
---|
2944 | mr_asprintf(&suffix, ""); |
---|
2945 | should_I_compress_slices = FALSE; |
---|
2946 | } else { |
---|
2947 | mr_asprintf(&suffix, bkpinfo->compression_suffix); |
---|
2948 | should_I_compress_slices = TRUE; |
---|
2949 | } |
---|
2950 | i = bkpinfo->optimal_set_size / 256; |
---|
2951 | for (slice_num = 1; !finished; slice_num++) { |
---|
2952 | mr_asprintf(&curr_slice_fname_uncompressed, |
---|
2953 | slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir, |
---|
2954 | "")); |
---|
2955 | mr_asprintf(&curr_slice_fname_compressed, |
---|
2956 | slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir, |
---|
2957 | suffix)); |
---|
2958 | |
---|
2959 | mr_asprintf(&tmp, percent_media_full_comment()); |
---|
2960 | update_progress_form(tmp); |
---|
2961 | mr_free(tmp); |
---|
2962 | |
---|
2963 | if (!(fout = fopen(curr_slice_fname_uncompressed, "w"))) { |
---|
2964 | log_OS_error(curr_slice_fname_uncompressed); |
---|
2965 | mr_free(curr_slice_fname_uncompressed); |
---|
2966 | mr_free(curr_slice_fname_compressed); |
---|
2967 | mr_free(suffix); |
---|
2968 | return (1); |
---|
2969 | } |
---|
2970 | tempblock = mr_malloc(256 * 1024); |
---|
2971 | if ((i == bkpinfo->optimal_set_size / 256) |
---|
2972 | && (totalread < 1.1 * totallength)) { |
---|
2973 | for (i = 0; i < bkpinfo->optimal_set_size / 256; i++) { |
---|
2974 | blksize = fread(tempblock, 1, 256 * 1024, fin); |
---|
2975 | if (blksize > 0) { |
---|
2976 | totalread = totalread + blksize; |
---|
2977 | (void) fwrite(tempblock, 1, blksize, fout); |
---|
2978 | } else { |
---|
2979 | break; |
---|
2980 | } |
---|
2981 | } |
---|
2982 | } else { |
---|
2983 | i = 0; |
---|
2984 | } |
---|
2985 | mr_free(tempblock); |
---|
2986 | paranoid_fclose(fout); |
---|
2987 | if (i > 0) // length_of_file (curr_slice_fname_uncompressed) |
---|
2988 | { |
---|
2989 | if (!does_file_exist(curr_slice_fname_uncompressed)) { |
---|
2990 | mr_msg(2, |
---|
2991 | "Warning - '%s' doesn't exist. How can I compress slice?", |
---|
2992 | curr_slice_fname_uncompressed); |
---|
2993 | } |
---|
2994 | if (should_I_compress_slices && bkpinfo->compression_level > 0) { |
---|
2995 | mr_asprintf(&command, "%s -%d %s", bkpinfo->compression_tool, |
---|
2996 | bkpinfo->compression_level, |
---|
2997 | curr_slice_fname_uncompressed); |
---|
2998 | mr_msg(2, command); |
---|
2999 | if ((res = system(command))) { |
---|
3000 | log_OS_error(command); |
---|
3001 | } |
---|
3002 | mr_free(command); |
---|
3003 | // did_I_compress_slice = TRUE; |
---|
3004 | } else { |
---|
3005 | /* BERLIOS: Useless |
---|
3006 | mr_asprintf(&command, "mv %s %s 2>> %s", |
---|
3007 | curr_slice_fname_uncompressed, |
---|
3008 | curr_slice_fname_compressed, MONDO_LOGFILE); |
---|
3009 | */ |
---|
3010 | res = 0; // don't do it :) |
---|
3011 | // did_I_compress_slice = FALSE; |
---|
3012 | } |
---|
3013 | retval += res; |
---|
3014 | if (res) { |
---|
3015 | mr_msg(2, "Failed to compress the slice"); |
---|
3016 | } |
---|
3017 | if ((bkpinfo->compression_type == lzo) |
---|
3018 | && strcmp(curr_slice_fname_compressed, |
---|
3019 | curr_slice_fname_uncompressed)) { |
---|
3020 | unlink(curr_slice_fname_uncompressed); |
---|
3021 | } |
---|
3022 | if (res) { |
---|
3023 | mr_asprintf(&tmp, "Problem with slice # %ld", slice_num); |
---|
3024 | } else { |
---|
3025 | mr_asprintf(&tmp, |
---|
3026 | "%s - Bigfile #%ld, slice #%ld compressed OK ", |
---|
3027 | biggie_filename, biggie_file_number + 1, |
---|
3028 | slice_num); |
---|
3029 | } |
---|
3030 | if (!g_text_mode) { |
---|
3031 | newtDrawRootText(0, g_noof_rows - 2, tmp); |
---|
3032 | newtRefresh(); |
---|
3033 | } else { |
---|
3034 | mr_msg(2, tmp); |
---|
3035 | } |
---|
3036 | mr_free(tmp); |
---|
3037 | mr_asprintf(&file_to_archive, curr_slice_fname_compressed); |
---|
3038 | g_current_progress++; |
---|
3039 | } else { /* if i==0 then ... */ |
---|
3040 | |
---|
3041 | finished = TRUE; |
---|
3042 | mr_asprintf(&file_to_archive, curr_slice_fname_uncompressed); |
---|
3043 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { |
---|
3044 | break; |
---|
3045 | } |
---|
3046 | } |
---|
3047 | |
---|
3048 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { |
---|
3049 | register_in_tape_catalog(biggieslice, biggie_file_number, |
---|
3050 | slice_num, file_to_archive); |
---|
3051 | maintain_collection_of_recent_archives(bkpinfo->tmpdir, |
---|
3052 | file_to_archive); |
---|
3053 | res = move_files_to_stream(file_to_archive, NULL); |
---|
3054 | } else { |
---|
3055 | res = move_files_to_cd(file_to_archive, NULL); |
---|
3056 | } |
---|
3057 | mr_free(file_to_archive); |
---|
3058 | retval += res; |
---|
3059 | if (res) { |
---|
3060 | mr_asprintf(&tmp, |
---|
3061 | "Failed to add slice %ld of bigfile %ld to scratchdir", |
---|
3062 | slice_num, biggie_file_number + 1); |
---|
3063 | log_to_screen(tmp); |
---|
3064 | mr_free(tmp); |
---|
3065 | fatal_error |
---|
3066 | ("Hard disk full. You should have bought a bigger one."); |
---|
3067 | } |
---|
3068 | mr_free(curr_slice_fname_uncompressed); |
---|
3069 | mr_free(curr_slice_fname_compressed); |
---|
3070 | } |
---|
3071 | mr_free(suffix); |
---|
3072 | paranoid_fclose(fin); |
---|
3073 | if (retval) { |
---|
3074 | mr_asprintf(&tmp, "Sliced bigfile #%ld...FAILED", |
---|
3075 | biggie_file_number + 1); |
---|
3076 | } else { |
---|
3077 | mr_asprintf(&tmp, "Sliced bigfile #%ld...OK!", |
---|
3078 | biggie_file_number + 1); |
---|
3079 | } |
---|
3080 | mr_msg(1, tmp); |
---|
3081 | mr_free(tmp); |
---|
3082 | return (retval); |
---|
3083 | } |
---|
3084 | |
---|
3085 | |
---|
3086 | /** |
---|
3087 | * Remove the archives in @c d. |
---|
3088 | * This could possibly include any of: |
---|
3089 | * - all afioballs (compressed and not) |
---|
3090 | * - all filelists |
---|
3091 | * - all slices |
---|
3092 | * - all checksums |
---|
3093 | * - a zero filler file |
---|
3094 | * |
---|
3095 | * @param d The directory to wipe the archives from. |
---|
3096 | * @ingroup utilityGroup |
---|
3097 | */ |
---|
3098 | void wipe_archives(char *d) |
---|
3099 | { |
---|
3100 | /*@ buffers ********************************************* */ |
---|
3101 | char *tmp = NULL; |
---|
3102 | char *dir = NULL; |
---|
3103 | |
---|
3104 | assert_string_is_neither_NULL_nor_zerolength(d); |
---|
3105 | |
---|
3106 | mr_asprintf(&dir, "%s/archives", d); |
---|
3107 | mr_asprintf(&tmp, "find %s -name '*.afio*' -exec rm -f '{}' \\;", dir); |
---|
3108 | run_program_and_log_output(tmp, FALSE); |
---|
3109 | mr_free(tmp); |
---|
3110 | mr_asprintf(&tmp, "find %s -name '*list.[0-9]*' -exec rm -f '{}' \\;", |
---|
3111 | dir); |
---|
3112 | run_program_and_log_output(tmp, FALSE); |
---|
3113 | mr_free(tmp); |
---|
3114 | |
---|
3115 | mr_asprintf(&tmp, "find %s -name 'slice*' -exec rm -f '{}' \\;", dir); |
---|
3116 | run_program_and_log_output(tmp, FALSE); |
---|
3117 | mr_free(tmp); |
---|
3118 | |
---|
3119 | mr_asprintf(&tmp, "rm -f %s/cklist*", dir); |
---|
3120 | run_program_and_log_output(tmp, FALSE); |
---|
3121 | mr_free(tmp); |
---|
3122 | |
---|
3123 | mr_asprintf(&tmp, "rm -f %s/zero", dir); |
---|
3124 | run_program_and_log_output(tmp, FALSE); |
---|
3125 | mr_free(tmp); |
---|
3126 | |
---|
3127 | mr_msg(1, "Wiped %s's archives", dir); |
---|
3128 | mr_asprintf(&tmp, "ls -l %s", dir); |
---|
3129 | run_program_and_log_output(tmp, FALSE); |
---|
3130 | mr_free(tmp); |
---|
3131 | |
---|
3132 | mr_free(dir); |
---|
3133 | } |
---|
3134 | |
---|
3135 | |
---|
3136 | /** |
---|
3137 | * @addtogroup LLarchiveGroup |
---|
3138 | * @{ |
---|
3139 | */ |
---|
3140 | /** |
---|
3141 | * Write the final ISO image. |
---|
3142 | * @param bkpinfo The backup information structure. Used only |
---|
3143 | * in the call to @c write_iso_and_go_on(). |
---|
3144 | * @return The number of errors encountered (0 for success) |
---|
3145 | * @see write_iso_and_go_on |
---|
3146 | * @see make_iso_fs |
---|
3147 | * @bug The final ISO is written even if there are no files on it. In practice, |
---|
3148 | * however, this occurs rarely. |
---|
3149 | */ |
---|
3150 | int write_final_iso_if_necessary() |
---|
3151 | { |
---|
3152 | /*@ int ***************************************************** */ |
---|
3153 | int res; |
---|
3154 | |
---|
3155 | /*@ buffers ************************************************** */ |
---|
3156 | char *tmp = NULL; |
---|
3157 | |
---|
3158 | assert(bkpinfo != NULL); |
---|
3159 | |
---|
3160 | // I should really check if there are any slices or tarballs to be copied to CD-R(W)'s; the odds are approx. 1 in a million that there are no files here, so I'll just go ahead & make one more CD anyway |
---|
3161 | |
---|
3162 | mr_asprintf(&tmp, "Writing the final ISO"); |
---|
3163 | mr_msg(2, tmp); |
---|
3164 | /* BERLIOS: Doesn't work on allocated chains anymore |
---|
3165 | center_string(tmp, 80); |
---|
3166 | */ |
---|
3167 | #ifndef _XWIN |
---|
3168 | if (!g_text_mode) { |
---|
3169 | newtPushHelpLine(tmp); |
---|
3170 | } |
---|
3171 | #endif |
---|
3172 | mr_free(tmp); |
---|
3173 | res = write_iso_and_go_on(TRUE); |
---|
3174 | #ifndef _XWIN |
---|
3175 | if (!g_text_mode) { |
---|
3176 | newtPopHelpLine(); |
---|
3177 | } |
---|
3178 | #endif |
---|
3179 | mr_msg(2, "Returning from writing final ISO (res=%d)", res); |
---|
3180 | return (res); |
---|
3181 | } |
---|
3182 | |
---|
3183 | |
---|
3184 | /** |
---|
3185 | * Write an ISO image to <tt>[bkpinfo->isodir]/bkpinfo->prefix-[g_current_media_number].iso</tt>. |
---|
3186 | * @param bkpinfo The backup information structure. Fields used: |
---|
3187 | * - @c backup_media_type |
---|
3188 | * - @c prefix |
---|
3189 | * - @c isodir |
---|
3190 | * - @c manual_tray |
---|
3191 | * - @c media_size |
---|
3192 | * - @c nfs_mount |
---|
3193 | * - @c nfs_remote_dir |
---|
3194 | * - @c scratchdir |
---|
3195 | * - @c verify_data |
---|
3196 | * |
---|
3197 | * @param last_cd If TRUE, this is the last CD to write; if FALSE, it's not. |
---|
3198 | * @return The number of errors encountered (0 for success) |
---|
3199 | * @see make_iso_fs |
---|
3200 | */ |
---|
3201 | int write_iso_and_go_on(bool last_cd) |
---|
3202 | { |
---|
3203 | /*@ pointers **************************************************** */ |
---|
3204 | FILE *fout; |
---|
3205 | |
---|
3206 | /*@ buffers ***************************************************** */ |
---|
3207 | char *tmp; |
---|
3208 | char *cdno_fname; |
---|
3209 | char *lastcd_fname; |
---|
3210 | char *isofile; |
---|
3211 | |
---|
3212 | /*@ bool ******************************************************** */ |
---|
3213 | bool that_one_was_ok; |
---|
3214 | bool orig_vfy_flag_val; |
---|
3215 | |
---|
3216 | /*@ int *********************************************************** */ |
---|
3217 | int res = 0; |
---|
3218 | |
---|
3219 | assert(bkpinfo != NULL); |
---|
3220 | orig_vfy_flag_val = bkpinfo->verify_data; |
---|
3221 | if (bkpinfo->media_size <= 0L) { |
---|
3222 | fatal_error("write_iso_and_go_on() - unknown media size"); |
---|
3223 | } |
---|
3224 | |
---|
3225 | mr_msg(1, "OK, time to make %s #%d", |
---|
3226 | bkpinfo->backup_media_string, |
---|
3227 | g_current_media_number); |
---|
3228 | |
---|
3229 | /* label the ISO with its number */ |
---|
3230 | |
---|
3231 | mr_asprintf(&cdno_fname, "%s/archives/THIS-CD-NUMBER", |
---|
3232 | bkpinfo->scratchdir); |
---|
3233 | fout = fopen(cdno_fname, "w"); |
---|
3234 | fprintf(fout, "%d", g_current_media_number); |
---|
3235 | paranoid_fclose(fout); |
---|
3236 | mr_free(cdno_fname); |
---|
3237 | |
---|
3238 | mr_asprintf(&tmp, "cp -f %s/autorun %s/", MONDO_SHARE, |
---|
3239 | bkpinfo->scratchdir); |
---|
3240 | if (run_program_and_log_output(tmp, FALSE)) { |
---|
3241 | mr_msg(2, "Warning - unable to copy autorun to scratchdir"); |
---|
3242 | } |
---|
3243 | mr_free(tmp); |
---|
3244 | |
---|
3245 | /* last CD or not? Label accordingly */ |
---|
3246 | mr_asprintf(&lastcd_fname, "%s/archives/NOT-THE-LAST", |
---|
3247 | bkpinfo->scratchdir); |
---|
3248 | if (last_cd) { |
---|
3249 | unlink(lastcd_fname); |
---|
3250 | mr_msg(2, |
---|
3251 | "OK, you're telling me this is the last CD. Fair enough."); |
---|
3252 | } else { |
---|
3253 | fout = fopen(lastcd_fname, "w"); |
---|
3254 | fprintf(fout, |
---|
3255 | "You're listening to 90.3 WPLN, Nashville Public Radio.\n"); |
---|
3256 | paranoid_fclose(fout); |
---|
3257 | } |
---|
3258 | mr_free(lastcd_fname); |
---|
3259 | |
---|
3260 | if (space_occupied_by_cd(bkpinfo->scratchdir) / 1024 > bkpinfo->media_size) { |
---|
3261 | mr_asprintf(&tmp, |
---|
3262 | "Warning! %s is too big. It occupies %ld KB, which is more than the %ld KB allowed.", |
---|
3263 | media_descriptor_string(bkpinfo->backup_media_type), |
---|
3264 | (long) space_occupied_by_cd(bkpinfo->scratchdir), |
---|
3265 | bkpinfo->media_size); |
---|
3266 | log_to_screen(tmp); |
---|
3267 | mr_free(tmp); |
---|
3268 | } |
---|
3269 | if (bkpinfo->backup_media_type != usb) { |
---|
3270 | mr_asprintf(&isofile, "%s/%s/%s-%d.iso", bkpinfo->isodir, |
---|
3271 | bkpinfo->nfs_remote_dir, bkpinfo->prefix, |
---|
3272 | g_current_media_number); |
---|
3273 | } else { |
---|
3274 | } |
---|
3275 | for (that_one_was_ok = FALSE; !that_one_was_ok;) { |
---|
3276 | if (bkpinfo->backup_media_type != usb) { |
---|
3277 | res = make_iso_fs(isofile); |
---|
3278 | } else { |
---|
3279 | res = make_usb_fs(); |
---|
3280 | } |
---|
3281 | if (g_current_media_number == 1 && !res |
---|
3282 | && (bkpinfo->backup_media_type == cdr |
---|
3283 | || bkpinfo->backup_media_type == cdrw)) { |
---|
3284 | if (find_cdrom_device(tmp, FALSE)) // make sure find_cdrom_device() finds, records CD-R's loc |
---|
3285 | { |
---|
3286 | mr_msg(3, "*Sigh* Mike, I hate your computer."); |
---|
3287 | bkpinfo->manual_tray = TRUE; |
---|
3288 | } // if it can't be found then force pausing |
---|
3289 | else { |
---|
3290 | mr_msg(3, "Great. Found Mike's CD-ROM drive."); |
---|
3291 | } |
---|
3292 | } |
---|
3293 | if (bkpinfo->verify_data && !res) { |
---|
3294 | log_to_screen |
---|
3295 | ("Please reboot from the 1st %s in Compare Mode, as a precaution.", |
---|
3296 | media_descriptor_string(g_backup_media_type)); |
---|
3297 | chdir("/"); |
---|
3298 | iamhere("Before calling verification of image()"); |
---|
3299 | if (bkpinfo->backup_media_type == usb) { |
---|
3300 | res += verify_usb_image(); |
---|
3301 | } else { |
---|
3302 | res += verify_cd_image(); |
---|
3303 | } |
---|
3304 | iamhere("After calling verification of image()"); |
---|
3305 | } |
---|
3306 | if (!res) { |
---|
3307 | that_one_was_ok = TRUE; |
---|
3308 | } else { |
---|
3309 | mr_asprintf(&tmp, "Failed to burn %s #%d. Retry?", |
---|
3310 | bkpinfo->backup_media_string, |
---|
3311 | g_current_media_number); |
---|
3312 | res = ask_me_yes_or_no(tmp); |
---|
3313 | mr_free(tmp); |
---|
3314 | if (!res) { |
---|
3315 | if (ask_me_yes_or_no("Abort the backup?")) { |
---|
3316 | fatal_error("FAILED TO BACKUP"); |
---|
3317 | } else { |
---|
3318 | break; |
---|
3319 | } |
---|
3320 | } else { |
---|
3321 | mr_msg(2, "Retrying, at user's request..."); |
---|
3322 | res = 0; |
---|
3323 | } |
---|
3324 | } |
---|
3325 | } |
---|
3326 | mr_free(isofile); |
---|
3327 | |
---|
3328 | g_current_media_number++; |
---|
3329 | wipe_archives(bkpinfo->scratchdir); |
---|
3330 | mr_asprintf(&tmp, "rm -Rf %s/images/*gz %s/images/*data*img", |
---|
3331 | bkpinfo->scratchdir, bkpinfo->scratchdir); |
---|
3332 | if (system(tmp)) { |
---|
3333 | mr_msg(2, |
---|
3334 | "Error occurred when I tried to delete the redundant IMGs and GZs"); |
---|
3335 | } |
---|
3336 | mr_free(tmp); |
---|
3337 | |
---|
3338 | if (last_cd) { |
---|
3339 | mr_msg(2, "This was your last media."); |
---|
3340 | } else { |
---|
3341 | mr_msg(2, "Continuing to backup your data..."); |
---|
3342 | } |
---|
3343 | |
---|
3344 | bkpinfo->verify_data = orig_vfy_flag_val; |
---|
3345 | return (0); |
---|
3346 | } |
---|
3347 | |
---|
3348 | /* @} - end of LLarchiveGroup */ |
---|
3349 | |
---|
3350 | |
---|
3351 | /** |
---|
3352 | * Verify the user's data. |
---|
3353 | * @param bkpinfo The backup information structure. Fields used: |
---|
3354 | * - @c backup_data |
---|
3355 | * - @c backup_media_type |
---|
3356 | * - @c media_device |
---|
3357 | * - @c verify_data |
---|
3358 | * |
---|
3359 | * @return The number of errors encountered (0 for success) |
---|
3360 | * @ingroup verifyGroup |
---|
3361 | */ |
---|
3362 | int verify_data() |
---|
3363 | { |
---|
3364 | int res = 0, retval = 0, cdno = 0; |
---|
3365 | char *tmp = NULL; |
---|
3366 | long diffs = 0; |
---|
3367 | |
---|
3368 | assert(bkpinfo != NULL); |
---|
3369 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { |
---|
3370 | chdir("/"); |
---|
3371 | mvaddstr_and_log_it(g_currentY, 0, |
---|
3372 | "Verifying archives against live filesystem"); |
---|
3373 | verify_tape_backups(); |
---|
3374 | mvaddstr_and_log_it(g_currentY++, 74, "Done."); |
---|
3375 | } else if (bkpinfo->backup_data) |
---|
3376 | //bkpinfo->backup_media_type == cdrw || bkpinfo->backup_media_type == cdr)) |
---|
3377 | { |
---|
3378 | mr_msg(2, |
---|
3379 | "Not verifying again. Per-CD/ISO verification already carried out."); |
---|
3380 | sprintf(tmp, "cat %s/changed.files > %s/changed.files 2> /dev/null",bkpinfo->tmpdir, MONDO_CACHE); |
---|
3381 | paranoid_system(tmp); |
---|
3382 | } else { |
---|
3383 | g_current_media_number = cdno; |
---|
3384 | chdir("/"); |
---|
3385 | for (cdno = 1; cdno < 99 && bkpinfo->verify_data; cdno++) { |
---|
3386 | if (cdno != g_current_media_number) { |
---|
3387 | mr_msg(2, |
---|
3388 | "Warning - had to change g_current_media_number from %d to %d", |
---|
3389 | g_current_media_number, cdno); |
---|
3390 | g_current_media_number = cdno; |
---|
3391 | } |
---|
3392 | if (bkpinfo->backup_media_type != iso) { |
---|
3393 | insist_on_this_cd_number(cdno); |
---|
3394 | } |
---|
3395 | res = verify_cd_image(); // sets verify_data to FALSE if it's time to stop verifying |
---|
3396 | retval += res; |
---|
3397 | if (res) { |
---|
3398 | mr_asprintf(&tmp, |
---|
3399 | "Warnings/errors were reported while checking %s #%d", |
---|
3400 | media_descriptor_string(bkpinfo->backup_media_type), |
---|
3401 | g_current_media_number); |
---|
3402 | log_to_screen(tmp); |
---|
3403 | mr_free(tmp); |
---|
3404 | |
---|
3405 | } |
---|
3406 | } |
---|
3407 | mr_asprintf(&tmp, |
---|
3408 | "grep 'afio: ' %s | sed 's/afio: //' | grep -vE '^/dev/.*$' >> %s/changed.files", |
---|
3409 | MONDO_LOGFILE, MONDO_CACHE); |
---|
3410 | system(tmp); |
---|
3411 | mr_free(tmp); |
---|
3412 | |
---|
3413 | mr_asprintf(&tmp, |
---|
3414 | "grep 'star: ' %s | sed 's/star: //' | grep -vE '^/dev/.*$' >> %s/changed.files", |
---|
3415 | MONDO_LOGFILE, MONDO_CACHE); |
---|
3416 | system(tmp); |
---|
3417 | mr_free(tmp); |
---|
3418 | |
---|
3419 | run_program_and_log_output("umount " MNT_CDROM, FALSE); |
---|
3420 | eject_device(bkpinfo->media_device); |
---|
3421 | } |
---|
3422 | sprintf(tmp, "%s/changed.files", MONDO_CACHE); |
---|
3423 | diffs = count_lines_in_file(tmp); |
---|
3424 | |
---|
3425 | if (diffs > 0) { |
---|
3426 | if (retval == 0) { |
---|
3427 | retval = (int) (-diffs); |
---|
3428 | } |
---|
3429 | } |
---|
3430 | return (retval); |
---|
3431 | } |
---|
3432 | |
---|
3433 | |
---|
3434 | void setenv_mondo_var(void) { |
---|
3435 | |
---|
3436 | char *tmp = NULL; |
---|
3437 | char *p = NULL; |
---|
3438 | char *path_min = "/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"; |
---|
3439 | |
---|
3440 | mr_setenv("MONDO_SHARE",MONDO_SHARE); |
---|
3441 | mr_setenv("MONDORESTORECFG",MONDORESTORECFG); |
---|
3442 | mr_setenv("MONDO_CACHE",MONDO_CACHE); |
---|
3443 | /* Add the ARCH environment variable for ia64 purposes */ |
---|
3444 | mr_setenv("ARCH", get_architecture()); |
---|
3445 | |
---|
3446 | |
---|
3447 | if ((p = getenv("PATH")) == NULL) { |
---|
3448 | mr_asprintf(&tmp, path_min); |
---|
3449 | } else { |
---|
3450 | mr_asprintf(&tmp, "%s:%s",p, path_min); |
---|
3451 | } |
---|
3452 | mr_setenv("PATH",tmp); |
---|
3453 | mr_free(tmp); |
---|
3454 | } |
---|