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