source: MondoRescue/branches/2.2.10/mondo/src/common/libmondo-archive.c@ 2405

Last change on this file since 2405 was 2405, checked in by Bruno Cornec, 15 years ago

Removes some malloc_string static allocation

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