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

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

r3342@localhost: bruno | 2009-08-14 00:46:51 +0200

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