source: MondoRescue/branches/2.2.6/mondo/src/common/libmondo-archive.c@ 1920

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