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

Last change on this file since 3567 was 3567, checked in by Bruno Cornec, 8 years ago

Add a MONDO_LOGFILENAME variable to allow the basename to be used when compressing the log on the target media

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