source: MondoRescue/branches/3.1/mondo/src/common/libmondo-archive.c@ 2937

Last change on this file since 2937 was 2937, checked in by Bruno Cornec, 12 years ago

svn merge -r 2849:2935 ../3.0

  • Adds 3 binaries called potentially by udev o support USB key mount at restore time (Victor Gattegno)
  • mindi only sets the boot flag of a USB device if none is present already (should avoid flip/flop situation)
  • Fix a compatibility bug in analyze-my-lvm whete exclude lists with '|' was incorrectly analyzed (' ' still expected)
  • Precise that -J is not supported by mondorestore yet.
  • Fix a compatibility bug in mindi where exclude lists with '|' was incorrectly analyzed (' ' still expected)
  • Install an MBR on USB devices when possible
  • Improve error message in case mondorestore isn't found
  • Adds support for more virtio devices for KVM restore
  • Improve mbr.bin handling
  • Fix an issue in test of FindKernel for Xen and non Xen cases
    • Fix #492 by removing an extra useless fi
    • Move fvat nd fat modules to CDROM_MODS in order to have them in the initrd to support saving logs to a USB device e.g.
    • Fix an error when dmidecode reports comments before system name
    • Fix previous broken patch on comment management for bkphw
    • Improve msgs printed during kbd analysis
    • Fix a small remaining pb with new comment support
    • Try to again improve the mount/umount stuff in mondo -Adds mention to OEL, CentOS, ScientifLinux as RHEL clones
  • Fix a panadoid_free done on the wrong variable (solve a memory leak)
  • Solve #495 by skipping the potential (auto-read-only) when analyzin /proc/mdstat result
  • Fix some markup in man pages
  • adds the post-nuke script sample for Debian (Guillaume Pernot/Andrée Leidenfrost)
  • Avoid a useless umount when changing of afio set, let insist_on_cd check and perform if needed
  • Copy everything under .ssh of root account to allow for sshfs mount without passwd at restore time.
  • Adds support for bnx2i driver
  • Try to fix #496 by supporting the protocol in the output of the mount command (sshfs#...)
  • Uses the -d option of the mount command to avoid leaving loop devices in use. Probably provoked by the usage of a more recent busybox, but anyway that option doesn't hurt, and does nothing for non-loop devices. Should fix the problems reported on the ML with NFS and more than 8 ISO images (8 being the default number of loop devices available)
  • Attempt to fix #436 by adding some newtDrawForm where appropriate.
  • Fix bugs in the kernel detection routine of mindi (some echo were done without capturing their output, confusing the return). This should also help the Xen detection issue
  • Change the logging function to be nearer from 2.2.10, and start using some
  • Initialize some global fields with an empty string, now that newt Draws more regularly progress forms
  • Mindi progression still not good, but showing now 3% when calling mindi. Would need a specific handling for the progress bar to evolve more afterwards
  • Add compatibility with the latest SSSTK + PSP content for HP ProLiant + branding homogeneous now. We only take conrep out of the SSSTK pending a package availability. Using hpacuscripting now. Review of parameters called following test made.
  • Fix #501 by pushing BOOT_SIZE to 36864 for certain Ubuntu cases
  • Fix some remaining inconsistencis in the ProLiant HW backup. ready for usage.
  • Fix an issue on udevadm call (needs an intermediate variable)
  • Fix a remaining ProLiant tool call
  • Remove again some wrong variable initialization for Net in order to not have strange messages now we call Draw more often
  • Adds support for hwaddr (MAC addresses) at restore time, and map to the correct NIC if it's found at restore time (based on code from Stefan Heijmans)
  • Try to Fix #499 by changing init in order to never exit, and rebooting using sysrq in /proc (not portable). Maybe should move to using a real init, and a separated rcS script.
  • Fixes the shell msg error by using setsid as per Busybox FAQ
  • Fix #491 by correctly checking Xen kernel used for a dom0 env (apollo13)
  • Improves logging in Die()
  • Improve again ProLiant HW support, by adding references to the yet to come SSSTK rpm so that conrep is called at its future right place.
  • Improve mindi support for kernel 3.x
  • Fix #499 for good, by using a real init from busybox and moving our init script to etc/init.d/rcS. We also now call the reboot from busybox to exit, which indeed reset the system correctly (in a VM at least which wasn't the case before). Reauires a new mindi-busybox as well.
  • Attempt to solve #503 by handling /lib64 separately for udev and only if not a link (to /lib) for Ubuntu 64
  • Improve again previous tests for bug #503
  • Improve -d option description for NFS
  • Allow http download for ftp content
  • New italian mirror
  • Fix #505 by documenting environment variables
    • Fix a bug where on OBDR mode compression was turned off to create the OBDR content but not back on (report from the mailing list)
  • solve http://trac.mondorescue.org/ticket/520 by Victor Gattegno
  • Fix #524 as option -U needs a size also
  • Removes useless gendf option
  • Fix #511 now stabgrub is called also after conf file modifications
  • Adds support for SUID binaries
  • remove a useless xenkernelname variable from mindi
  • Should fix #512 by clearing old scratchdir before changing to a new
  • Simplify the function engaging SCSI for Smart Array controllers, and support as many controller as we have
  • Add some binaries used on SLES 10 by udev
  • Fix a syntax issue in newt-specific.c
  • Fix a memory free bug where a used variable was freed to early
  • Fix a memory free bug where a used variable was misused in asprintf/free
  • Fix #498 by using an external program (hpsa_obdr_mode) which can set the mode of the tape to CD-ROM or Sequential at will.

That program will have to be downloaded from http://cciss.sf.net

  • Adds support for the route command in mindi-busybox
  • Force block size back to 32768 in OBDR mode after skipping the 2 tape marks, to read the additional rootfs data corerctly - Fix #498 for good it seems
  • Adds support for a new pata_atiixp driver
  • Fix #525 and improve printing when no /etc/raidtab, but still md devices
  • Exclude /run similarly to /sys and /proc
  • Fix a bug in mindi when having multiple swap partiions with same starting string (/dev/dm-1 and /dev/dm-16). We now add a space in the grep to avoid mischoice.
  • Fix grub installation if we had to go in the hack part which wasn't using the correct variables to make decisions !
  • Remove all mention of mondorescue.com from code
  • Fix some website typo on the download page and precise that we now develop on Mageia
  • Exclude sysfs devpts and tmpfs partitions found in RHEL 6.2 from analyze by mindi (made error messages)
  • Force activation of first partition which should not be optional as everything is destroyed before
  • Fix a bug in analyze-my-lvm where LVs were created in random order (the one of lvscan) instead of using the dm-xxx order, which creates issues at restore time between the mapping created then and the one we had at backup time which could be inconssistent

-mondoarchive now exists if the mt command is missing when needed

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