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