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