source: MondoRescue/branches/3.3/mondo/src/common/libmondo-archive.c@ 3875

Last change on this file since 3875 was 3875, checked in by Bruno Cornec, 4 months ago

find_dvd|cdrom_device merged into a rewritten find_optical_device - adds find_usb_device and find_device - mount_CDROM_here moved to mount_media (ongoing)

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