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

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

handle 2 new conf file parameters

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