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

Last change on this file since 2291 was 2291, checked in by Bruno Cornec, 15 years ago
  • Fix a printing error in mindi for the tar command
  • Fix all mr_asprintf which had no second param as a string

(report bug fix done originaly in 2.2.9)

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