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

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

Continue to use configuration file data (may not compile)

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