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