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