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