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