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

Last change on this file since 2623 was 2623, checked in by Bruno Cornec, 14 years ago

r3783@localhost: bruno | 2010-04-11 11:57:27 +0200

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