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

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