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