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