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