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