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