source: MondoRescue/trunk/mondo/src/common/libmondo-archive.c@ 1043

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

merge -r978:1042 $SVN_M/branches/stable

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