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

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