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

Last change on this file since 1769 was 1769, checked in by Bruno Cornec, 16 years ago

Continue on configuration file items (compression)

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