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

Last change on this file since 1663 was 1663, checked in by Bruno Cornec, 17 years ago
  • Fix bug #197 (based on an initial patch of Scott Cummings)
  • Fix a bug where df was using locale to print messages and wasn't filtered correctly
  • mkdtemp checked in configure
  • reset_bkpinfo called as early as possible by both main program.
  • It creates a tmpdir cleanly with mkdtemp in setup_tmpdir subfunction, which takes in account TMPIR and TMP env var. Remains to see what tmpfs does and tests
  • configure.in should also be filtered.
  • Remove g_bkpinfo_DONTUSETHIS
  • remove bkpinfo also from header files
  • Render bkpinfo global (potential issue on thread, but should not be a problem as that structure is indeed static during archive)
  • Apply patch from Andree Leidenfrost, modified a bit to use bkpinfo->tmpdir instead of /tmp or MINDI_CACHE when appropriate. Fix security issues in mondo. Thanks al ot Andree for catching all those issues.
  • /tmp => /var/log for mondorestore.log in mindi
  • Update linux terminfo to fix a color issue (Andree Leidenfrost)
  • Removes useless log file (Andree Leidenfrost)
  • replace vi with find_my_editor during restore (Andree Leidenfrost)
  • sync in bg in mindi (VMWare issue to look at)
  • mindi/mindi-busybox have a different version than mondo for pb
  • PB-SUF also added to spec file
  • Fix a bug for pb build (omission of PB-SUF declaration)

(merge -r1631:1662 $SVN_M/branches/2.2.5)

  • Property svn:keywords set to Id
File size: 93.6 KB
Line 
1/* libmondo-archive.c
2 $Id: libmondo-archive.c 1663 2007-09-27 10:21:18Z 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 1663 2007-09-27 10:21:18Z 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/* Reference to global bkpinfo */
82extern struct s_bkpinfo *bkpinfo;
83
84
85
86/**
87 * @addtogroup globalGroup
88 * @{
89 */
90/**
91 * The current backup media type in use.
92 */
93t_bkptype g_backup_media_type = none;
94char *g_backup_media_string = NULL;
95
96/**
97 * Incremented by each archival thread when it starts up. After that,
98 * this is the number of threads running.
99 */
100int g_current_thread_no = 0;
101
102/* @} - end of globalGroup */
103
104extern int g_noof_rows;
105
106/* Semaphore-related code */
107
108static int set_semvalue(void);
109static void del_semvalue(void);
110static int semaphore_p(void);
111static int semaphore_v(void);
112
113static int g_sem_id;
114static int g_sem_key;
115
116
117
118
119/**
120 * Initialize the semaphore.
121 * @see del_semvalue
122 * @see semaphore_p
123 * @see semaphore_v
124 * @return 1 for success, 0 for failure.
125 */
126static int set_semvalue(void) // initializes semaphore
127{
128 union semun sem_union;
129 sem_union.val = 1;
130 if (semctl(g_sem_id, 0, SETVAL, sem_union) == -1) {
131 return (0);
132 }
133 return (1);
134}
135
136/**
137 * Frees (deletes) the semaphore. Failure is indicated by a log
138 * message.
139 * @see set_semvalue
140 */
141static void del_semvalue(void) // deletes semaphore
142{
143 union semun sem_union;
144
145 if (semctl(g_sem_id, 0, IPC_RMID, sem_union) == -1) {
146 mr_msg(3, "Failed to delete semaphore");
147 }
148}
149
150/**
151 * Acquire (increment) the semaphore (change status to P).
152 * @return 1 for success, 0 for failure.
153 * @see semaphore_v
154 */
155static int semaphore_p(void) // changes status to 'P' (waiting)
156{
157 struct sembuf sem_b;
158
159 sem_b.sem_num = 0;
160 sem_b.sem_op = -1; // P()
161 sem_b.sem_flg = SEM_UNDO;
162 if (semop(g_sem_id, &sem_b, 1) == -1) {
163 mr_msg(3, "semaphore_p failed");
164 return (0);
165 }
166 return (1);
167}
168
169/**
170 * Free (decrement) the semaphore (change status to V).
171 * @return 1 for success, 0 for failure.
172 */
173static int semaphore_v(void) // changes status to 'V' (free)
174{
175 struct sembuf sem_b;
176
177 sem_b.sem_num = 0;
178 sem_b.sem_op = 1; // V()
179 sem_b.sem_flg = SEM_UNDO;
180 if (semop(g_sem_id, &sem_b, 1) == -1) {
181 mr_msg(3, "semaphore_v failed");
182 return (0);
183 }
184 return (1);
185}
186
187
188//------------------------------------------------------
189
190
191/**
192 * Size in megabytes of the buffer afforded to the executable "buffer".
193 * This figure is used when we calculate how much data we have probably 'lost'
194 * when writing off the end of tape N, so that we can then figure out how much
195 * data we must recreate & write to the start of tape N+1.
196 */
197extern int g_tape_buffer_size_MB;
198
199
200
201
202int
203archive_this_fileset_with_star(char *filelist, char *fname, int setno)
204{
205 int retval = 0;
206 unsigned int res = 0;
207 int tries = 0;
208 char *command = NULL;
209 char *tmp = NULL;
210 char *p =NULL;
211 char *tmp1 = NULL;
212
213 malloc_string(tmp1);
214
215 if (!does_file_exist(filelist)) {
216 mr_asprintf(&tmp,
217 "(archive_this_fileset) - filelist %s does not exist",
218 filelist);
219 log_to_screen(tmp);
220 mr_free(tmp);
221 return (1);
222 }
223
224 mr_asprintf(&tmp, "echo hi > %s 2> /dev/null", fname);
225 if (system(tmp)) {
226 fatal_error("Unable to write tarball to scratchdir");
227 }
228 mr_free(tmp);
229
230 mr_asprintf(&command, "star H=star list=%s -c " STAR_ACL_SZ " file=%s",
231 filelist, fname);
232 if (bkpinfo->use_lzo) {
233 fatal_error("Can't use lzop");
234 }
235 if (bkpinfo->compression_level > 0) {
236 mr_asprintf(&tmp, "%s -bz", command);
237 mr_free(command);
238 command = tmp;
239 }
240 mr_asprintf(&tmp, "%s 2>> %s", command, MONDO_LOGFILE);
241 mr_free(command);
242 command = tmp;
243 mr_msg(4, "command = '%s'", command);
244
245 for (res = 99, tries = 0; tries < 3 && res != 0; tries++) {
246 mr_msg(5, "command='%s'", command);
247 res = system(command);
248 strcpy(tmp1, last_line_of_file(MONDO_LOGFILE));
249 mr_msg(1, "res=%d; tmp='%s'", res, tmp);
250 if (bkpinfo->use_star && (res == 254 || res == 65024)
251 && strstr(tmp, "star: Processed all possible files")
252 && tries > 0) {
253 mr_msg(1, "Star returned nonfatal error");
254 res = 0;
255 }
256 if (res) {
257 log_OS_error(command);
258 p = strstr(command, "-acl ");
259 if (p) {
260 p[0] = p[1] = p[2] = p[3] = ' ';
261 mr_msg(1, "new command = '%s'", command);
262 } else {
263 mr_msg(3,
264 "Attempt #%d failed. Pausing 3 seconds and retrying...",
265 tries + 1);
266 sleep(3);
267 }
268 }
269 }
270 mr_free(command);
271
272 retval += res;
273 if (retval) {
274 mr_msg(3, "Failed to write set %d", setno);
275 } else if (tries > 1) {
276 mr_msg(3, "Succeeded in writing set %d, on try #%d", setno,
277 tries);
278 }
279
280 return (retval);
281}
282
283
284/**
285 * Call @c afio to archive the filelist @c filelist to the file @c fname.
286 *
287 * @param bkpinfo The backup information structure. Fields used:
288 * - @c compression_level
289 * - @c scratchdir (only verifies existence)
290 * - @c tmpdir (only verifies existence)
291 * - @c zip_exe
292 * - @c zip_suffix
293 * @param filelist The path to a file containing a list of files to be archived
294 * in this fileset.
295 * @param fname The output file to archive to.
296 * @param setno This fileset number.
297 * @return The number of errors encountered (0 for success).
298 * @ingroup LLarchiveGroup
299 */
300int
301archive_this_fileset(char *filelist, char *fname, int setno)
302{
303
304 /*@ int ************************************************************ */
305 int retval = 0;
306 int res = 0;
307 int i = 0;
308 int tries = 0;
309 static int free_ramdisk_space = 9999;
310
311 /*@ buffers ******************************************************** */
312 char *command = NULL;
313 char *zipparams = NULL;
314 char *tmp = NULL;
315 char *tmp1 = NULL;
316
317 assert(bkpinfo != NULL);
318 assert_string_is_neither_NULL_nor_zerolength(filelist);
319 assert_string_is_neither_NULL_nor_zerolength(fname);
320
321 if (bkpinfo->compression_level > 0 && bkpinfo->use_star) {
322 return (archive_this_fileset_with_star(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()
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();
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())) { /* generate scratchdir/filelist.full */
455 fatal_error("Failed to generate filelist catalog");
456 }
457 if (call_filelist_chopper()) {
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(); // 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())) {
489 fatal_error("Failed to generate boot+data disks");
490 }
491 retval += do_that_initial_phase(); // 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(); // backup regular files
496 retval += make_those_slices_phase(); // backup BIG files
497 retval += do_that_final_phase(); // 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()
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_bis;
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_bis = (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 =
1091 archive_this_fileset(archiving_filelist_fname,
1092 archiving_afioball_fname,
1093 archiving_set_no);
1094 retval += res;
1095
1096 if (res) {
1097 mr_asprintf(&tmp,
1098 "Errors occurred while archiving set %ld. Please review logs.",
1099 archiving_set_no);
1100 log_to_screen(tmp);
1101 mr_free(tmp);
1102 }
1103 if (!semaphore_p()) {
1104 fatal_error("Cannot get semaphore P");
1105 }
1106
1107 set_bit_N_of_array(p_list_of_fileset_flags, archiving_set_no, 5);
1108
1109 if (*p_last_set_archived < archiving_set_no) {
1110 *p_last_set_archived = archiving_set_no;
1111 } // finished archiving this one
1112
1113 if (!semaphore_v()) {
1114 fatal_error("Cannot get semaphore V");
1115 }
1116 mr_msg(4, "[%d:%d] - archived %d OK", getpid(),
1117 this_thread_no, archiving_set_no);
1118 archiving_set_no++;
1119 }
1120 if (!semaphore_p()) {
1121 fatal_error("Cannot get semaphore P");
1122 }
1123 (*p_archival_threads_running)--;
1124 if (!semaphore_v()) {
1125 fatal_error("Cannot get semaphore V");
1126 }
1127 mr_msg(3, "[%d:%d] - exiting", getpid(),
1128 this_thread_no);
1129 mr_free(archiving_filelist_fname);
1130 mr_free(archiving_afioball_fname);
1131 pthread_exit(NULL);
1132}
1133
1134
1135/**
1136 * Finalize the backup.
1137 * For streaming backups, this writes the closing block
1138 * to the stream. For CD-based backups, this creates
1139 * the final ISO image.
1140 * @param bkpinfo The backup information structure, used only
1141 * for the @c backup_media_type.
1142 * @ingroup MLarchiveGroup
1143 */
1144int do_that_final_phase()
1145{
1146
1147 /*@ int ************************************** */
1148 int res = 0;
1149 int retval = 0;
1150
1151 /*@ buffers ********************************** */
1152
1153 assert(bkpinfo != NULL);
1154 mvaddstr_and_log_it(g_currentY, 0,
1155 "Writing any remaining data to media ");
1156
1157 mr_msg(1, "Closing tape/CD ... ");
1158 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
1159 /* write tape/cdstream */
1160 closeout_tape();
1161 } else {
1162 /* write final ISO/USB */
1163 res = write_final_iso_if_necessary();
1164 retval += res;
1165 if (res) {
1166 mr_msg(1, "write_final_iso_if_necessary returned an error");
1167 }
1168 }
1169 mr_msg(2, "Fork is exiting ... ");
1170
1171 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1172
1173 /* final stuff */
1174 if (retval) {
1175 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
1176 } else {
1177 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1178 }
1179
1180 return (retval);
1181}
1182
1183
1184/**
1185 * Initialize the backup.
1186 * Does the following:
1187 * - Sets up the serial number.
1188 * - For streaming backups, opens the tape stream and writes the data disks
1189 * and backup headers.
1190 * - For CD-based backups, wipes the ISOs in the target directory.
1191 *
1192 * @param bkpinfo The backup information structure. Fields used:
1193 * - @c backup_media_type
1194 * - @c writer_speed
1195 * - @c prefix
1196 * - @c isodir
1197 * - @c media_device
1198 * - @c scratchdir
1199 * - @c tmpdir
1200 * @return The number of errors encountered (0 for success).
1201 * @ingroup MLarchiveGroup
1202 */
1203int do_that_initial_phase()
1204{
1205 /*@ int *************************************** */
1206 int retval = 0;
1207
1208 /*@ buffers *********************************** */
1209 char *command, *tmp_file, *data_disks_file;
1210
1211 assert(bkpinfo != NULL);
1212 malloc_string(command);
1213
1214 mr_asprintf(&data_disks_file, "%s/all.tar.gz", bkpinfo->tmpdir);
1215
1216 snprintf(g_serial_string, MAX_STR_LEN - 1,
1217 call_program_and_get_last_line_of_output("dd \
1218if=/dev/urandom bs=16 count=1 2> /dev/null | \
1219hexdump | tr -s ' ' '0' | head -n1"));
1220 mr_strip_spaces(g_serial_string);
1221 strcat(g_serial_string, "...word.");
1222 mr_msg(2, "g_serial_string = '%s'", g_serial_string);
1223 assert(strlen(g_serial_string) < MAX_STR_LEN);
1224
1225 mr_asprintf(&tmp_file, "%s/archives/SERIAL-STRING", bkpinfo->scratchdir);
1226 if (write_one_liner_data_file(tmp_file, g_serial_string)) {
1227 mr_msg(1, "%ld: Failed to write serial string", __LINE__);
1228 }
1229 mr_free(tmp_file);
1230
1231 mvaddstr_and_log_it(g_currentY, 0, "Preparing to archive your data");
1232 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
1233 if (bkpinfo->backup_media_type == cdstream) {
1234 openout_cdstream(bkpinfo->media_device, bkpinfo->writer_speed);
1235 } else {
1236 openout_tape(bkpinfo->media_device, bkpinfo->internal_tape_block_size); /* sets g_tape_stream */
1237 }
1238 if (!g_tape_stream) {
1239 fatal_error("Cannot open backup (streaming) device");
1240 }
1241 mr_msg(1, "Backup (stream) opened OK");
1242 write_data_disks_to_stream(data_disks_file);
1243 } else {
1244 mr_msg(1, "Backing up to CD's");
1245 }
1246 mr_free(data_disks_file);
1247
1248 mr_asprintf(&command, "rm -f %s/%s/%s-[1-9]*.iso", bkpinfo->isodir,
1249 bkpinfo->nfs_remote_dir, bkpinfo->prefix);
1250 paranoid_system(command);
1251 mr_free(command);
1252
1253 wipe_archives(bkpinfo->scratchdir);
1254 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1255 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
1256 write_header_block_to_stream((off_t)0, "start-of-tape",
1257 BLK_START_OF_TAPE);
1258 write_header_block_to_stream((off_t)0, "start-of-backup",
1259 BLK_START_OF_BACKUP);
1260 }
1261 return (retval);
1262}
1263
1264
1265/**
1266 * Get the <tt>N</tt>th bit of @c array.
1267 * @param array The bit-array (as a @c char pointer).
1268 * @param N The number of the bit you want.
1269 * @return TRUE (bit is set) or FALSE (bit is not set).
1270 * @see set_bit_N_of_array
1271 * @ingroup utilityGroup
1272 */
1273bool get_bit_N_of_array(char *array, int N)
1274{
1275 int element_number;
1276 int bit_number;
1277 int mask;
1278
1279 element_number = N / 8;
1280 bit_number = N % 8;
1281 mask = 1 << bit_number;
1282 if (array[element_number] & mask) {
1283 return (TRUE);
1284 } else {
1285 return (FALSE);
1286 }
1287}
1288
1289
1290/**
1291 * @addtogroup LLarchiveGroup
1292 * @{
1293 */
1294/**
1295 * Start up threads to archive your files.
1296 *
1297 * This function starts @c ARCH_THREADS threads,
1298 * each starting execution in @c create_afio_files_in_background().
1299 * Each thread will archive individual filesets, based on the
1300 * pointers passed to it and continually updated, until all files
1301 * have been backed up. This function coordinates the threads
1302 * and copies their output to the @c scratchdir.
1303 *
1304 * @param bkpinfo The backup information structure. Fields used:
1305 * - @c backup_media_type
1306 * - @c scratchdir
1307 * - @c tmpdir
1308 * - @c zip_suffix
1309 *
1310 * @return The number of errors encountered (0 for success)
1311 */
1312int make_afioballs_and_images()
1313{
1314
1315 /*@ int ************************************************** */
1316 int retval = 0;
1317 long int storing_set_no = 0;
1318 int res = 0;
1319 bool done_storing = FALSE;
1320 char *result_str;
1321 char *transfer_block;
1322 void *vp;
1323 void **pvp;
1324
1325 /*@ buffers ********************************************** */
1326 char *storing_filelist_fname;
1327 char *storing_afioball_fname;
1328 char *tmp = NULL;
1329 char *media_usage_comment;
1330 pthread_t archival_thread[ARCH_THREADS];
1331 char *p_list_of_fileset_flags;
1332 int *p_archival_threads_running;
1333 int *p_last_set_archived;
1334 int *p_next_set_to_archive;
1335 int noof_threads;
1336 int i;
1337 char *curr_xattr_list_fname = NULL;
1338 char *curr_acl_list_fname;
1339 int misc_counter_that_is_not_important = 0;
1340
1341 mr_msg(8, "here");
1342 assert(bkpinfo != NULL);
1343 /* BERLIOS: To be removed */
1344 malloc_string(result_str);
1345 malloc_string(curr_xattr_list_fname);
1346 malloc_string(curr_acl_list_fname);
1347 malloc_string(storing_filelist_fname);
1348 malloc_string(media_usage_comment);
1349 malloc_string(storing_afioball_fname);
1350 transfer_block =
1351 mr_malloc(sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64);
1352 memset((void *) transfer_block, 0,
1353 sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64);
1354 p_last_set_archived = (int *) transfer_block;
1355 p_archival_threads_running = (int *) (transfer_block + 4);
1356 p_next_set_to_archive = (int *) (transfer_block + 8);
1357 p_list_of_fileset_flags = (char *) (transfer_block + 12);
1358 memcpy((void *) (transfer_block + BKPINFO_LOC_OFFSET),
1359 (void *) bkpinfo, sizeof(struct s_bkpinfo));
1360 pvp = &vp;
1361 vp = (void *) result_str;
1362 *p_archival_threads_running = 0;
1363 *p_last_set_archived = -1;
1364 *p_next_set_to_archive = 0;
1365 log_to_screen("Archiving regular files");
1366 open_progress_form(_("Backing up filesystem"),
1367 _("I am backing up your live filesystem now."),
1368 _("Please wait. This may take a couple of hours."),
1369 _("Working..."),
1370 get_last_filelist_number() + 1);
1371
1372 srand((unsigned int) getpid());
1373 g_sem_key = 1234 + random() % 30000;
1374 if ((g_sem_id =
1375 semget((key_t) g_sem_key, 1,
1376 IPC_CREAT | S_IREAD | S_IWRITE)) == -1) {
1377 fatal_error("MABAI - unable to semget");
1378 }
1379 if (!set_semvalue()) {
1380 fatal_error("Unable to init semaphore");
1381 } // initialize semaphore
1382 for (noof_threads = 0; noof_threads < ARCH_THREADS; noof_threads++) {
1383 mr_msg(8, "Creating thread #%d", noof_threads);
1384 (*p_archival_threads_running)++;
1385 if ((res =
1386 pthread_create(&archival_thread[noof_threads], NULL,
1387 create_afio_files_in_background,
1388 (void *) transfer_block))) {
1389 fatal_error("Unable to create an archival thread");
1390 }
1391 }
1392
1393 mr_msg(8, "About to enter while() loop");
1394 while (!done_storing) {
1395 if (g_exiting) {
1396 fatal_error("Execution run aborted (main loop)");
1397 }
1398 if (*p_archival_threads_running == 0
1399 && *p_last_set_archived == storing_set_no - 1) {
1400 mr_msg(2,
1401 "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... :-)",
1402 *p_last_set_archived, storing_set_no);
1403 done_storing = TRUE;
1404 } else
1405 if (!get_bit_N_of_array
1406 (p_list_of_fileset_flags, storing_set_no)) {
1407 misc_counter_that_is_not_important =
1408 (misc_counter_that_is_not_important + 1) % 5;
1409 if (!misc_counter_that_is_not_important) {
1410 update_progress_form(media_usage_comment);
1411 }
1412 sleep(1);
1413 } else {
1414 // store set N
1415 sprintf(storing_filelist_fname, FILELIST_FNAME_RAW_SZ,
1416 bkpinfo->tmpdir, storing_set_no);
1417 sprintf(storing_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
1418 bkpinfo->tmpdir, storing_set_no, bkpinfo->zip_suffix);
1419 if (g_getfattr) {
1420 sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
1421 bkpinfo->tmpdir, storing_set_no);
1422 }
1423 if (g_getfacl) {
1424 sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
1425 bkpinfo->tmpdir, storing_set_no);
1426 }
1427
1428 mr_msg(2, "Storing set %d", storing_set_no);
1429 while (!does_file_exist(storing_filelist_fname)
1430 || !does_file_exist(storing_afioball_fname)) {
1431 mr_msg(2,
1432 "Warning - either %s or %s doesn't exist yet. I'll pause 5 secs.",
1433 storing_filelist_fname, storing_afioball_fname);
1434 sleep(5);
1435 }
1436 strcpy(media_usage_comment, percent_media_full_comment());
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(curr_xattr_list_fname,
1445 curr_acl_list_fname);
1446 // archives themselves
1447 res +=
1448 move_files_to_stream(storing_afioball_fname,
1449 NULL);
1450 } else {
1451 if (g_getfacl) {
1452 if (g_getfattr) {
1453 res = move_files_to_cd(storing_filelist_fname,
1454 curr_xattr_list_fname,
1455 curr_acl_list_fname,
1456 storing_afioball_fname, NULL);
1457 } else {
1458 res = move_files_to_cd(storing_filelist_fname,
1459 curr_acl_list_fname,
1460 storing_afioball_fname, NULL);
1461 }
1462 } else {
1463 if (g_getfattr) {
1464 res = move_files_to_cd(storing_filelist_fname,
1465 curr_xattr_list_fname,
1466 storing_afioball_fname, NULL);
1467 } else {
1468 res = move_files_to_cd(storing_filelist_fname,
1469 storing_afioball_fname, NULL);
1470 }
1471 }
1472 }
1473 retval += res;
1474 g_current_progress++;
1475 update_progress_form(media_usage_comment);
1476 if (res) {
1477 mr_asprintf(&tmp,
1478 "Failed to add archive %ld's files to CD dir\n",
1479 storing_set_no);
1480 log_to_screen(tmp);
1481 mr_free(tmp);
1482 fatal_error
1483 ("Is your hard disk full? If not, please send the author the logfile.");
1484 }
1485 storing_set_no++;
1486 // sleep(2);
1487 }
1488 }
1489 close_progress_form();
1490
1491 mr_msg(2, "Joining background threads to foreground thread");
1492 for (i = 0; i < noof_threads; i++) {
1493 pthread_join(archival_thread[i], pvp);
1494 mr_msg(3, "Thread %d of %d: closed OK", i + 1, noof_threads);
1495 }
1496 del_semvalue();
1497 mr_msg(2, "Done.");
1498 if (retval) {
1499 mr_asprintf(&tmp,
1500 "Your regular files have been archived (with errors).");
1501 } else {
1502 mr_asprintf(&tmp,
1503 "Your regular files have been archived successfully");
1504 }
1505 log_to_screen(tmp);
1506 mr_free(tmp);
1507 mr_free(transfer_block);
1508 mr_free(result_str);
1509 mr_free(storing_filelist_fname);
1510 mr_free(media_usage_comment);
1511 mr_free(storing_afioball_fname);
1512 mr_free(curr_xattr_list_fname);
1513 mr_free(curr_acl_list_fname);
1514 return (retval);
1515}
1516
1517
1518void pause_for_N_seconds(int how_long, char *msg)
1519{
1520 int i;
1521 open_evalcall_form(msg);
1522 for (i = 0; i < how_long; i++) {
1523 update_evalcall_form((int) ((100.0 / (float) (how_long) * i)));
1524 sleep(1);
1525 }
1526 close_evalcall_form();
1527}
1528
1529
1530/**
1531 * Create an ISO image in @c destfile, from files in @c bkpinfo->scratchdir.
1532 *
1533 * @param bkpinfo The backup information structure. Fields used:
1534 * - @c backup_media_type
1535 * - @c call_after_iso
1536 * - @c call_before_iso
1537 * - @c call_burn_iso
1538 * - @c call_make_iso
1539 * - @c manual_tray
1540 * - @c nonbootable_backup
1541 * - @c scratchdir
1542 *
1543 * @param destfile Where to put the generated ISO image.
1544 * @return The number of errors encountered (0 for success)
1545 */
1546int make_iso_fs(char *destfile)
1547{
1548 /*@ int ********************************************** */
1549 int retval = 0;
1550 int res;
1551
1552 /*@ buffers ****************************************** */
1553 char *tmp = NULL;
1554 char *old_pwd;
1555 char *message_to_screen = NULL;
1556 char *sz_blank_disk = NULL;
1557 char *tmp2 = NULL;
1558 char *tmp3 = NULL;
1559
1560 malloc_string(old_pwd);
1561 assert(bkpinfo != NULL);
1562 assert_string_is_neither_NULL_nor_zerolength(destfile);
1563
1564 mr_asprintf(&tmp, "%s/isolinux.bin", bkpinfo->scratchdir);
1565 mr_asprintf(&tmp2, "%s/isolinux.bin", bkpinfo->tmpdir);
1566 if (does_file_exist(tmp)) {
1567 mr_asprintf(&tmp3, "cp -f %s %s", tmp, tmp2);
1568 paranoid_system(tmp3);
1569 mr_free(tmp3);
1570 }
1571 if (!does_file_exist(tmp) && does_file_exist(tmp2)) {
1572 mr_asprintf(&tmp3, "cp -f %s %s", tmp2, tmp);
1573 paranoid_system(tmp3);
1574 mr_free(tmp3);
1575 }
1576 mr_free(tmp2);
1577 mr_free(tmp);
1578
1579 if (bkpinfo->backup_media_type != iso && bkpinfo->manual_tray) {
1580 popup_and_OK(_("Please insert new media and press Enter."));
1581 }
1582
1583 mr_msg(2, "make_iso_fs --- scratchdir=%s --- destfile=%s",
1584 bkpinfo->scratchdir, destfile);
1585 /* BERLIOS: Do not ignore getcwd result */
1586 (void) getcwd(old_pwd, MAX_STR_LEN - 1);
1587 chmod(bkpinfo->scratchdir,0755);
1588 chdir(bkpinfo->scratchdir);
1589
1590 if (bkpinfo->call_before_iso[0] != '\0') {
1591 mr_asprintf(&message_to_screen, "Running pre-ISO call for CD#%d",
1592 g_current_media_number);
1593 res = eval_call_to_make_ISO(bkpinfo->call_before_iso,
1594 destfile, g_current_media_number,
1595 MONDO_LOGFILE, message_to_screen);
1596 if (res) {
1597 log_to_screen("%s...failed", message_to_screen);
1598 } else {
1599 log_to_screen("%s...OK", message_to_screen);
1600 }
1601 mr_free(message_to_screen);
1602 retval += res;
1603 }
1604
1605 if (bkpinfo->call_make_iso[0] != '\0') {
1606 mr_msg(2, "bkpinfo->call_make_iso = %s", bkpinfo->call_make_iso);
1607 mr_asprintf(&message_to_screen, "Making an ISO (%s #%d)",
1608 bkpinfo->backup_media_string,
1609 g_current_media_number);
1610
1611 /* if g_current_media_number >= 2 then pause & ask */
1612 if (bkpinfo->backup_media_type != iso) {
1613 pause_and_ask_for_cdr(2);
1614 }
1615 if (retval) {
1616 log_to_screen
1617 ("Serious error(s) occurred already. I shan't try to write to media.");
1618 } else {
1619 res = eval_call_to_make_ISO(bkpinfo->call_make_iso,
1620 destfile, g_current_media_number,
1621 MONDO_LOGFILE, message_to_screen);
1622 if (res) {
1623 log_to_screen("%s...failed to write", message_to_screen);
1624 } else {
1625 log_to_screen("%s...OK", message_to_screen);
1626 mr_asprintf(&tmp, "tail -n10 %s | grep -F ':-('", MONDO_LOGFILE);
1627 if (!run_program_and_log_output(tmp, 1)) {
1628 log_to_screen
1629 ("Despite nonfatal errors, growisofs confirms the write was successful.");
1630 }
1631 mr_free(tmp);
1632 }
1633 retval += res;
1634#ifdef DVDRWFORMAT
1635 mr_asprintf(&tmp,
1636 "tail -n8 %s | grep 'blank=full.*dvd-compat.*DAO'",
1637 MONDO_LOGFILE);
1638 if (g_backup_media_type == dvd
1639 && (res || !run_program_and_log_output(tmp, 1))) {
1640 log_to_screen
1641 ("Failed to write to disk. I shall blank it and then try again.");
1642 sleep(5);
1643 sync();
1644 pause_for_N_seconds(5, "Letting DVD drive settle");
1645
1646 // dvd+rw-format --- OPTION 2
1647 if (!bkpinfo->please_dont_eject) {
1648 log_to_screen("Ejecting media to clear drive status.");
1649 eject_device(bkpinfo->media_device);
1650 inject_device(bkpinfo->media_device);
1651 }
1652 pause_for_N_seconds(5, "Letting DVD drive settle");
1653 mr_asprintf(&sz_blank_disk, "dvd+rw-format -force %s",
1654 bkpinfo->media_device);
1655 mr_msg(3, "sz_blank_disk = '%s'", sz_blank_disk);
1656 res = run_external_binary_with_percentage_indicator_NEW
1657 ("Blanking DVD disk", sz_blank_disk);
1658 if (res) {
1659 log_to_screen
1660 ("Warning - format failed. (Was it a DVD-R?) Sleeping for 5 seconds to take a breath...");
1661 pause_for_N_seconds(5,
1662 "Letting DVD drive settle... and trying again.");
1663 res = run_external_binary_with_percentage_indicator_NEW
1664 ("Blanking DVD disk", sz_blank_disk);
1665 if (res) {
1666 log_to_screen("Format failed a second time.");
1667 }
1668 } else {
1669 log_to_screen
1670 ("Format succeeded. Sleeping for 5 seconds to take a breath...");
1671 }
1672 mr_free(sz_blank_disk);
1673 pause_for_N_seconds(5, "Letting DVD drive settle");
1674 if (!bkpinfo->please_dont_eject) {
1675 log_to_screen("Ejecting media to clear drive status.");
1676 eject_device(bkpinfo->media_device);
1677 inject_device(bkpinfo->media_device);
1678 }
1679 pause_for_N_seconds(5, "Letting DVD drive settle");
1680 res =
1681 eval_call_to_make_ISO(bkpinfo->call_make_iso,
1682 destfile,
1683 g_current_media_number,
1684 MONDO_LOGFILE,
1685 message_to_screen);
1686 retval += res;
1687 if (!bkpinfo->please_dont_eject) {
1688 log_to_screen("Ejecting media.");
1689 eject_device(bkpinfo->media_device);
1690 }
1691 if (res) {
1692 log_to_screen("Dagnabbit. It still failed.");
1693 } else {
1694 log_to_screen
1695 ("OK, this time I successfully backed up to DVD.");
1696 }
1697 }
1698 mr_free(tmp);
1699#endif
1700 if (g_backup_media_type == dvd && !bkpinfo->please_dont_eject) {
1701 eject_device(bkpinfo->media_device);
1702 }
1703 }
1704 mr_free(message_to_screen);
1705 } else {
1706 fatal_error("call_make_iso undefined. Not normal in this case");
1707 }
1708
1709 if (bkpinfo->backup_media_type == cdr
1710 || bkpinfo->backup_media_type == cdrw) {
1711 if (is_this_device_mounted(bkpinfo->media_device)) {
1712 mr_msg(2,
1713 "Warning - %s mounted. I'm unmounting it before I burn to it.",
1714 bkpinfo->media_device);
1715 mr_asprintf(&tmp, "umount %s", bkpinfo->media_device);
1716 run_program_and_log_output(tmp, FALSE);
1717 mr_free(tmp);
1718 }
1719 }
1720
1721 if (bkpinfo->call_after_iso != NULL) {
1722 mr_asprintf(&message_to_screen, "Running post-ISO call (%s #%d)",
1723 bkpinfo->backup_media_string,
1724 g_current_media_number);
1725 res = eval_call_to_make_ISO(bkpinfo->call_after_iso,
1726 destfile, g_current_media_number,
1727 MONDO_LOGFILE, message_to_screen);
1728 if (res) {
1729 log_to_screen("%s...failed", message_to_screen);
1730 } else {
1731 log_to_screen("%s...OK", message_to_screen);
1732 }
1733 mr_free(message_to_screen);
1734 retval += res;
1735 }
1736
1737 chdir(old_pwd);
1738 if (retval) {
1739 mr_msg(1, "WARNING - make_iso_fs returned an error");
1740 }
1741 mr_free(old_pwd);
1742 return (retval);
1743}
1744
1745
1746bool is_dev_an_NTFS_dev(char *bigfile_fname)
1747{
1748 char *tmp;
1749 char *command;
1750 malloc_string(tmp);
1751 bool ret = TRUE;
1752 mr_asprintf(&command,
1753 "dd if=%s bs=512 count=1 2> /dev/null | strings | head -n1",
1754 bigfile_fname);
1755 mr_msg(1, "command = '%s'", command);
1756 strcpy(tmp, call_program_and_get_last_line_of_output(command));
1757 mr_msg(1, "--> tmp = '%s'", tmp);
1758 mr_free(command);
1759 if (strstr(tmp, "NTFS")) {
1760 iamhere("TRUE");
1761 } else {
1762 iamhere("FALSE");
1763 ret = FALSE;
1764 }
1765 return(ret);
1766}
1767
1768
1769/**
1770 * Back up big files by chopping them up.
1771 * This function backs up all "big" files (where "big" depends
1772 * on your backup media) in "chunks" (whose size again depends
1773 * on your media).
1774 *
1775 * @param bkpinfo The backup information structure. Fields used:
1776 * - @c backup_media_type
1777 * - @c optimal_set_size
1778 * @param biggielist_fname The path to a file containing a list of
1779 * all "big" files.
1780 * @return The number of errors encountered (0 for success)
1781 * @see slice_up_file_etc
1782 */
1783int
1784make_slices_and_images(char *biggielist_fname)
1785{
1786
1787 /*@ pointers ******************************************* */
1788 FILE *fin = NULL;
1789 char *p = NULL;
1790
1791 /*@ buffers ******************************************** */
1792 char *tmp = NULL;
1793 char *bigfile_fname = NULL;
1794 char *sz_devfile = NULL;
1795 char *ntfsprog_fifo = NULL;
1796 /*@ long *********************************************** */
1797 long biggie_file_number = 0;
1798 long noof_biggie_files = 0;
1799 long estimated_total_noof_slices = 0;
1800
1801 /*@ int ************************************************ */
1802 int retval = 0;
1803 int res = 0;
1804 size_t n = 0;
1805 pid_t pid;
1806 FILE *ftmp = NULL;
1807 bool delete_when_done;
1808 bool use_ntfsprog;
1809 off_t biggie_fsize;
1810
1811 assert(bkpinfo != NULL);
1812 assert_string_is_neither_NULL_nor_zerolength(biggielist_fname);
1813
1814 estimated_total_noof_slices =
1815 size_of_all_biggiefiles_K() / bkpinfo->optimal_set_size + 1;
1816
1817 mr_msg(1, "size of all biggiefiles = %ld",
1818 size_of_all_biggiefiles_K());
1819 mr_msg(1, "estimated_total_noof_slices = %ld KB / %ld KB = %ld",
1820 size_of_all_biggiefiles_K(), bkpinfo->optimal_set_size,
1821 estimated_total_noof_slices);
1822
1823 if (length_of_file(biggielist_fname) < 6) {
1824 mr_msg(1, "No biggiefiles; fair enough...");
1825 return (0);
1826 }
1827 mr_asprintf(&tmp, "I am now backing up all large files.");
1828 log_to_screen(tmp);
1829 noof_biggie_files = count_lines_in_file(biggielist_fname);
1830 open_progress_form("Backing up big files", tmp,
1831 "Please wait. This may take some time.", "",
1832 estimated_total_noof_slices);
1833 mr_free(tmp);
1834
1835 if (!(fin = fopen(biggielist_fname, "r"))) {
1836 log_OS_error("Unable to openin biggielist");
1837 return (1);
1838 }
1839 for (mr_getline(&bigfile_fname, &n, fin); !feof(fin);
1840 mr_getline(&bigfile_fname, &n, fin), biggie_file_number++) {
1841 use_ntfsprog = FALSE;
1842 if (bigfile_fname[strlen(bigfile_fname) - 1] < 32) {
1843 bigfile_fname[strlen(bigfile_fname) - 1] = '\0';
1844 }
1845 biggie_fsize = length_of_file(bigfile_fname);
1846 delete_when_done = FALSE;
1847
1848 if (!does_file_exist(bigfile_fname)) {
1849 ftmp = fopen(bigfile_fname, "w");
1850 if (ftmp == NULL) {
1851 mr_msg(3, "Unable to write to %s", bigfile_fname);
1852 // So skip it as it doesn't exist
1853 continue;
1854 } else {
1855 paranoid_fclose(ftmp);
1856 }
1857 delete_when_done = TRUE;
1858 } else {
1859 // Call ntfsclone (formerly partimagehack) if it's a /dev entry
1860 // (i.e. a partition to be imaged)
1861 mr_msg(2, "bigfile_fname = %s", bigfile_fname);
1862 use_ntfsprog = FALSE;
1863 if (!strncmp(bigfile_fname, "/dev/", 5)
1864 && is_dev_an_NTFS_dev(bigfile_fname)) {
1865 use_ntfsprog = TRUE;
1866 mr_msg(2,
1867 "Calling ntfsclone in background because %s is an NTFS partition",
1868 bigfile_fname);
1869 mr_asprintf(&sz_devfile, "%s/%d.%d.000",
1870 bkpinfo->tmpdir,
1871 (int) (random() % 32768),
1872 (int) (random() % 32768));
1873 mkfifo(sz_devfile, 0x770);
1874 ntfsprog_fifo = sz_devfile;
1875 switch (pid = fork()) {
1876 case -1:
1877 fatal_error("Fork failure");
1878 case 0:
1879 mr_msg(2,
1880 "CHILD - fip - calling feed_into_ntfsprog(%s, %s)",
1881 bigfile_fname, sz_devfile);
1882 res = feed_into_ntfsprog(bigfile_fname, sz_devfile);
1883 mr_free(sz_devfile);
1884 exit(res);
1885 break;
1886 default:
1887 mr_msg(2,
1888 "feed_into_ntfsprog() called in background --- pid=%ld",
1889 (long int) (pid));
1890 mr_free(sz_devfile);
1891 break;
1892 }
1893 }
1894 // Otherwise, use good old 'dd' and 'bzip2'
1895 else {
1896 ntfsprog_fifo = NULL;
1897 }
1898
1899 // Whether partition or biggiefile, just do your thang :-)
1900 mr_msg(5, "Bigfile #%ld is '%s' (%ld KB)",
1901 biggie_file_number + 1, bigfile_fname,
1902 (long) biggie_fsize >> 10);
1903 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
1904 write_header_block_to_stream(biggie_fsize, bigfile_fname,
1905 use_ntfsprog ?
1906 BLK_START_A_PIHBIGGIE :
1907 BLK_START_A_NORMBIGGIE);
1908 }
1909 res =
1910 slice_up_file_etc(bigfile_fname,
1911 ntfsprog_fifo, biggie_file_number,
1912 noof_biggie_files, use_ntfsprog);
1913 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
1914 write_header_block_to_stream((off_t)0,
1915 calc_checksum_of_file
1916 (bigfile_fname),
1917 BLK_STOP_A_BIGGIE);
1918 }
1919 retval += res;
1920 p = strrchr(bigfile_fname, '/');
1921 if (p) {
1922 p++;
1923 } else {
1924 p = bigfile_fname;
1925 }
1926 if (res) {
1927 mr_asprintf(&tmp, "Archiving %s ... Failed!", bigfile_fname);
1928 } else {
1929 mr_asprintf(&tmp, "Archiving %s ... OK!", bigfile_fname);
1930 }
1931 mr_msg(4,tmp);
1932 mr_free(tmp);
1933 if (delete_when_done) {
1934 unlink(bigfile_fname);
1935 delete_when_done = FALSE;
1936 }
1937 }
1938 if (!g_text_mode) {
1939 newtDrawRootText(0, g_noof_rows - 2, tmp);
1940 newtRefresh();
1941 }
1942 }
1943 mr_free(bigfile_fname);
1944 paranoid_fclose(fin);
1945
1946 mr_msg(1, "Finished backing up bigfiles");
1947 mr_msg(1, "estimated slices = %ld; actual slices = %ld",
1948 estimated_total_noof_slices, g_current_progress);
1949 close_progress_form();
1950 return (retval);
1951}
1952
1953
1954/**
1955 * Single-threaded version of @c make_afioballs_and_images().
1956 * @see make_afioballs_and_images
1957 */
1958int make_afioballs_and_images_OLD()
1959{
1960
1961 /*@ int ************************************************** */
1962 int retval = 0;
1963 long int curr_set_no = 0;
1964 int res = 0;
1965
1966 /*@ buffers ********************************************** */
1967 char *curr_filelist_fname = NULL;
1968 char *curr_afioball_fname = NULL;
1969 char *curr_xattr_list_fname = NULL;
1970 char *curr_acl_list_fname = NULL;
1971 char *media_usage_comment = NULL;
1972 char *tmp= mr_malloc(MAX_STR_LEN * 2);
1973
1974 /* BERLIOS: Useless ?
1975 mr_asprintf(&tmp, "%s/archives/filelist.full", bkpinfo->scratchdir);
1976 */
1977 malloc_string(media_usage_comment);
1978 log_to_screen("Archiving regular files");
1979
1980 open_progress_form(_("Backing up filesystem"),
1981 _("I am backing up your live filesystem now."),
1982 _("Please wait. This may take a couple of hours."),
1983 _("Working..."),
1984 get_last_filelist_number() + 1);
1985
1986 mr_asprintf(&curr_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir,
1987 0L);
1988
1989 curr_set_no = 0;
1990 while (does_file_exist(curr_filelist_fname)) {
1991 /* backup this set of files */
1992 mr_asprintf(&curr_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
1993 bkpinfo->tmpdir, curr_set_no, bkpinfo->zip_suffix);
1994
1995 mr_msg(1, "EXAT'g set %ld", curr_set_no);
1996 if (g_getfattr) {
1997 mr_asprintf(&curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
1998 bkpinfo->tmpdir, curr_set_no);
1999 get_fattr_list(curr_filelist_fname, curr_xattr_list_fname);
2000 }
2001 if (g_getfacl) {
2002 mr_asprintf(&curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
2003 bkpinfo->tmpdir, curr_set_no);
2004 get_acl_list(curr_filelist_fname, curr_acl_list_fname);
2005 }
2006
2007 mr_msg(1, "Archiving set %ld", curr_set_no);
2008 res = archive_this_fileset(curr_filelist_fname,
2009 curr_afioball_fname, curr_set_no);
2010 retval += res;
2011 if (res) {
2012 mr_asprintf(&tmp,
2013 "Errors occurred while archiving set %ld. Perhaps your live filesystem changed?",
2014 curr_set_no);
2015 log_to_screen(tmp);
2016 mr_free(tmp);
2017 }
2018
2019 strcpy(media_usage_comment, percent_media_full_comment());
2020
2021 /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
2022 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2023 register_in_tape_catalog(fileset, curr_set_no, -1,
2024 curr_afioball_fname);
2025 maintain_collection_of_recent_archives(bkpinfo->tmpdir,
2026 curr_afioball_fname);
2027 iamhere("Writing EXAT files");
2028 res += write_EXAT_files_to_tape(curr_xattr_list_fname,
2029 curr_acl_list_fname);
2030 // archives themselves
2031 res = move_files_to_stream(curr_afioball_fname, NULL);
2032 } else {
2033 if (g_getfacl) {
2034 if (g_getfattr) {
2035 res = move_files_to_cd(curr_filelist_fname,
2036 curr_xattr_list_fname,
2037 curr_acl_list_fname,
2038 curr_afioball_fname, NULL);
2039 } else {
2040 res = move_files_to_cd(curr_filelist_fname,
2041 curr_acl_list_fname,
2042 curr_afioball_fname, NULL);
2043 }
2044 } else {
2045 if (g_getfattr) {
2046 res = move_files_to_cd(curr_filelist_fname,
2047 curr_xattr_list_fname,
2048 curr_afioball_fname, NULL);
2049 } else {
2050 res = move_files_to_cd(curr_filelist_fname,
2051 curr_afioball_fname, NULL);
2052 }
2053 }
2054 }
2055 retval += res;
2056 g_current_progress++;
2057 update_progress_form(media_usage_comment);
2058
2059 if (res) {
2060 mr_asprintf(&tmp, "Failed to add archive %ld's files to CD dir\n",
2061 curr_set_no);
2062 log_to_screen(tmp);
2063 mr_free(tmp);
2064 fatal_error
2065 ("Is your hard disk is full? If not, please send the author the logfile.");
2066 }
2067 mr_free(curr_filelist_fname);
2068 mr_free(curr_afioball_fname);
2069 mr_free(curr_xattr_list_fname);
2070 mr_free(curr_acl_list_fname);
2071 mr_asprintf(&curr_filelist_fname, FILELIST_FNAME_RAW_SZ,
2072 bkpinfo->tmpdir, ++curr_set_no);
2073 }
2074 mr_free(curr_filelist_fname);
2075 close_progress_form();
2076 if (retval) {
2077 log_to_screen
2078 ("Your regular files have been archived (with errors).");
2079 } else {
2080 log_to_screen
2081 ("Your regular files have been archived successfully.");
2082 }
2083 mr_free(media_usage_comment);
2084 return (retval);
2085}
2086
2087/* @} - end of LLarchiveGroup */
2088
2089
2090/**
2091 * Wrapper around @c make_afioballs_and_images().
2092 * @param bkpinfo the backup information structure. Only the
2093 * @c backup_media_type field is used within this function.
2094 * @return return code of make_afioballs_and_images
2095 * @see make_afioballs_and_images
2096 * @ingroup MLarchiveGroup
2097 */
2098int make_those_afios_phase()
2099{
2100 /*@ int ******************************************* */
2101 int res = 0;
2102 int retval = 0;
2103
2104 assert(bkpinfo != NULL);
2105
2106 mvaddstr_and_log_it(g_currentY, 0,
2107 "Archiving regular files to media ");
2108
2109 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2110 write_header_block_to_stream((off_t)0, "start-of-afioballs",
2111 BLK_START_AFIOBALLS);
2112#if __FreeBSD__ == 5
2113 mr_msg(1,
2114 "Using single-threaded make_afioballs_and_images() to suit b0rken FreeBSD 5.0");
2115 res = make_afioballs_and_images_OLD();
2116#else
2117 res = make_afioballs_and_images_OLD();
2118#endif
2119 write_header_block_to_stream((off_t)0, "stop-afioballs",
2120 BLK_STOP_AFIOBALLS);
2121 } else {
2122 res = make_afioballs_and_images();
2123 }
2124
2125 retval += res;
2126 if (res) {
2127 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2128 mr_msg(1, "make_afioballs_and_images returned an error");
2129 } else {
2130 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2131 }
2132 return (retval);
2133}
2134
2135/**
2136 * Wrapper around @c make_slices_and_images().
2137 * @param bkpinfo The backup information structure. Fields used:
2138 * - @c backup_media_type
2139 * - @c scratchdir
2140 * - @c tmpdir
2141 * @return The number of errors encountered (0 for success)
2142 * @ingroup MLarchiveGroup
2143 */
2144int make_those_slices_phase()
2145{
2146
2147 /*@ int ***************************************************** */
2148 int res = 0;
2149 int retval = 0;
2150
2151 /*@ buffers ************************************************** */
2152 char *biggielist = NULL;
2153 char *command = NULL;
2154 char *blah = NULL;
2155 char *xattr_fname = NULL;
2156 char *acl_fname = NULL;
2157
2158 assert(bkpinfo != NULL);
2159 /* slice big files */
2160 mvaddstr_and_log_it(g_currentY, 0,
2161 "Archiving large files to media ");
2162 mr_asprintf(&biggielist, "%s/archives/biggielist.txt", bkpinfo->scratchdir);
2163 if (g_getfattr) {
2164 mr_asprintf(&xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
2165 }
2166 if (g_getfacl) {
2167 mr_asprintf(&acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
2168 }
2169
2170 mr_asprintf(&command, "cp %s/biggielist.txt %s", bkpinfo->tmpdir, biggielist);
2171 paranoid_system(command);
2172 mr_free(command);
2173
2174 mr_asprintf(&blah, "biggielist = %s", biggielist);
2175 mr_msg(2, blah);
2176 mr_free(blah);
2177
2178 if (!does_file_exist(biggielist)) {
2179 mr_msg(1, "BTW, the biggielist does not exist");
2180 }
2181
2182 if (g_getfattr) {
2183 get_fattr_list(biggielist, xattr_fname);
2184 mr_asprintf(&command, "cp %s %s/archives/", xattr_fname, bkpinfo->scratchdir);
2185 paranoid_system(command);
2186 mr_free(command);
2187 }
2188 if (g_getfacl) {
2189 get_acl_list(biggielist, acl_fname);
2190 mr_asprintf(&command, "cp %s %s/archives/", acl_fname, bkpinfo->scratchdir);
2191 paranoid_system(command);
2192 mr_free(command);
2193 }
2194
2195 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2196 res += write_EXAT_files_to_tape(xattr_fname, acl_fname);
2197 mr_asprintf(&blah, "%ld", count_lines_in_file(biggielist));
2198 write_header_block_to_stream((off_t)0, blah, BLK_START_BIGGIEFILES);
2199 mr_free(blah);
2200 }
2201 if (g_getfattr) {
2202 mr_free(xattr_fname);
2203 }
2204 if (g_getfacl) {
2205 mr_free(acl_fname);
2206 }
2207
2208 res = make_slices_and_images(biggielist);
2209 mr_free(biggielist);
2210
2211 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2212 write_header_block_to_stream((off_t)0, "end-of-biggiefiles",
2213 BLK_STOP_BIGGIEFILES);
2214 }
2215 retval += res;
2216 if (res) {
2217 mr_msg(1, "make_slices_and_images returned an error");
2218 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2219 } else {
2220 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2221 }
2222 return (retval);
2223}
2224
2225
2226/**
2227 * @addtogroup LLarchiveGroup
2228 * @{
2229 */
2230/**
2231 * Function pointer to an appropriate @c move_files_to_cd routine.
2232 * You can set this to your own function (for example, one to
2233 * transfer files over the network) or leave it as is.
2234 */
2235int (*move_files_to_cd) (char *, ...) =
2236 _move_files_to_cd;
2237
2238/**
2239 * Move some files to the ISO scratch directory.
2240 * This function moves files specified as parameters, into the directory
2241 * @c bkpinfo->scratchdir, where the files that will be stored on the next
2242 * CD are waiting.
2243 *
2244 * @param bkpinfo The backup information structure. Fields used:
2245 * - @c media_size
2246 * - @c scratchdir
2247 * @param files_to_add The files to add to the scratchdir.
2248 * @warning The list of @c files_to_add must be terminated with @c NULL.
2249 * @note If and when the space occupied by the scratchdir would exceed
2250 * the capacity of the current CD,
2251 * <tt>write_iso_and_go_on(bkpinfo, FALSE)</tt> is called and the
2252 * scratchdir is emptied.
2253 *
2254 * @return The number of errors encountered (0 for success)
2255 */
2256int _move_files_to_cd(char *files_to_add, ...)
2257{
2258
2259 /*@ int ************************************************************ */
2260 int retval = 0;
2261 int res = 0;
2262
2263 /*@ buffers ******************************************************** */
2264 char *tmp = NULL;
2265 char *curr_file = NULL;
2266 char *cf = NULL;
2267
2268 /*@ long ************************************************************ */
2269 va_list ap;
2270 long long would_occupy;
2271
2272 assert(bkpinfo != NULL);
2273 would_occupy = space_occupied_by_cd(bkpinfo->scratchdir);
2274 va_start(ap, files_to_add); // initialize the variable arguments
2275 for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
2276 if (!cf) {
2277 continue;
2278 }
2279 mr_asprintf(&curr_file, cf);
2280 if (!does_file_exist(curr_file)) {
2281 mr_msg(1,
2282 "Warning - you're trying to add a non-existent file - '%s' to the CD",
2283 curr_file);
2284 } else {
2285 mr_msg(8, "Trying to add file %s to CD", curr_file);
2286 would_occupy += length_of_file(curr_file) / 1024;
2287 }
2288 mr_free(curr_file);
2289 }
2290 va_end(ap);
2291
2292 if (bkpinfo->media_size <= 0L) {
2293 fatal_error("move_files_to_cd() - unknown media size");
2294 }
2295 if (would_occupy / 1024 > bkpinfo->media_size) {
2296 /* FALSE because this is not the last CD we'll write */
2297 res = write_iso_and_go_on(FALSE);
2298 retval += res;
2299 if (res) {
2300 mr_msg(1, "WARNING - write_iso_and_go_on returned an error");
2301 }
2302 }
2303
2304 va_start(ap, files_to_add); // initialize the variable arguments
2305 for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
2306 if (!cf) {
2307 continue;
2308 }
2309 mr_asprintf(&curr_file, cf);
2310
2311 mr_asprintf(&tmp, "mv -f %s %s/archives/", curr_file,
2312 bkpinfo->scratchdir);
2313 res = run_program_and_log_output(tmp, 5);
2314 retval += res;
2315 if (res) {
2316 mr_msg(1, "(move_files_to_cd) '%s' failed", tmp);
2317 } else {
2318 mr_msg(8, "Moved %s to CD OK", tmp);
2319 }
2320 mr_free(tmp);
2321 mr_free(curr_file);
2322 // unlink (curr_file);
2323 }
2324 va_end(ap);
2325
2326 if (retval) {
2327 mr_msg(1,
2328 "Warning - errors occurred while I was adding files to CD dir");
2329 }
2330 return (retval);
2331}
2332
2333/* @} - end of LLarchiveGroup */
2334
2335
2336/**
2337 * @addtogroup LLarchiveGroup
2338 * @{
2339 */
2340/**
2341 * Function pointer to an appropriate @c move_files_to_stream routine.
2342 * You can set this to your own function (for example, one to
2343 * transfer files over the network) or leave it as is.
2344 */
2345int (*move_files_to_stream) (char *, ...) =
2346 _move_files_to_stream;
2347
2348/**
2349 * Copy some files to tape.
2350 * This function copies the files specified as parameters into the tape stream.
2351 *
2352 * @param bkpinfo The backup information structure. Used only in the call to
2353 * @c write_file_to_stream_from_file().
2354 *
2355 * @param files_to_add The files to copy to the tape stream.
2356 * @warning The list of @c files_to_add must be terminated with @c NULL.
2357 * @note Files may be split across multiple tapes if necessary.
2358 *
2359 * @return The number of errors encountered (0 for success)
2360 */
2361int
2362_move_files_to_stream(char *files_to_add, ...)
2363{
2364
2365 /*@ int ************************************************************ */
2366 int retval = 0;
2367 int res = 0;
2368 /*@ buffers ******************************************************** */
2369
2370 /*@ char *********************************************************** */
2371 char start_chr;
2372 char stop_chr;
2373 char *curr_file = NULL;
2374 char *cf = NULL;
2375 /*@ long long ****************************************************** */
2376 off_t length_of_incoming_file = (off_t)0;
2377 t_archtype type;
2378 va_list ap;
2379
2380 assert(bkpinfo != NULL);
2381 va_start(ap, files_to_add);
2382 for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
2383 if (!cf) {
2384 continue;
2385 }
2386 mr_asprintf(&curr_file, cf);
2387 if (!does_file_exist(curr_file)) {
2388 mr_msg(1,
2389 "Warning - you're trying to add a non-existent file - '%s' to the tape",
2390 curr_file);
2391 }
2392 /* create header chars */
2393 start_chr = BLK_START_AN_AFIO_OR_SLICE;
2394 stop_chr = BLK_STOP_AN_AFIO_OR_SLICE;
2395 /* ask for new tape if necessary */
2396 length_of_incoming_file = length_of_file(curr_file);
2397 write_header_block_to_stream(length_of_incoming_file, curr_file,
2398 start_chr);
2399 if (strstr(curr_file, ".afio.") || strstr(curr_file, ".star.")) {
2400 type = fileset;
2401 } else if (strstr(curr_file, "slice")) {
2402 type = biggieslice;
2403 } else {
2404 type = other;
2405 }
2406 res = write_file_to_stream_from_file(curr_file);
2407 retval += res;
2408 unlink(curr_file);
2409 mr_free(curr_file);
2410 /* write closing header */
2411 write_header_block_to_stream((off_t)0, "finished-writing-file", stop_chr);
2412 }
2413 va_end(ap);
2414
2415 if (retval) {
2416 mr_msg(1,
2417 "Warning - errors occurred while I was adding file to tape");
2418 }
2419 return (retval);
2420}
2421
2422/* @} - end of LLarchiveGroup */
2423
2424
2425/**
2426 * @addtogroup utilityGroup
2427 * @{
2428 */
2429/**
2430 * Make sure the user has a valid CD-R(W) in the CD drive.
2431 * @param cdrw_dev Set to the CD-R(W) device checked.
2432 * @param keep_looping If TRUE, keep pestering user until they insist
2433 * or insert a correct CD; if FALSE, only check once.
2434 * @return 0 (there was an OK CD in the drive) or 1 (there wasn't).
2435 */
2436int interrogate_disk_currently_in_cdrw_drive(char *cdrw_dev,
2437 bool keep_looping)
2438{
2439 int res = 0;
2440 char *bkp = NULL;
2441 char *cdrecord = NULL;
2442
2443 malloc_string(bkp);
2444 strcpy(bkp, cdrw_dev);
2445 if (find_cdrw_device(cdrw_dev)) {
2446 strcpy(cdrw_dev, bkp);
2447 } else {
2448 if (!system("which cdrecord > /dev/null 2> /dev/null")) {
2449 mr_asprintf(&cdrecord, "cdrecord dev=%s -atip", cdrw_dev);
2450 } else if (!system("which dvdrecord > /dev/null 2> /dev/null")) {
2451 mr_asprintf(&cdrecord, "dvdrecord dev=%s -atip", cdrw_dev);
2452 } else {
2453 mr_msg(2, "Oh well. I guess I'll just pray then.");
2454 }
2455 if (cdrecord != NULL) {
2456 if (!keep_looping) {
2457 retract_CD_tray_and_defeat_autorun();
2458 res = run_program_and_log_output(cdrecord, 5);
2459 } else {
2460 while ((res = run_program_and_log_output(cdrecord, 5))) {
2461 retract_CD_tray_and_defeat_autorun();
2462 if (ask_me_yes_or_no
2463 ("Unable to examine CD. Are you sure this is a valid CD-R(W) CD?"))
2464 {
2465 mr_msg(1, "Well, he insisted...");
2466 break;
2467 }
2468 }
2469 }
2470 }
2471 mr_free(cdrecord);
2472 }
2473// retract_CD_tray_and_defeat_autorun();
2474 mr_free(bkp);
2475 return (res);
2476}
2477
2478
2479/**
2480 * Asks the user to put a CD-R(W) in the drive.
2481 * @param ask_for_one_if_more_than_this (unused)
2482 */
2483void
2484pause_and_ask_for_cdr(int ask_for_one_if_more_than_this)
2485{
2486
2487 /*@ buffers ********************************************* */
2488 char *tmp = NULL;
2489 char *szmsg = NULL;
2490 char *cdrom_dev = NULL;
2491 char *cdrw_dev = NULL;
2492 char *our_serial_str = NULL;
2493 bool ok_go_ahead_burn_it;
2494 int cd_number = -1;
2495 int attempt_to_mount_returned_this = 999;
2496 char *mtpt = NULL;
2497 char *szcdno = NULL;
2498 char *szserfname = NULL;
2499 char *szunmount = NULL;
2500
2501 malloc_string(szmsg);
2502 malloc_string(cdrom_dev);
2503 malloc_string(cdrw_dev);
2504 malloc_string(mtpt);
2505 malloc_string(szcdno);
2506 malloc_string(szserfname);
2507 malloc_string(our_serial_str);
2508 malloc_string(szunmount);
2509
2510 sprintf(szmsg, "I am about to burn %s #%d",
2511 media_descriptor_string(g_backup_media_type),
2512 g_current_media_number);
2513 log_to_screen(szmsg);
2514 if (g_current_media_number < ask_for_one_if_more_than_this) {
2515 return;
2516 }
2517 log_to_screen("Scanning CD-ROM drive...");
2518 sprintf(mtpt, "%s/cd.mtpt", bkpinfo->tmpdir);
2519 make_hole_for_dir(mtpt);
2520
2521 gotos_make_me_puke:
2522 ok_go_ahead_burn_it = TRUE;
2523 if (!find_cdrom_device(cdrom_dev, FALSE)) {
2524/* When enabled, it made CD eject-and-retract when wrong CD inserted.. Weird
2525 mr_msg(2, "paafcd: Retracting CD-ROM drive if possible" );
2526 retract_CD_tray_and_defeat_autorun();
2527*/
2528 mr_asprintf(&tmp, "umount %s", cdrom_dev);
2529 run_program_and_log_output(tmp, 1);
2530 mr_free(tmp);
2531 sprintf(szcdno, "%s/archives/THIS-CD-NUMBER", mtpt);
2532 sprintf(szserfname, "%s/archives/SERIAL-STRING", mtpt);
2533 sprintf(szunmount, "umount %s", mtpt);
2534 cd_number = -1;
2535 our_serial_str[0] = '\0';
2536 mr_asprintf(&tmp, "mount %s %s", cdrom_dev, mtpt);
2537 attempt_to_mount_returned_this = run_program_and_log_output(tmp, 1);
2538 mr_free(tmp);
2539 if (attempt_to_mount_returned_this) {
2540 mr_msg(4, "Failed to mount %s at %s", cdrom_dev, mtpt);
2541 log_to_screen("If there's a CD/DVD in the drive, it's blank.");
2542 } else if (!does_file_exist(szcdno)
2543 || !does_file_exist(szserfname)) {
2544 log_to_screen
2545 ("%s has data on it but it's probably not a Mondo CD.",
2546 media_descriptor_string(g_backup_media_type));
2547 } else {
2548 log_to_screen("%s found in drive. It's a Mondo disk.",
2549 media_descriptor_string(g_backup_media_type));
2550 cd_number = atoi(last_line_of_file(szcdno));
2551 mr_asprintf(&tmp, "cat %s 2> /dev/null", szserfname);
2552 strcpy(our_serial_str,
2553 call_program_and_get_last_line_of_output(tmp));
2554 mr_free(tmp);
2555 // FIXME - should be able to use last_line_of_file(), surely?
2556 }
2557 run_program_and_log_output(szunmount, 1);
2558 mr_msg(2, "paafcd: cd_number = %d", cd_number);
2559 mr_msg(2, "our serial str = %s; g_serial_string = %s",
2560 our_serial_str, g_serial_string);
2561 if (cd_number > 0 && !strcmp(our_serial_str, g_serial_string)) {
2562 mr_msg(2, "This %s is part of this backup set!",
2563 media_descriptor_string(g_backup_media_type));
2564 ok_go_ahead_burn_it = FALSE;
2565 if (cd_number == g_current_media_number - 1) {
2566 log_to_screen
2567 ("I think you've left the previous %s in the drive.",
2568 media_descriptor_string(g_backup_media_type));
2569 } else {
2570 log_to_screen
2571 ("Please remove this %s. It is part of the backup set you're making now.",
2572 media_descriptor_string(g_backup_media_type));
2573 }
2574 } else {
2575 log_to_screen("...but not part of _our_ backup set.");
2576 }
2577 } else {
2578 mr_msg(2,
2579 "paafcd: Can't find CD-ROM drive. Perhaps it has a blank %s in it?",
2580 media_descriptor_string(g_backup_media_type));
2581 if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE)) {
2582 ok_go_ahead_burn_it = FALSE;
2583 log_to_screen("There isn't a writable %s in the drive.",
2584 media_descriptor_string(g_backup_media_type));
2585 }
2586 }
2587
2588 if (!ok_go_ahead_burn_it) {
2589 eject_device(cdrom_dev);
2590 mr_asprintf(&tmp,
2591 "I am about to burn %s #%d of the backup set. Please insert %s and press Enter.",
2592 media_descriptor_string(g_backup_media_type),
2593 g_current_media_number,
2594 media_descriptor_string(g_backup_media_type));
2595 popup_and_OK(tmp);
2596 mr_free(tmp);
2597 goto gotos_make_me_puke;
2598 } else {
2599 mr_msg(2, "paafcd: OK, going ahead and burning it.");
2600 }
2601
2602 mr_msg(2,
2603 "paafcd: OK, I assume I have a blank/reusable %s in the drive...",
2604 media_descriptor_string(g_backup_media_type));
2605
2606 // if (ask_for_one_if_more_than_this>1) { popup_and_OK(szmsg); }
2607
2608 log_to_screen("Proceeding w/ %s in drive.",
2609 media_descriptor_string(g_backup_media_type));
2610 mr_free(szmsg);
2611 mr_free(cdrom_dev);
2612 mr_free(cdrw_dev);
2613 mr_free(mtpt);
2614 mr_free(szcdno);
2615 mr_free(szserfname);
2616 mr_free(our_serial_str);
2617 mr_free(szunmount);
2618}
2619
2620
2621/**
2622 * Set the <tt>N</tt>th bit of @c array to @c true_or_false.
2623 * @param array The bit array (as a @c char pointer).
2624 * @param N The bit number to set or reset.
2625 * @param true_or_false If TRUE then set bit @c N, if FALSE then reset bit @c N.
2626 * @see get_bit_N_of_array
2627 */
2628void set_bit_N_of_array(char *array, int N, bool true_or_false)
2629{
2630 int bit_number;
2631 int mask, orig_val, to_add;
2632 int element_number;
2633
2634 assert(array != NULL);
2635
2636 element_number = N / 8;
2637 bit_number = N % 8;
2638 to_add = (1 << bit_number);
2639 mask = 255 - to_add;
2640 orig_val = array[element_number] & mask;
2641 // log_it("array[%d]=%02x; %02x&%02x = %02x", element_number, array[element_number], mask, orig_val);
2642 if (true_or_false) {
2643 array[element_number] = orig_val | to_add;
2644 }
2645}
2646
2647/* @} - end of utilityGroup */
2648
2649
2650/**
2651 * Chop up @c filename.
2652 * @param bkpinfo The backup information structure. Fields used:
2653 * - @c backup_media_type
2654 * - @c compression_level
2655 * - @c optimal_set_size
2656 * - @c tmpdir
2657 * - @c use_lzo
2658 * - @c zip_exe
2659 * - @c zip_suffix
2660 *
2661 * @param biggie_filename The file to chop up.
2662 * @param ntfsprog_fifo The FIFO to ntfsclone if this is an imagedev, NULL otherwise.
2663 * @param biggie_file_number The sequence number of this biggie file (starting from 0).
2664 * @param noof_biggie_files The number of biggie files there are total.
2665 * @return The number of errors encountered (0 for success)
2666 * @see make_slices_and_images
2667 * @ingroup LLarchiveGroup
2668 */
2669int
2670slice_up_file_etc(char *biggie_filename,
2671 char *ntfsprog_fifo, long biggie_file_number,
2672 long noof_biggie_files, bool use_ntfsprog)
2673{
2674
2675 /*@ buffers ************************************************** */
2676 char *tmp = NULL;
2677 char *checksum_line = NULL;
2678 char *command = NULL;
2679 char *tempblock = NULL;
2680 char *curr_slice_fname_uncompressed = NULL;
2681 char *curr_slice_fname_compressed = NULL;
2682 char *file_to_archive = NULL;
2683 char *file_to_openin = NULL;
2684 /*@ pointers ************************************************** */
2685 char *pB = NULL;
2686 FILE *fin = NULL;
2687 FILE *fout = NULL;
2688
2689 /*@ bool ****************************************************** */
2690 bool finished = FALSE;
2691
2692 /*@ long ****************************************************** */
2693 size_t blksize = 0;
2694 long slice_num = 0;
2695 long i;
2696 long optimal_set_size;
2697 bool should_I_compress_slices;
2698 char *suffix = NULL; // for compressed slices
2699
2700 /*@ long long ************************************************** */
2701 off_t totalread = (off_t)0;
2702 off_t totallength = (off_t)0;
2703 off_t length;
2704
2705 /*@ int ******************************************************** */
2706 int retval = 0;
2707 int res = 0;
2708 size_t n = 0;
2709
2710 /*@ structures ************************************************** */
2711 struct s_filename_and_lstat_info biggiestruct;
2712// struct stat statbuf;
2713
2714 assert(bkpinfo != NULL);
2715 assert_string_is_neither_NULL_nor_zerolength(biggie_filename);
2716
2717 biggiestruct.for_backward_compatibility = '\n';
2718 biggiestruct.use_ntfsprog = use_ntfsprog;
2719 optimal_set_size = bkpinfo->optimal_set_size;
2720
2721 if (optimal_set_size < 999) {
2722 fatal_error("bkpinfo->optimal_set_size is insanely small");
2723 }
2724 if (ntfsprog_fifo) {
2725 file_to_openin = ntfsprog_fifo;
2726 mr_asprintf(&checksum_line, "IGNORE");
2727 mr_msg(2,
2728 "Not calculating checksum for %s: it would take too long",
2729 biggie_filename);
2730 if ( !find_home_of_exe("ntfsresize")) {
2731 fatal_error("ntfsresize not found");
2732 }
2733 mr_asprintf(&command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", biggie_filename);
2734 log_it("command = %s", command);
2735 mr_asprintf(&tmp, call_program_and_get_last_line_of_output(command));
2736 mr_free(command);
2737
2738 log_it("res of it = %s", tmp);
2739 totallength = (off_t)atoll(tmp);
2740 mr_free(tmp);
2741 } else {
2742 file_to_openin = biggie_filename;
2743 if (strchr(biggie_filename,'\'') != NULL) {
2744 mr_asprintf(&command, "md5sum \"%s\"", biggie_filename);
2745 } else {
2746 mr_asprintf(&command, "md5sum '%s'", biggie_filename);
2747 }
2748 if (!(fin = popen(command, "r"))) {
2749 log_OS_error("Unable to popen-in command");
2750 mr_free(command);
2751 return (1);
2752 }
2753 mr_free(command);
2754 mr_getline(&checksum_line, &n, fin);
2755 pclose(fin);
2756 totallength = length_of_file (biggie_filename);
2757 }
2758 lstat(biggie_filename, &biggiestruct.properties);
2759 if (strlen(biggie_filename) <= MAX_STR_LEN) {
2760 strcpy(biggiestruct.filename, biggie_filename);
2761 } else {
2762 fatal_error("biggie_filename too big");
2763 }
2764 pB = strchr(checksum_line, ' ');
2765 if (!pB) {
2766 pB = strchr(checksum_line, '\t');
2767 }
2768 if (pB) {
2769 *pB = '\0';
2770 }
2771 if (strlen(checksum_line) <= 64) {
2772 strcpy(biggiestruct.checksum, checksum_line);
2773 } else {
2774 fatal_error("checksum_line too big");
2775 }
2776 mr_free(checksum_line);
2777
2778 mr_asprintf(&tmp, slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, ""));
2779 fout = mr_fopen(tmp, "w");
2780 mr_free(tmp);
2781
2782 (void) fwrite((void *) &biggiestruct, 1, sizeof(biggiestruct), fout);
2783 mr_fclose(fout);
2784 length = totallength / optimal_set_size / 1024;
2785 mr_msg(1, "Opening in %s; slicing it and writing to CD/tape",
2786 file_to_openin);
2787 if (!(fin = fopen(file_to_openin, "r"))) {
2788 log_OS_error("Unable to openin biggie_filename");
2789 mr_asprintf(&tmp, "Cannot archive bigfile '%s': not found",
2790 biggie_filename);
2791 log_to_screen(tmp);
2792 mr_free(tmp);
2793 return (1);
2794 }
2795 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2796 res =
2797 move_files_to_stream(slice_fname(biggie_file_number, 0,
2798 bkpinfo->tmpdir, ""), NULL);
2799 } else {
2800 res =
2801 move_files_to_cd(slice_fname(biggie_file_number, 0,
2802 bkpinfo->tmpdir, ""), NULL);
2803 }
2804 if (is_this_file_compressed(biggie_filename)
2805 || bkpinfo->compression_level == 0) {
2806 mr_asprintf(&suffix, "");
2807 should_I_compress_slices = FALSE;
2808 } else {
2809 mr_asprintf(&suffix, bkpinfo->zip_suffix);
2810 should_I_compress_slices = TRUE;
2811 }
2812 i = bkpinfo->optimal_set_size / 256;
2813 for (slice_num = 1; !finished; slice_num++) {
2814 mr_asprintf(&curr_slice_fname_uncompressed,
2815 slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir,
2816 ""));
2817 mr_asprintf(&curr_slice_fname_compressed,
2818 slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir,
2819 suffix));
2820
2821 mr_asprintf(&tmp, percent_media_full_comment());
2822 update_progress_form(tmp);
2823 mr_free(tmp);
2824
2825 if (!(fout = fopen(curr_slice_fname_uncompressed, "w"))) {
2826 log_OS_error(curr_slice_fname_uncompressed);
2827 mr_free(curr_slice_fname_uncompressed);
2828 mr_free(curr_slice_fname_compressed);
2829 mr_free(suffix);
2830 return (1);
2831 }
2832 tempblock = mr_malloc(256 * 1024);
2833 if ((i == bkpinfo->optimal_set_size / 256)
2834 && (totalread < 1.1 * totallength)) {
2835 for (i = 0; i < bkpinfo->optimal_set_size / 256; i++) {
2836 blksize = fread(tempblock, 1, 256 * 1024, fin);
2837 if (blksize > 0) {
2838 totalread = totalread + blksize;
2839 (void) fwrite(tempblock, 1, blksize, fout);
2840 } else {
2841 break;
2842 }
2843 }
2844 } else {
2845 i = 0;
2846 }
2847 mr_free(tempblock);
2848 paranoid_fclose(fout);
2849 if (i > 0) // length_of_file (curr_slice_fname_uncompressed)
2850 {
2851 if (!does_file_exist(curr_slice_fname_uncompressed)) {
2852 mr_msg(2,
2853 "Warning - '%s' doesn't exist. How can I compress slice?",
2854 curr_slice_fname_uncompressed);
2855 }
2856 if (should_I_compress_slices && bkpinfo->compression_level > 0) {
2857 mr_asprintf(&command, "%s -%d %s", bkpinfo->zip_exe,
2858 bkpinfo->compression_level,
2859 curr_slice_fname_uncompressed);
2860 mr_msg(2, command);
2861 if ((res = system(command))) {
2862 log_OS_error(command);
2863 }
2864 mr_free(command);
2865 // did_I_compress_slice = TRUE;
2866 } else {
2867 /* BERLIOS: Useless
2868 mr_asprintf(&command, "mv %s %s 2>> %s",
2869 curr_slice_fname_uncompressed,
2870 curr_slice_fname_compressed, MONDO_LOGFILE);
2871 */
2872 res = 0; // don't do it :)
2873 // did_I_compress_slice = FALSE;
2874 }
2875 retval += res;
2876 if (res) {
2877 mr_msg(2, "Failed to compress the slice");
2878 }
2879 if (bkpinfo->use_lzo
2880 && strcmp(curr_slice_fname_compressed,
2881 curr_slice_fname_uncompressed)) {
2882 unlink(curr_slice_fname_uncompressed);
2883 }
2884 if (res) {
2885 mr_asprintf(&tmp, "Problem with slice # %ld", slice_num);
2886 } else {
2887 mr_asprintf(&tmp,
2888 "%s - Bigfile #%ld, slice #%ld compressed OK ",
2889 biggie_filename, biggie_file_number + 1,
2890 slice_num);
2891 }
2892 if (!g_text_mode) {
2893 newtDrawRootText(0, g_noof_rows - 2, tmp);
2894 newtRefresh();
2895 } else {
2896 mr_msg(2, tmp);
2897 }
2898 mr_free(tmp);
2899 mr_asprintf(&file_to_archive, curr_slice_fname_compressed);
2900 g_current_progress++;
2901 } else { /* if i==0 then ... */
2902
2903 finished = TRUE;
2904 mr_asprintf(&file_to_archive, curr_slice_fname_uncompressed);
2905 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2906 break;
2907 }
2908 }
2909
2910 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2911 register_in_tape_catalog(biggieslice, biggie_file_number,
2912 slice_num, file_to_archive);
2913 maintain_collection_of_recent_archives(bkpinfo->tmpdir,
2914 file_to_archive);
2915 res = move_files_to_stream(file_to_archive, NULL);
2916 } else {
2917 res = move_files_to_cd(file_to_archive, NULL);
2918 }
2919 mr_free(file_to_archive);
2920 retval += res;
2921 if (res) {
2922 mr_asprintf(&tmp,
2923 "Failed to add slice %ld of bigfile %ld to scratchdir",
2924 slice_num, biggie_file_number + 1);
2925 log_to_screen(tmp);
2926 mr_free(tmp);
2927 fatal_error
2928 ("Hard disk full. You should have bought a bigger one.");
2929 }
2930 mr_free(curr_slice_fname_uncompressed);
2931 mr_free(curr_slice_fname_compressed);
2932 }
2933 mr_free(suffix);
2934 paranoid_fclose(fin);
2935 if (retval) {
2936 mr_asprintf(&tmp, "Sliced bigfile #%ld...FAILED",
2937 biggie_file_number + 1);
2938 } else {
2939 mr_asprintf(&tmp, "Sliced bigfile #%ld...OK!",
2940 biggie_file_number + 1);
2941 }
2942 mr_msg(1, tmp);
2943 mr_free(tmp);
2944 return (retval);
2945}
2946
2947
2948/**
2949 * Remove the archives in @c d.
2950 * This could possibly include any of:
2951 * - all afioballs (compressed and not)
2952 * - all filelists
2953 * - all slices
2954 * - all checksums
2955 * - a zero filler file
2956 *
2957 * @param d The directory to wipe the archives from.
2958 * @ingroup utilityGroup
2959 */
2960void wipe_archives(char *d)
2961{
2962 /*@ buffers ********************************************* */
2963 char *tmp = NULL;
2964 char *dir = NULL;
2965
2966 assert_string_is_neither_NULL_nor_zerolength(d);
2967
2968 mr_asprintf(&dir, "%s/archives", d);
2969 mr_asprintf(&tmp, "find %s -name '*.afio*' -exec rm -f '{}' \\;", dir);
2970 run_program_and_log_output(tmp, FALSE);
2971 mr_free(tmp);
2972 mr_asprintf(&tmp, "find %s -name '*list.[0-9]*' -exec rm -f '{}' \\;",
2973 dir);
2974 run_program_and_log_output(tmp, FALSE);
2975 mr_free(tmp);
2976
2977 mr_asprintf(&tmp, "find %s -name 'slice*' -exec rm -f '{}' \\;", dir);
2978 run_program_and_log_output(tmp, FALSE);
2979 mr_free(tmp);
2980
2981 mr_asprintf(&tmp, "rm -f %s/cklist*", dir);
2982 run_program_and_log_output(tmp, FALSE);
2983 mr_free(tmp);
2984
2985 mr_asprintf(&tmp, "rm -f %s/zero", dir);
2986 run_program_and_log_output(tmp, FALSE);
2987 mr_free(tmp);
2988
2989 mr_msg(1, "Wiped %s's archives", dir);
2990 mr_asprintf(&tmp, "ls -l %s", dir);
2991 run_program_and_log_output(tmp, FALSE);
2992 mr_free(tmp);
2993
2994 mr_free(dir);
2995}
2996
2997
2998/**
2999 * @addtogroup LLarchiveGroup
3000 * @{
3001 */
3002/**
3003 * Write the final ISO image.
3004 * @param bkpinfo The backup information structure. Used only
3005 * in the call to @c write_iso_and_go_on().
3006 * @return The number of errors encountered (0 for success)
3007 * @see write_iso_and_go_on
3008 * @see make_iso_fs
3009 * @bug The final ISO is written even if there are no files on it. In practice,
3010 * however, this occurs rarely.
3011 */
3012int write_final_iso_if_necessary()
3013{
3014 /*@ int ***************************************************** */
3015 int res;
3016
3017 /*@ buffers ************************************************** */
3018 char *tmp = NULL;
3019
3020 assert(bkpinfo != NULL);
3021
3022// 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
3023
3024 mr_asprintf(&tmp, "Writing the final ISO");
3025 mr_msg(2, tmp);
3026 /* BERLIOS: Doesn't work on allocated chains anymore
3027 center_string(tmp, 80);
3028 */
3029#ifndef _XWIN
3030 if (!g_text_mode) {
3031 newtPushHelpLine(tmp);
3032 }
3033#endif
3034 mr_free(tmp);
3035 res = write_iso_and_go_on(TRUE);
3036#ifndef _XWIN
3037 if (!g_text_mode) {
3038 newtPopHelpLine();
3039 }
3040#endif
3041 mr_msg(2, "Returning from writing final ISO (res=%d)", res);
3042 return (res);
3043}
3044
3045
3046/**
3047 * Write an ISO image to <tt>[bkpinfo->isodir]/bkpinfo->prefix-[g_current_media_number].iso</tt>.
3048 * @param bkpinfo The backup information structure. Fields used:
3049 * - @c backup_media_type
3050 * - @c prefix
3051 * - @c isodir
3052 * - @c manual_tray
3053 * - @c media_size
3054 * - @c nfs_mount
3055 * - @c nfs_remote_dir
3056 * - @c scratchdir
3057 * - @c verify_data
3058 *
3059 * @param last_cd If TRUE, this is the last CD to write; if FALSE, it's not.
3060 * @return The number of errors encountered (0 for success)
3061 * @see make_iso_fs
3062 */
3063int write_iso_and_go_on(bool last_cd)
3064{
3065 /*@ pointers **************************************************** */
3066 FILE *fout;
3067
3068 /*@ buffers ***************************************************** */
3069 char *tmp;
3070 char *cdno_fname;
3071 char *lastcd_fname;
3072 char *isofile;
3073
3074 /*@ bool ******************************************************** */
3075 bool that_one_was_ok;
3076 bool using_nfs;
3077 bool orig_vfy_flag_val;
3078
3079 /*@ int *********************************************************** */
3080 int res = 0;
3081
3082 assert(bkpinfo != NULL);
3083 orig_vfy_flag_val = bkpinfo->verify_data;
3084 if (bkpinfo->media_size <= 0L) {
3085 fatal_error("write_iso_and_go_on() - unknown media size");
3086 }
3087
3088 if (strlen(bkpinfo->nfs_mount) > 1) {
3089 using_nfs = TRUE;
3090 } else {
3091 using_nfs = FALSE;
3092 }
3093 mr_msg(1, "OK, time to make %s #%d",
3094 bkpinfo->backup_media_string,
3095 g_current_media_number);
3096
3097 /* label the ISO with its number */
3098
3099 mr_asprintf(&cdno_fname, "%s/archives/THIS-CD-NUMBER",
3100 bkpinfo->scratchdir);
3101 fout = fopen(cdno_fname, "w");
3102 fprintf(fout, "%d", g_current_media_number);
3103 paranoid_fclose(fout);
3104 mr_free(cdno_fname);
3105
3106 mr_asprintf(&tmp, "cp -f %s/autorun %s/", MONDO_SHARE,
3107 bkpinfo->scratchdir);
3108 if (run_program_and_log_output(tmp, FALSE)) {
3109 mr_msg(2, "Warning - unable to copy autorun to scratchdir");
3110 }
3111 mr_free(tmp);
3112
3113 /* last CD or not? Label accordingly */
3114 mr_asprintf(&lastcd_fname, "%s/archives/NOT-THE-LAST",
3115 bkpinfo->scratchdir);
3116 if (last_cd) {
3117 unlink(lastcd_fname);
3118 mr_msg(2,
3119 "OK, you're telling me this is the last CD. Fair enough.");
3120 } else {
3121 fout = fopen(lastcd_fname, "w");
3122 fprintf(fout,
3123 "You're listening to 90.3 WPLN, Nashville Public Radio.\n");
3124 paranoid_fclose(fout);
3125 }
3126 mr_free(lastcd_fname);
3127
3128 if (space_occupied_by_cd(bkpinfo->scratchdir) / 1024 > bkpinfo->media_size) {
3129 mr_asprintf(&tmp,
3130 "Warning! %s is too big. It occupies %ld KB, which is more than the %ld KB allowed.",
3131 media_descriptor_string(bkpinfo->backup_media_type),
3132 (long) space_occupied_by_cd(bkpinfo->scratchdir),
3133 bkpinfo->media_size);
3134 log_to_screen(tmp);
3135 mr_free(tmp);
3136 }
3137 if (bkpinfo->backup_media_type != usb) {
3138 mr_asprintf(&isofile, "%s/%s/%s-%d.iso", bkpinfo->isodir,
3139 bkpinfo->nfs_remote_dir, bkpinfo->prefix,
3140 g_current_media_number);
3141 } else {
3142 }
3143 for (that_one_was_ok = FALSE; !that_one_was_ok;) {
3144 if (bkpinfo->backup_media_type != usb) {
3145 res = make_iso_fs(isofile);
3146 } else {
3147 }
3148 if (g_current_media_number == 1 && !res
3149 && (bkpinfo->backup_media_type == cdr
3150 || bkpinfo->backup_media_type == cdrw)) {
3151 if (find_cdrom_device(tmp, FALSE)) // make sure find_cdrom_device() finds, records CD-R's loc
3152 {
3153 mr_msg(3, "*Sigh* Mike, I hate your computer.");
3154 bkpinfo->manual_tray = TRUE;
3155 } // if it can't be found then force pausing
3156 else {
3157 mr_msg(3, "Great. Found Mike's CD-ROM drive.");
3158 }
3159 }
3160 if (bkpinfo->verify_data && !res) {
3161 log_to_screen
3162 ("Please reboot from the 1st %s in Compare Mode, as a precaution.",
3163 media_descriptor_string(g_backup_media_type));
3164 chdir("/");
3165 iamhere("Before calling verify_cd_image()");
3166 res += verify_cd_image();
3167 iamhere("After calling verify_cd_image()");
3168 }
3169 if (!res) {
3170 that_one_was_ok = TRUE;
3171 } else {
3172 mr_asprintf(&tmp, "Failed to burn %s #%d. Retry?",
3173 bkpinfo->backup_media_string,
3174 g_current_media_number);
3175 res = ask_me_yes_or_no(tmp);
3176 mr_free(tmp);
3177 if (!res) {
3178 if (ask_me_yes_or_no("Abort the backup?")) {
3179 fatal_error("FAILED TO BACKUP");
3180 } else {
3181 break;
3182 }
3183 } else {
3184 mr_msg(2, "Retrying, at user's request...");
3185 res = 0;
3186 }
3187 }
3188 }
3189 mr_free(isofile);
3190
3191 g_current_media_number++;
3192 wipe_archives(bkpinfo->scratchdir);
3193 mr_asprintf(&tmp, "rm -Rf %s/images/*gz %s/images/*data*img",
3194 bkpinfo->scratchdir, bkpinfo->scratchdir);
3195 if (system(tmp)) {
3196 mr_msg(2,
3197 "Error occurred when I tried to delete the redundant IMGs and GZs");
3198 }
3199 mr_free(tmp);
3200
3201 if (last_cd) {
3202 mr_msg(2, "This was your last CD.");
3203 } else {
3204 mr_msg(2, "Continuing to backup your data...");
3205 }
3206
3207 bkpinfo->verify_data = orig_vfy_flag_val;
3208 return (0);
3209}
3210
3211/* @} - end of LLarchiveGroup */
3212
3213
3214/**
3215 * Verify the user's data.
3216 * @param bkpinfo The backup information structure. Fields used:
3217 * - @c backup_data
3218 * - @c backup_media_type
3219 * - @c media_device
3220 * - @c verify_data
3221 *
3222 * @return The number of errors encountered (0 for success)
3223 * @ingroup verifyGroup
3224 */
3225int verify_data()
3226{
3227 int res = 0, retval = 0, cdno = 0;
3228 char *tmp = NULL;
3229 long diffs = 0;
3230
3231 assert(bkpinfo != NULL);
3232 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
3233 chdir("/");
3234 mvaddstr_and_log_it(g_currentY, 0,
3235 "Verifying archives against live filesystem");
3236 verify_tape_backups();
3237 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
3238 } else if (bkpinfo->backup_data)
3239 //bkpinfo->backup_media_type == cdrw || bkpinfo->backup_media_type == cdr))
3240 {
3241 mr_msg(2,
3242 "Not verifying again. Per-CD/ISO verification already carried out.");
3243 sprintf(tmp, "cat %s/changed.files > %s/changed.files 2> /dev/null",bkpinfo->tmpdir, MINDI_CACHE);
3244 paranoid_system(tmp);
3245 } else {
3246 g_current_media_number = cdno;
3247 chdir("/");
3248 for (cdno = 1; cdno < 99 && bkpinfo->verify_data; cdno++) {
3249 if (cdno != g_current_media_number) {
3250 mr_msg(2,
3251 "Warning - had to change g_current_media_number from %d to %d",
3252 g_current_media_number, cdno);
3253 g_current_media_number = cdno;
3254 }
3255 if (bkpinfo->backup_media_type != iso) {
3256 insist_on_this_cd_number(cdno);
3257 }
3258 res = verify_cd_image(); // sets verify_data to FALSE if it's time to stop verifying
3259 retval += res;
3260 if (res) {
3261 mr_asprintf(&tmp,
3262 "Warnings/errors were reported while checking %s #%d",
3263 media_descriptor_string(bkpinfo->backup_media_type),
3264 g_current_media_number);
3265 log_to_screen(tmp);
3266 mr_free(tmp);
3267
3268 }
3269 }
3270 mr_asprintf(&tmp,
3271 "grep 'afio: ' %s | sed 's/afio: //' | grep -vE '^/dev/.*$' >> %s/changed.files",
3272 MONDO_LOGFILE, MINDI_CACHE);
3273 system(tmp);
3274 mr_free(tmp);
3275
3276 mr_asprintf(&tmp,
3277 "grep 'star: ' %s | sed 's/star: //' | grep -vE '^/dev/.*$' >> %s/changed.files",
3278 MONDO_LOGFILE, MINDI_CACHE);
3279 system(tmp);
3280 mr_free(tmp);
3281
3282 run_program_and_log_output("umount " MNT_CDROM, FALSE);
3283 eject_device(bkpinfo->media_device);
3284 }
3285 sprintf(tmp, "%s/changed.files", MINDI_CACHE);
3286 diffs = count_lines_in_file(tmp);
3287
3288 if (diffs > 0) {
3289 if (retval == 0) {
3290 retval = (int) (-diffs);
3291 }
3292 }
3293 return (retval);
3294}
3295
3296
3297void setenv_mondo_var(void) {
3298
3299 char *tmp = NULL;
3300 char *p = NULL;
3301 char *path_min = "/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
3302
3303 mr_setenv("MONDO_SHARE",MONDO_SHARE);
3304 mr_setenv("MONDORESTORECFG",MONDORESTORECFG);
3305 mr_setenv("MONDO_CACHE",MONDO_CACHE);
3306 /* Add the ARCH environment variable for ia64 purposes */
3307 mr_setenv("ARCH", get_architecture());
3308
3309
3310 if ((p = getenv("PATH")) == NULL) {
3311 mr_asprintf(&tmp, path_min);
3312 } else {
3313 mr_asprintf(&tmp, "%s:%s",p, path_min);
3314 }
3315 mr_setenv("PATH",tmp);
3316 mr_free(tmp);
3317}
Note: See TracBrowser for help on using the repository browser.