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

Last change on this file since 3373 was 3373, checked in by Bruno Cornec, 9 years ago

Change the bkpinfo->boot_device from statically allocated to dynamically allocated

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