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

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