source: MondoRescue/branches/stable/mondo/src/common/libmondo-archive.c@ 1638

Last change on this file since 1638 was 1638, checked in by Bruno Cornec, 17 years ago

Continue to use configuration file data (may not compile)

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