source: MondoRescue/branches/3.0/mondo/src/common/libmondo-archive.c@ 2944

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