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