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

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

More conf file items handled

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