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