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