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