source: MondoRescue/branches/2.2.9/mondo/src/common/libmondo-archive.c@ 2227

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

Remove the iamhere function (will hopefully suppress valgrind errors at restore time)

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