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

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

Continue to remove floppy support

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