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