source: MondoRescue/branches/3.2/mondo/src/common/libmondo-archive.c@ 3191

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