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