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