source: MondoRescue/branches/stable/mondo/src/common/libmondo-archive.c@ 1663

Last change on this file since 1663 was 1663, checked in by Bruno Cornec, 17 years ago
  • Fix bug #197 (based on an initial patch of Scott Cummings)
  • Fix a bug where df was using locale to print messages and wasn't filtered correctly
  • mkdtemp checked in configure
  • reset_bkpinfo called as early as possible by both main program.
  • It creates a tmpdir cleanly with mkdtemp in setup_tmpdir subfunction, which takes in account TMPIR and TMP env var. Remains to see what tmpfs does and tests
  • configure.in should also be filtered.
  • Remove g_bkpinfo_DONTUSETHIS
  • remove bkpinfo also from header files
  • Render bkpinfo global (potential issue on thread, but should not be a problem as that structure is indeed static during archive)
  • Apply patch from Andree Leidenfrost, modified a bit to use bkpinfo->tmpdir instead of /tmp or MINDI_CACHE when appropriate. Fix security issues in mondo. Thanks al ot Andree for catching all those issues.
  • /tmp => /var/log for mondorestore.log in mindi
  • Update linux terminfo to fix a color issue (Andree Leidenfrost)
  • Removes useless log file (Andree Leidenfrost)
  • replace vi with find_my_editor during restore (Andree Leidenfrost)
  • sync in bg in mindi (VMWare issue to look at)
  • mindi/mindi-busybox have a different version than mondo for pb
  • PB-SUF also added to spec file
  • Fix a bug for pb build (omission of PB-SUF declaration)

(merge -r1631:1662 $SVN_M/branches/2.2.5)

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