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