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

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

r3333@localhost: bruno | 2009-08-08 01:58:31 +0200

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