[1] | 1 | /* libmondo-archive.c
|
---|
[99] | 2 | $Id: libmondo-archive.c 1256 2007-03-21 11:48:32Z 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>
|
---|
[1152] | 16 | #include <stdlib.h>
|
---|
[1107] | 17 | #include <unistd.h>
|
---|
[1] | 18 |
|
---|
[1067] | 19 | #include "my-stuff.h"
|
---|
[1193] | 20 | #include "mondostructures.h"
|
---|
[1256] | 21 |
|
---|
[1107] | 22 | #include "mr_conf.h"
|
---|
| 23 | #include "mr_mem.h"
|
---|
[1123] | 24 | #include "mr_msg.h"
|
---|
[1107] | 25 | #include "mr_err.h"
|
---|
| 26 | #include "mr_str.h"
|
---|
| 27 | #include "mr_file.h"
|
---|
| 28 |
|
---|
[1] | 29 | #include "libmondo-string-EXT.h"
|
---|
| 30 | #include "libmondo-stream-EXT.h"
|
---|
| 31 | #include "libmondo-devices-EXT.h"
|
---|
| 32 | #include "libmondo-tools-EXT.h"
|
---|
[1118] | 33 | #include "newt-specific-EXT.h"
|
---|
[1] | 34 | #include "libmondo-fork-EXT.h"
|
---|
| 35 | #include "libmondo-files-EXT.h"
|
---|
| 36 | #include "libmondo-filelist-EXT.h"
|
---|
| 37 | #include "libmondo-tools-EXT.h"
|
---|
| 38 | #include "libmondo-verify-EXT.h"
|
---|
| 39 | #include "libmondo-archive.h"
|
---|
[1063] | 40 |
|
---|
[1] | 41 | #define DVDRWFORMAT 1
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 |
|
---|
| 45 | /** @def DEFAULT_1722MB_DISK The default 1.722M floppy disk to write images to. */
|
---|
| 46 | /** @def BACKUP_1722MB_DISK The 1.722M floppy disk to try if the default fails. */
|
---|
| 47 |
|
---|
| 48 | #ifdef __FreeBSD__
|
---|
[128] | 49 | #define DEFAULT_1722MB_DISK "/dev/fd0.1722"
|
---|
| 50 | #define BACKUP_1722MB_DISK "/dev/fd0.1722"
|
---|
[1] | 51 | #else
|
---|
[128] | 52 | #define DEFAULT_1722MB_DISK "/dev/fd0u1722"
|
---|
| 53 | #define BACKUP_1722MB_DISK "/dev/fd0H1722"
|
---|
[1] | 54 | #ifndef _SEMUN_H
|
---|
[128] | 55 | #define _SEMUN_H
|
---|
[1] | 56 |
|
---|
| 57 | /**
|
---|
| 58 | * The semaphore union, provided only in case the user's system doesn't.
|
---|
| 59 | */
|
---|
[128] | 60 | union semun {
|
---|
| 61 | int val;
|
---|
| 62 | struct semid_ds *buf;
|
---|
| 63 | unsigned short int *array;
|
---|
| 64 | struct seminfo *__buf;
|
---|
| 65 | };
|
---|
[1] | 66 | #endif
|
---|
[128] | 67 | #endif /* __FreeBSD__ */
|
---|
[1] | 68 |
|
---|
| 69 | /*@unused@*/
|
---|
[99] | 70 | //static char cvsid[] = "$Id: libmondo-archive.c 1256 2007-03-21 11:48:32Z bruno $";
|
---|
[1] | 71 |
|
---|
| 72 | /* *************************** external global vars ******************/
|
---|
| 73 | extern int g_current_media_number;
|
---|
| 74 | extern int g_currentY;
|
---|
| 75 | extern bool g_text_mode;
|
---|
| 76 | extern bool g_exiting;
|
---|
| 77 | extern long g_current_progress;
|
---|
[128] | 78 | extern FILE *g_tape_stream;
|
---|
[1] | 79 | extern long long g_tape_posK;
|
---|
| 80 | extern char *g_tmpfs_mountpt;
|
---|
| 81 | extern bool g_cd_recovery;
|
---|
| 82 | extern char *g_serial_string;
|
---|
| 83 |
|
---|
[948] | 84 | extern char *g_getfacl;
|
---|
| 85 | extern char *g_getfattr;
|
---|
| 86 |
|
---|
| 87 |
|
---|
| 88 |
|
---|
[1] | 89 | /**
|
---|
| 90 | * @addtogroup globalGroup
|
---|
| 91 | * @{
|
---|
| 92 | */
|
---|
| 93 | /**
|
---|
| 94 | * The current backup media type in use.
|
---|
| 95 | */
|
---|
[128] | 96 | t_bkptype g_backup_media_type = none;
|
---|
[1107] | 97 | char *g_backup_media_string = NULL;
|
---|
[1] | 98 |
|
---|
| 99 | /**
|
---|
| 100 | * Incremented by each archival thread when it starts up. After that,
|
---|
| 101 | * this is the number of threads running.
|
---|
| 102 | */
|
---|
| 103 | int g_current_thread_no = 0;
|
---|
| 104 |
|
---|
| 105 | /* @} - end of globalGroup */
|
---|
| 106 |
|
---|
| 107 | extern int g_noof_rows;
|
---|
| 108 |
|
---|
| 109 | /* Semaphore-related code */
|
---|
| 110 |
|
---|
| 111 | static int set_semvalue(void);
|
---|
| 112 | static void del_semvalue(void);
|
---|
| 113 | static int semaphore_p(void);
|
---|
| 114 | static int semaphore_v(void);
|
---|
| 115 |
|
---|
| 116 | static int g_sem_id;
|
---|
| 117 | static int g_sem_key;
|
---|
| 118 |
|
---|
| 119 |
|
---|
| 120 |
|
---|
| 121 |
|
---|
| 122 | /**
|
---|
| 123 | * Initialize the semaphore.
|
---|
| 124 | * @see del_semvalue
|
---|
| 125 | * @see semaphore_p
|
---|
| 126 | * @see semaphore_v
|
---|
| 127 | * @return 1 for success, 0 for failure.
|
---|
| 128 | */
|
---|
[128] | 129 | static int set_semvalue(void) // initializes semaphore
|
---|
[1] | 130 | {
|
---|
[128] | 131 | union semun sem_union;
|
---|
| 132 | sem_union.val = 1;
|
---|
| 133 | if (semctl(g_sem_id, 0, SETVAL, sem_union) == -1) {
|
---|
| 134 | return (0);
|
---|
| 135 | }
|
---|
| 136 | return (1);
|
---|
[1] | 137 | }
|
---|
| 138 |
|
---|
| 139 | /**
|
---|
| 140 | * Frees (deletes) the semaphore. Failure is indicated by a log
|
---|
| 141 | * message.
|
---|
| 142 | * @see set_semvalue
|
---|
| 143 | */
|
---|
[128] | 144 | static void del_semvalue(void) // deletes semaphore
|
---|
[1] | 145 | {
|
---|
[128] | 146 | union semun sem_union;
|
---|
[1] | 147 |
|
---|
[128] | 148 | if (semctl(g_sem_id, 0, IPC_RMID, sem_union) == -1) {
|
---|
[1107] | 149 | mr_msg(3, "Failed to delete semaphore");
|
---|
[128] | 150 | }
|
---|
[1] | 151 | }
|
---|
| 152 |
|
---|
| 153 | /**
|
---|
| 154 | * Acquire (increment) the semaphore (change status to P).
|
---|
| 155 | * @return 1 for success, 0 for failure.
|
---|
| 156 | * @see semaphore_v
|
---|
| 157 | */
|
---|
[128] | 158 | static int semaphore_p(void) // changes status to 'P' (waiting)
|
---|
[1] | 159 | {
|
---|
[128] | 160 | struct sembuf sem_b;
|
---|
[1] | 161 |
|
---|
[128] | 162 | sem_b.sem_num = 0;
|
---|
| 163 | sem_b.sem_op = -1; // P()
|
---|
| 164 | sem_b.sem_flg = SEM_UNDO;
|
---|
| 165 | if (semop(g_sem_id, &sem_b, 1) == -1) {
|
---|
[1107] | 166 | mr_msg(3, "semaphore_p failed");
|
---|
[128] | 167 | return (0);
|
---|
| 168 | }
|
---|
| 169 | return (1);
|
---|
[1] | 170 | }
|
---|
| 171 |
|
---|
| 172 | /**
|
---|
| 173 | * Free (decrement) the semaphore (change status to V).
|
---|
| 174 | * @return 1 for success, 0 for failure.
|
---|
| 175 | */
|
---|
[128] | 176 | static int semaphore_v(void) // changes status to 'V' (free)
|
---|
[1] | 177 | {
|
---|
[128] | 178 | struct sembuf sem_b;
|
---|
[1] | 179 |
|
---|
[128] | 180 | sem_b.sem_num = 0;
|
---|
| 181 | sem_b.sem_op = 1; // V()
|
---|
| 182 | sem_b.sem_flg = SEM_UNDO;
|
---|
| 183 | if (semop(g_sem_id, &sem_b, 1) == -1) {
|
---|
[1107] | 184 | mr_msg(3, "semaphore_v failed");
|
---|
[128] | 185 | return (0);
|
---|
| 186 | }
|
---|
| 187 | return (1);
|
---|
[1] | 188 | }
|
---|
| 189 |
|
---|
| 190 |
|
---|
| 191 | //------------------------------------------------------
|
---|
| 192 |
|
---|
| 193 |
|
---|
| 194 | /**
|
---|
| 195 | * Size in megabytes of the buffer afforded to the executable "buffer".
|
---|
| 196 | * This figure is used when we calculate how much data we have probably 'lost'
|
---|
| 197 | * when writing off the end of tape N, so that we can then figure out how much
|
---|
| 198 | * data we must recreate & write to the start of tape N+1.
|
---|
| 199 | */
|
---|
| 200 | extern int g_tape_buffer_size_MB;
|
---|
| 201 |
|
---|
| 202 |
|
---|
| 203 |
|
---|
| 204 |
|
---|
| 205 | int
|
---|
[128] | 206 | archive_this_fileset_with_star(struct s_bkpinfo *bkpinfo, char *filelist,
|
---|
| 207 | char *fname, int setno)
|
---|
[1] | 208 | {
|
---|
[128] | 209 | int retval = 0;
|
---|
| 210 | unsigned int res = 0;
|
---|
| 211 | int tries = 0;
|
---|
[1118] | 212 | char *command = NULL;
|
---|
| 213 | char *tmp = NULL;
|
---|
| 214 | char *p =NULL;
|
---|
| 215 | char *tmp1 = NULL;
|
---|
[1] | 216 |
|
---|
[1118] | 217 | malloc_string(tmp1);
|
---|
[1] | 218 |
|
---|
[128] | 219 | if (!does_file_exist(filelist)) {
|
---|
[1118] | 220 | mr_asprintf(&tmp,
|
---|
| 221 | "(archive_this_fileset) - filelist %s does not exist",
|
---|
| 222 | filelist);
|
---|
[128] | 223 | log_to_screen(tmp);
|
---|
[1118] | 224 | mr_free(tmp);
|
---|
[128] | 225 | return (1);
|
---|
[1] | 226 | }
|
---|
| 227 |
|
---|
[1118] | 228 | mr_asprintf(&tmp, "echo hi > %s 2> /dev/null", fname);
|
---|
[128] | 229 | if (system(tmp)) {
|
---|
| 230 | fatal_error("Unable to write tarball to scratchdir");
|
---|
| 231 | }
|
---|
[1118] | 232 | mr_free(tmp);
|
---|
[128] | 233 |
|
---|
[1118] | 234 | mr_asprintf(&command, "star H=star list=%s -c " STAR_ACL_SZ " file=%s",
|
---|
| 235 | filelist, fname);
|
---|
[128] | 236 | if (bkpinfo->use_lzo) {
|
---|
| 237 | fatal_error("Can't use lzop");
|
---|
| 238 | }
|
---|
| 239 | if (bkpinfo->compression_level > 0) {
|
---|
[1118] | 240 | mr_asprintf(&tmp, "%s -bz", command);
|
---|
| 241 | mr_free(command);
|
---|
| 242 | command = tmp;
|
---|
[128] | 243 | }
|
---|
[1118] | 244 | mr_asprintf(&tmp, "%s 2>> %s", command, MONDO_LOGFILE);
|
---|
| 245 | mr_free(command);
|
---|
| 246 | command = tmp;
|
---|
[1107] | 247 | mr_msg(4, "command = '%s'", command);
|
---|
[128] | 248 |
|
---|
| 249 | for (res = 99, tries = 0; tries < 3 && res != 0; tries++) {
|
---|
[1107] | 250 | mr_msg(5, "command='%s'", command);
|
---|
[128] | 251 | res = system(command);
|
---|
[1118] | 252 | strcpy(tmp1, last_line_of_file(MONDO_LOGFILE));
|
---|
[1107] | 253 | mr_msg(1, "res=%d; tmp='%s'", res, tmp);
|
---|
[128] | 254 | if (bkpinfo->use_star && (res == 254 || res == 65024)
|
---|
| 255 | && strstr(tmp, "star: Processed all possible files")
|
---|
| 256 | && tries > 0) {
|
---|
[1107] | 257 | mr_msg(1, "Star returned nonfatal error");
|
---|
[128] | 258 | res = 0;
|
---|
| 259 | }
|
---|
| 260 | if (res) {
|
---|
| 261 | log_OS_error(command);
|
---|
| 262 | p = strstr(command, "-acl ");
|
---|
| 263 | if (p) {
|
---|
| 264 | p[0] = p[1] = p[2] = p[3] = ' ';
|
---|
[1107] | 265 | mr_msg(1, "new command = '%s'", command);
|
---|
[128] | 266 | } else {
|
---|
[1107] | 267 | mr_msg(3,
|
---|
[128] | 268 | "Attempt #%d failed. Pausing 3 seconds and retrying...",
|
---|
| 269 | tries + 1);
|
---|
| 270 | sleep(3);
|
---|
| 271 | }
|
---|
| 272 | }
|
---|
| 273 | }
|
---|
[1118] | 274 | mr_free(command);
|
---|
| 275 |
|
---|
[128] | 276 | retval += res;
|
---|
| 277 | if (retval) {
|
---|
[1107] | 278 | mr_msg(3, "Failed to write set %d", setno);
|
---|
[128] | 279 | } else if (tries > 1) {
|
---|
[1107] | 280 | mr_msg(3, "Succeeded in writing set %d, on try #%d", setno,
|
---|
[128] | 281 | tries);
|
---|
| 282 | }
|
---|
| 283 |
|
---|
| 284 | return (retval);
|
---|
[1] | 285 | }
|
---|
| 286 |
|
---|
| 287 |
|
---|
| 288 | /**
|
---|
| 289 | * Call @c afio to archive the filelist @c filelist to the file @c fname.
|
---|
| 290 | *
|
---|
| 291 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 292 | * - @c compression_level
|
---|
| 293 | * - @c scratchdir (only verifies existence)
|
---|
| 294 | * - @c tmpdir (only verifies existence)
|
---|
| 295 | * - @c zip_exe
|
---|
| 296 | * - @c zip_suffix
|
---|
| 297 | * @param filelist The path to a file containing a list of files to be archived
|
---|
| 298 | * in this fileset.
|
---|
| 299 | * @param fname The output file to archive to.
|
---|
| 300 | * @param setno This fileset number.
|
---|
| 301 | * @return The number of errors encountered (0 for success).
|
---|
| 302 | * @ingroup LLarchiveGroup
|
---|
| 303 | */
|
---|
| 304 | int
|
---|
[128] | 305 | archive_this_fileset(struct s_bkpinfo *bkpinfo, char *filelist,
|
---|
| 306 | char *fname, int setno)
|
---|
[1] | 307 | {
|
---|
| 308 |
|
---|
[1118] | 309 | /*@ int ************************************************************ */
|
---|
[128] | 310 | int retval = 0;
|
---|
| 311 | int res = 0;
|
---|
| 312 | int i = 0;
|
---|
| 313 | int tries = 0;
|
---|
| 314 | static int free_ramdisk_space = 9999;
|
---|
[1] | 315 |
|
---|
[1118] | 316 | /*@ buffers ******************************************************** */
|
---|
| 317 | char *command = NULL;
|
---|
| 318 | char *zipparams = NULL;
|
---|
| 319 | char *tmp = NULL;
|
---|
| 320 | char *tmp1 = NULL;
|
---|
[1] | 321 |
|
---|
[128] | 322 | assert(bkpinfo != NULL);
|
---|
| 323 | assert_string_is_neither_NULL_nor_zerolength(filelist);
|
---|
| 324 | assert_string_is_neither_NULL_nor_zerolength(fname);
|
---|
[1] | 325 |
|
---|
[128] | 326 | if (bkpinfo->compression_level > 0 && bkpinfo->use_star) {
|
---|
| 327 | return (archive_this_fileset_with_star
|
---|
| 328 | (bkpinfo, filelist, fname, setno));
|
---|
| 329 | }
|
---|
[1] | 330 |
|
---|
[128] | 331 | if (!does_file_exist(filelist)) {
|
---|
[1118] | 332 | mr_asprintf(&tmp,
|
---|
| 333 | "(archive_this_fileset) - filelist %s does not exist",
|
---|
| 334 | filelist);
|
---|
[128] | 335 | log_to_screen(tmp);
|
---|
[1118] | 336 | mr_free(tmp);
|
---|
[128] | 337 | return (1);
|
---|
| 338 | }
|
---|
[1118] | 339 | mr_asprintf(&tmp, "echo hi > %s 2> /dev/null", fname);
|
---|
[128] | 340 | if (system(tmp)) {
|
---|
| 341 | fatal_error("Unable to write tarball to scratchdir");
|
---|
| 342 | }
|
---|
[1118] | 343 | mr_free(tmp);
|
---|
[128] | 344 |
|
---|
| 345 |
|
---|
| 346 | if (bkpinfo->compression_level > 0) {
|
---|
[1118] | 347 | mr_asprintf(&zipparams, "-Z -P %s -G %d -T 3k", bkpinfo->zip_exe,
|
---|
| 348 | bkpinfo->compression_level);
|
---|
[1213] | 349 | mr_asprintf(&tmp, "%s/do-not-compress-these", MONDO_SHARE);
|
---|
[128] | 350 | if (does_file_exist(tmp)) {
|
---|
[1186] | 351 | mr_asprintf(&tmp1, " -E +%s", tmp);
|
---|
| 352 | mr_strcat(zipparams, tmp1);
|
---|
| 353 | mr_free(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 |
|
---|
[1158] | 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);
|
---|
[1087] | 803 |
|
---|
[128] | 804 | switch (bkpinfo->backup_media_type) {
|
---|
| 805 | case cdr:
|
---|
[1158] | 806 | mr_fprintf(fd1, "backup-media-type=cdr\n");
|
---|
[128] | 807 | break;
|
---|
| 808 | case cdrw:
|
---|
[1158] | 809 | mr_fprintf(fd1, "backup-media-type=cdrw\n");
|
---|
[128] | 810 | break;
|
---|
| 811 | case cdstream:
|
---|
[1158] | 812 | mr_fprintf(fd1, "backup-media-type=cdstream\n");
|
---|
[128] | 813 | break;
|
---|
| 814 | case tape:
|
---|
[1158] | 815 | mr_fprintf(fd1, "backup-media-type=tape\n");
|
---|
[128] | 816 | break;
|
---|
| 817 | case udev:
|
---|
[1158] | 818 | mr_fprintf(fd1, "backup-media-type=udev\n");
|
---|
[128] | 819 | break;
|
---|
| 820 | case iso:
|
---|
[1158] | 821 | mr_fprintf(fd1, "backup-media-type=iso\n");
|
---|
[128] | 822 | break;
|
---|
| 823 | case nfs:
|
---|
[1158] | 824 | mr_fprintf(fd1, "backup-media-type=nfs\n");
|
---|
[128] | 825 | break;
|
---|
| 826 | case dvd:
|
---|
[1158] | 827 | mr_fprintf(fd1, "backup-media-type=dvd\n");
|
---|
[128] | 828 | break;
|
---|
[1063] | 829 | case usb:
|
---|
[1158] | 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);
|
---|
[1158] | 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) {
|
---|
[1158] | 847 | mr_fprintf(fd1, "use-comp=yes\n");
|
---|
[128] | 848 | } else {
|
---|
[1158] | 849 | mr_fprintf(fd1, "use-comp=no\n");
|
---|
[128] | 850 | }
|
---|
[1087] | 851 | if (bkpinfo->use_gzip) {
|
---|
[1158] | 852 | mr_fprintf(fd1, "use-gzip=yes\n");
|
---|
[1087] | 853 | } else {
|
---|
[1158] | 854 | mr_fprintf(fd1, "use-gzip=no\n");
|
---|
[1087] | 855 | }
|
---|
| 856 | if (bkpinfo->use_lzo) {
|
---|
[1158] | 857 | mr_fprintf(fd1, "use-lzo=yes\n");
|
---|
[1087] | 858 | } else {
|
---|
[1158] | 859 | mr_fprintf(fd1, "use-lzo=no\n");
|
---|
[1087] | 860 | }
|
---|
| 861 | if (bkpinfo->use_star) {
|
---|
[1158] | 862 | mr_fprintf(fd1, "use-star=yes\n");
|
---|
[1087] | 863 | } else {
|
---|
[1158] | 864 | mr_fprintf(fd1, "use-star=no\n");
|
---|
[1087] | 865 | }
|
---|
[949] | 866 | if (g_getfattr) {
|
---|
[1158] | 867 | mr_fprintf(fd1, "xattr=yes\n");
|
---|
[1087] | 868 | } else {
|
---|
[1158] | 869 | mr_fprintf(fd1, "xattr=no\n");
|
---|
[949] | 870 | }
|
---|
| 871 | if (g_getfacl) {
|
---|
[1158] | 872 | mr_fprintf(fd1, "acl=yes\n");
|
---|
[1087] | 873 | } else {
|
---|
[1158] | 874 | mr_fprintf(fd1, "acl=no\n");
|
---|
[949] | 875 | }
|
---|
| 876 |
|
---|
[1087] | 877 | if (g_cd_recovery) {
|
---|
[1158] | 878 | mr_fprintf(fd1, "use-cdrecovery=yes\n");
|
---|
[1087] | 879 | } else {
|
---|
[1158] | 880 | mr_fprintf(fd1, "use-cdrecovery=no\n");
|
---|
[128] | 881 | }
|
---|
[1118] | 882 |
|
---|
[1087] | 883 | if (bkpinfo->make_cd_use_lilo) {
|
---|
[1158] | 884 | mr_fprintf(fd1, "use-lilo=yes\n");
|
---|
[1087] | 885 | } else {
|
---|
[1158] | 886 | mr_fprintf(fd1, "use-lilo=no\n");
|
---|
[128] | 887 | }
|
---|
[1087] | 888 | if (bkpinfo->nonbootable_backup) {
|
---|
[1158] | 889 | mr_fprintf(fd1, "non-bootable=yes\n");
|
---|
[1063] | 890 | } else {
|
---|
[1158] | 891 | mr_fprintf(fd1, "non-bootable=no\n");
|
---|
[1063] | 892 | }
|
---|
[1087] | 893 | if (bkpinfo->differential) {
|
---|
[1158] | 894 | mr_fprintf(fd1, "differential=1\n");
|
---|
[1087] | 895 | } else {
|
---|
[1158] | 896 | mr_fprintf(fd1, "differential=0\n");
|
---|
[1087] | 897 | }
|
---|
[1063] | 898 |
|
---|
[1087] | 899 | mr_fclose(fd);
|
---|
[1158] | 900 | mr_fprintf(fd1, "datestamp=%s\n", mr_date());
|
---|
[1087] | 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 *********************************** */
|
---|
[1164] | 1235 | char *command, *tmp_file, *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"));
|
---|
[1168] | 1246 | mr_strip_spaces(g_serial_string);
|
---|
[128] | 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 |
|
---|
[1164] | 1251 | mr_asprintf(&tmp_file, "%s/archives/SERIAL-STRING", bkpinfo->scratchdir);
|
---|
| 1252 | if (write_one_liner_data_file(tmp_file, g_serial_string)) {
|
---|
[1107] | 1253 | mr_msg(1, "%ld: Failed to write serial string", __LINE__);
|
---|
[128] | 1254 | }
|
---|
[1164] | 1255 | mr_free(tmp_file);
|
---|
[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");
|
---|
[1118] | 1525 | open_progress_form(_("Backing up filesystem"),
|
---|
| 1526 | _("I am backing up your live filesystem now."),
|
---|
| 1527 | _("Please wait. This may take a couple of hours."),
|
---|
| 1528 | _("Working..."),
|
---|
[128] | 1529 | get_last_filelist_number(bkpinfo) + 1);
|
---|
[1] | 1530 |
|
---|
[128] | 1531 | srand((unsigned int) getpid());
|
---|
| 1532 | g_sem_key = 1234 + random() % 30000;
|
---|
| 1533 | if ((g_sem_id =
|
---|
| 1534 | semget((key_t) g_sem_key, 1,
|
---|
| 1535 | IPC_CREAT | S_IREAD | S_IWRITE)) == -1) {
|
---|
| 1536 | fatal_error("MABAI - unable to semget");
|
---|
[1] | 1537 | }
|
---|
[128] | 1538 | if (!set_semvalue()) {
|
---|
| 1539 | fatal_error("Unable to init semaphore");
|
---|
| 1540 | } // initialize semaphore
|
---|
| 1541 | for (noof_threads = 0; noof_threads < ARCH_THREADS; noof_threads++) {
|
---|
[1107] | 1542 | mr_msg(8, "Creating thread #%d", noof_threads);
|
---|
[128] | 1543 | (*p_archival_threads_running)++;
|
---|
| 1544 | if ((res =
|
---|
| 1545 | pthread_create(&archival_thread[noof_threads], NULL,
|
---|
| 1546 | create_afio_files_in_background,
|
---|
| 1547 | (void *) transfer_block))) {
|
---|
| 1548 | fatal_error("Unable to create an archival thread");
|
---|
| 1549 | }
|
---|
[1] | 1550 | }
|
---|
| 1551 |
|
---|
[1107] | 1552 | mr_msg(8, "About to enter while() loop");
|
---|
[128] | 1553 | while (!done_storing) {
|
---|
| 1554 | if (g_exiting) {
|
---|
| 1555 | fatal_error("Execution run aborted (main loop)");
|
---|
| 1556 | }
|
---|
| 1557 | if (*p_archival_threads_running == 0
|
---|
| 1558 | && *p_last_set_archived == storing_set_no - 1) {
|
---|
[1107] | 1559 | mr_msg(2,
|
---|
[128] | 1560 | "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... :-)",
|
---|
| 1561 | *p_last_set_archived, storing_set_no);
|
---|
| 1562 | done_storing = TRUE;
|
---|
| 1563 | } else
|
---|
| 1564 | if (!get_bit_N_of_array
|
---|
| 1565 | (p_list_of_fileset_flags, storing_set_no)) {
|
---|
| 1566 | misc_counter_that_is_not_important =
|
---|
| 1567 | (misc_counter_that_is_not_important + 1) % 5;
|
---|
| 1568 | if (!misc_counter_that_is_not_important) {
|
---|
| 1569 | update_progress_form(media_usage_comment);
|
---|
| 1570 | }
|
---|
| 1571 | sleep(1);
|
---|
[1118] | 1572 | } else {
|
---|
[128] | 1573 | // store set N
|
---|
| 1574 | sprintf(storing_filelist_fname, FILELIST_FNAME_RAW_SZ,
|
---|
| 1575 | bkpinfo->tmpdir, storing_set_no);
|
---|
| 1576 | sprintf(storing_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
|
---|
| 1577 | bkpinfo->tmpdir, storing_set_no, bkpinfo->zip_suffix);
|
---|
[948] | 1578 | if (g_getfattr) {
|
---|
| 1579 | sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
|
---|
[128] | 1580 | bkpinfo->tmpdir, storing_set_no);
|
---|
[948] | 1581 | }
|
---|
| 1582 | if (g_getfacl) {
|
---|
| 1583 | sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
|
---|
[128] | 1584 | bkpinfo->tmpdir, storing_set_no);
|
---|
[948] | 1585 | }
|
---|
[128] | 1586 |
|
---|
[1107] | 1587 | mr_msg(2, "Storing set %d", storing_set_no);
|
---|
[128] | 1588 | while (!does_file_exist(storing_filelist_fname)
|
---|
| 1589 | || !does_file_exist(storing_afioball_fname)) {
|
---|
[1107] | 1590 | mr_msg(2,
|
---|
[128] | 1591 | "Warning - either %s or %s doesn't exist yet. I'll pause 5 secs.",
|
---|
| 1592 | storing_filelist_fname, storing_afioball_fname);
|
---|
| 1593 | sleep(5);
|
---|
| 1594 | }
|
---|
| 1595 | strcpy(media_usage_comment,
|
---|
| 1596 | percent_media_full_comment(bkpinfo));
|
---|
| 1597 | /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
|
---|
| 1598 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 1599 | register_in_tape_catalog(fileset, storing_set_no, -1,
|
---|
| 1600 | storing_afioball_fname);
|
---|
| 1601 | maintain_collection_of_recent_archives(bkpinfo->tmpdir,
|
---|
| 1602 | storing_afioball_fname);
|
---|
| 1603 | iamhere("Writing EXAT files");
|
---|
[1118] | 1604 | res += write_EXAT_files_to_tape(bkpinfo,
|
---|
| 1605 | curr_xattr_list_fname,
|
---|
| 1606 | curr_acl_list_fname);
|
---|
| 1607 | // archives themselves
|
---|
[128] | 1608 | res +=
|
---|
| 1609 | move_files_to_stream(bkpinfo, storing_afioball_fname,
|
---|
| 1610 | NULL);
|
---|
| 1611 | } else {
|
---|
[948] | 1612 | if (g_getfacl) {
|
---|
| 1613 | if (g_getfattr) {
|
---|
| 1614 | res = move_files_to_cd(bkpinfo, storing_filelist_fname,
|
---|
[128] | 1615 | curr_xattr_list_fname,
|
---|
| 1616 | curr_acl_list_fname,
|
---|
| 1617 | storing_afioball_fname, NULL);
|
---|
[948] | 1618 | } else {
|
---|
| 1619 | res = move_files_to_cd(bkpinfo, storing_filelist_fname,
|
---|
| 1620 | curr_acl_list_fname,
|
---|
| 1621 | storing_afioball_fname, NULL);
|
---|
| 1622 | }
|
---|
| 1623 | } else {
|
---|
| 1624 | if (g_getfattr) {
|
---|
| 1625 | res = move_files_to_cd(bkpinfo, storing_filelist_fname,
|
---|
| 1626 | curr_xattr_list_fname,
|
---|
| 1627 | storing_afioball_fname, NULL);
|
---|
| 1628 | } else {
|
---|
| 1629 | res = move_files_to_cd(bkpinfo, storing_filelist_fname,
|
---|
| 1630 | storing_afioball_fname, NULL);
|
---|
| 1631 | }
|
---|
| 1632 | }
|
---|
[128] | 1633 | }
|
---|
| 1634 | retval += res;
|
---|
| 1635 | g_current_progress++;
|
---|
| 1636 | update_progress_form(media_usage_comment);
|
---|
| 1637 | if (res) {
|
---|
[1135] | 1638 | mr_asprintf(&tmp,
|
---|
| 1639 | "Failed to add archive %ld's files to CD dir\n",
|
---|
| 1640 | storing_set_no);
|
---|
[128] | 1641 | log_to_screen(tmp);
|
---|
[1135] | 1642 | mr_free(tmp);
|
---|
[128] | 1643 | fatal_error
|
---|
| 1644 | ("Is your hard disk full? If not, please send the author the logfile.");
|
---|
| 1645 | }
|
---|
| 1646 | storing_set_no++;
|
---|
| 1647 | // sleep(2);
|
---|
[1] | 1648 | }
|
---|
| 1649 | }
|
---|
[128] | 1650 | close_progress_form();
|
---|
[1] | 1651 |
|
---|
[1107] | 1652 | mr_msg(2, "Joining background threads to foreground thread");
|
---|
[128] | 1653 | for (i = 0; i < noof_threads; i++) {
|
---|
| 1654 | pthread_join(archival_thread[i], pvp);
|
---|
[1107] | 1655 | mr_msg(3, "Thread %d of %d: closed OK", i + 1, noof_threads);
|
---|
[128] | 1656 | }
|
---|
| 1657 | del_semvalue();
|
---|
[1107] | 1658 | mr_msg(2, "Done.");
|
---|
[128] | 1659 | if (retval) {
|
---|
[1135] | 1660 | mr_asprintf(&tmp,
|
---|
| 1661 | "Your regular files have been archived (with errors).");
|
---|
[128] | 1662 | } else {
|
---|
[1135] | 1663 | mr_asprintf(&tmp,
|
---|
| 1664 | "Your regular files have been archived successfully");
|
---|
[128] | 1665 | }
|
---|
| 1666 | log_to_screen(tmp);
|
---|
[1135] | 1667 | mr_free(tmp);
|
---|
[1080] | 1668 | mr_free(transfer_block);
|
---|
| 1669 | mr_free(result_str);
|
---|
| 1670 | mr_free(storing_filelist_fname);
|
---|
| 1671 | mr_free(media_usage_comment);
|
---|
| 1672 | mr_free(storing_afioball_fname);
|
---|
| 1673 | mr_free(curr_xattr_list_fname);
|
---|
| 1674 | mr_free(curr_acl_list_fname);
|
---|
[128] | 1675 | return (retval);
|
---|
[1] | 1676 | }
|
---|
| 1677 |
|
---|
| 1678 |
|
---|
[128] | 1679 | void pause_for_N_seconds(int how_long, char *msg)
|
---|
[1] | 1680 | {
|
---|
[128] | 1681 | int i;
|
---|
| 1682 | open_evalcall_form(msg);
|
---|
| 1683 | for (i = 0; i < how_long; i++) {
|
---|
| 1684 | update_evalcall_form((int) ((100.0 / (float) (how_long) * i)));
|
---|
| 1685 | sleep(1);
|
---|
| 1686 | }
|
---|
| 1687 | close_evalcall_form();
|
---|
[1] | 1688 | }
|
---|
| 1689 |
|
---|
| 1690 |
|
---|
| 1691 | /**
|
---|
| 1692 | * Create an ISO image in @c destfile, from files in @c bkpinfo->scratchdir.
|
---|
| 1693 | *
|
---|
| 1694 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 1695 | * - @c backup_media_type
|
---|
| 1696 | * - @c call_after_iso
|
---|
| 1697 | * - @c call_before_iso
|
---|
| 1698 | * - @c call_burn_iso
|
---|
| 1699 | * - @c call_make_iso
|
---|
| 1700 | * - @c make_cd_use_lilo
|
---|
| 1701 | * - @c manual_cd_tray
|
---|
| 1702 | * - @c nonbootable_backup
|
---|
| 1703 | * - @c scratchdir
|
---|
| 1704 | *
|
---|
| 1705 | * @param destfile Where to put the generated ISO image.
|
---|
| 1706 | * @return The number of errors encountered (0 for success)
|
---|
| 1707 | */
|
---|
[541] | 1708 | int make_iso_fs(struct s_bkpinfo *bkpinfo, char *destfile)
|
---|
[1] | 1709 | {
|
---|
[128] | 1710 | /*@ int ********************************************** */
|
---|
| 1711 | int retval = 0;
|
---|
| 1712 | int res;
|
---|
[1] | 1713 |
|
---|
[128] | 1714 | /*@ buffers ****************************************** */
|
---|
[1138] | 1715 | char *tmp = NULL;
|
---|
[128] | 1716 | char *old_pwd;
|
---|
[1138] | 1717 | char *result_sz = NULL;
|
---|
| 1718 | char *message_to_screen = NULL;
|
---|
| 1719 | char *sz_blank_disk = NULL;
|
---|
[1137] | 1720 | char *tmp2 = NULL;
|
---|
| 1721 | char *tmp3 = NULL;
|
---|
[128] | 1722 | bool cd_is_mountable;
|
---|
[1] | 1723 |
|
---|
[128] | 1724 | malloc_string(old_pwd);
|
---|
| 1725 | assert(bkpinfo != NULL);
|
---|
| 1726 | assert_string_is_neither_NULL_nor_zerolength(destfile);
|
---|
[1] | 1727 |
|
---|
[1138] | 1728 | mr_asprintf(&tmp, "%s/isolinux.bin", bkpinfo->scratchdir);
|
---|
[1137] | 1729 | mr_asprintf(&tmp2, "%s/isolinux.bin", bkpinfo->tmpdir);
|
---|
[128] | 1730 | if (does_file_exist(tmp)) {
|
---|
[1137] | 1731 | mr_asprintf(&tmp3, "cp -f %s %s", tmp, tmp2);
|
---|
[128] | 1732 | paranoid_system(tmp3);
|
---|
[1137] | 1733 | mr_free(tmp3);
|
---|
[1] | 1734 | }
|
---|
[128] | 1735 | if (!does_file_exist(tmp) && does_file_exist(tmp2)) {
|
---|
[1137] | 1736 | mr_asprintf(&tmp3, "cp -f %s %s", tmp2, tmp);
|
---|
[128] | 1737 | paranoid_system(tmp3);
|
---|
[1137] | 1738 | mr_free(tmp3);
|
---|
[1] | 1739 | }
|
---|
[1080] | 1740 | mr_free(tmp2);
|
---|
[1138] | 1741 | mr_free(tmp);
|
---|
| 1742 |
|
---|
[128] | 1743 | if (bkpinfo->backup_media_type == iso && bkpinfo->manual_cd_tray) {
|
---|
[1136] | 1744 | popup_and_OK(_("Please insert new media and press Enter."));
|
---|
[128] | 1745 | }
|
---|
[1] | 1746 |
|
---|
[1107] | 1747 | mr_msg(2, "make_iso_fs --- scratchdir=%s --- destfile=%s",
|
---|
[128] | 1748 | bkpinfo->scratchdir, destfile);
|
---|
[1136] | 1749 | /* BERLIOS: Do not ignore getcwd result */
|
---|
[128] | 1750 | (void) getcwd(old_pwd, MAX_STR_LEN - 1);
|
---|
[1138] | 1751 | mr_asprintf(&tmp, "chmod 755 %s", bkpinfo->scratchdir);
|
---|
[128] | 1752 | run_program_and_log_output(tmp, FALSE);
|
---|
[1138] | 1753 | mr_free(tmp);
|
---|
[128] | 1754 | chdir(bkpinfo->scratchdir);
|
---|
[1] | 1755 |
|
---|
[128] | 1756 | if (bkpinfo->call_before_iso[0] != '\0') {
|
---|
[1138] | 1757 | mr_asprintf(&message_to_screen, "Running pre-ISO call for CD#%d",
|
---|
[128] | 1758 | g_current_media_number);
|
---|
[1138] | 1759 | res = eval_call_to_make_ISO(bkpinfo, bkpinfo->call_before_iso,
|
---|
| 1760 | destfile, g_current_media_number,
|
---|
| 1761 | MONDO_LOGFILE, message_to_screen);
|
---|
[128] | 1762 | if (res) {
|
---|
[1138] | 1763 | log_to_screen("%s...failed", message_to_screen);
|
---|
[128] | 1764 | } else {
|
---|
[1138] | 1765 | log_to_screen("%s...OK", message_to_screen);
|
---|
[128] | 1766 | }
|
---|
[1138] | 1767 | mr_free(message_to_screen);
|
---|
[128] | 1768 | retval += res;
|
---|
[1] | 1769 | }
|
---|
| 1770 |
|
---|
[128] | 1771 | if (bkpinfo->call_make_iso[0] != '\0') {
|
---|
[1107] | 1772 | mr_msg(2, "bkpinfo->call_make_iso = %s", bkpinfo->call_make_iso);
|
---|
[1138] | 1773 | mr_asprintf(&message_to_screen, "Making an ISO (%s #%d)",
|
---|
| 1774 | bkpinfo->backup_media_string,
|
---|
| 1775 | g_current_media_number);
|
---|
[1] | 1776 |
|
---|
[1138] | 1777 | /* if g_current_media_number >= 2 then pause & ask */
|
---|
| 1778 | pause_and_ask_for_cdr(2, &cd_is_mountable);
|
---|
[128] | 1779 | if (retval) {
|
---|
| 1780 | log_to_screen
|
---|
| 1781 | ("Serious error(s) occurred already. I shan't try to write to media.");
|
---|
| 1782 | } else {
|
---|
[1138] | 1783 | res = eval_call_to_make_ISO(bkpinfo, bkpinfo->call_make_iso,
|
---|
| 1784 | bkpinfo->scratchdir,
|
---|
| 1785 | g_current_media_number,
|
---|
| 1786 | MONDO_LOGFILE, message_to_screen);
|
---|
[128] | 1787 | if (res) {
|
---|
| 1788 | log_to_screen("%s...failed to write", message_to_screen);
|
---|
| 1789 | } else {
|
---|
| 1790 | log_to_screen("%s...OK", message_to_screen);
|
---|
| 1791 | if (!run_program_and_log_output
|
---|
[681] | 1792 | ("tail -n10 /var/log/mondo-archive.log | grep -F ':-('",
|
---|
[128] | 1793 | 1)) {
|
---|
| 1794 | log_to_screen
|
---|
| 1795 | ("Despite nonfatal errors, growisofs confirms the write was successful.");
|
---|
| 1796 | }
|
---|
| 1797 | }
|
---|
| 1798 | retval += res;
|
---|
[1] | 1799 | #ifdef DVDRWFORMAT
|
---|
[1138] | 1800 | mr_asprintf(&tmp,
|
---|
| 1801 | "tail -n8 %s | grep 'blank=full.*dvd-compat.*DAO'",
|
---|
| 1802 | MONDO_LOGFILE);
|
---|
[128] | 1803 | if (g_backup_media_type == dvd
|
---|
| 1804 | && (res || !run_program_and_log_output(tmp, 1))) {
|
---|
| 1805 | log_to_screen
|
---|
| 1806 | ("Failed to write to disk. I shall blank it and then try again.");
|
---|
| 1807 | sleep(5);
|
---|
[1136] | 1808 | sync();
|
---|
[128] | 1809 | pause_for_N_seconds(5, "Letting DVD drive settle");
|
---|
[1] | 1810 |
|
---|
[1136] | 1811 | // dvd+rw-format --- OPTION 2
|
---|
[128] | 1812 | if (!bkpinfo->please_dont_eject) {
|
---|
| 1813 | log_to_screen("Ejecting media to clear drive status.");
|
---|
| 1814 | eject_device(bkpinfo->media_device);
|
---|
| 1815 | inject_device(bkpinfo->media_device);
|
---|
| 1816 | }
|
---|
| 1817 | pause_for_N_seconds(5, "Letting DVD drive settle");
|
---|
[1138] | 1818 | mr_asprintf(&sz_blank_disk, "dvd+rw-format -force %s",
|
---|
| 1819 | bkpinfo->media_device);
|
---|
[1107] | 1820 | mr_msg(3, "sz_blank_disk = '%s'", sz_blank_disk);
|
---|
[1138] | 1821 | res = run_external_binary_with_percentage_indicator_NEW
|
---|
[128] | 1822 | ("Blanking DVD disk", sz_blank_disk);
|
---|
| 1823 | if (res) {
|
---|
| 1824 | log_to_screen
|
---|
| 1825 | ("Warning - format failed. (Was it a DVD-R?) Sleeping for 5 seconds to take a breath...");
|
---|
| 1826 | pause_for_N_seconds(5,
|
---|
| 1827 | "Letting DVD drive settle... and trying again.");
|
---|
[1138] | 1828 | res = run_external_binary_with_percentage_indicator_NEW
|
---|
[128] | 1829 | ("Blanking DVD disk", sz_blank_disk);
|
---|
| 1830 | if (res) {
|
---|
| 1831 | log_to_screen("Format failed a second time.");
|
---|
| 1832 | }
|
---|
| 1833 | } else {
|
---|
| 1834 | log_to_screen
|
---|
| 1835 | ("Format succeeded. Sleeping for 5 seconds to take a breath...");
|
---|
| 1836 | }
|
---|
[1138] | 1837 | mr_free(sz_blank_disk);
|
---|
[128] | 1838 | pause_for_N_seconds(5, "Letting DVD drive settle");
|
---|
| 1839 | if (!bkpinfo->please_dont_eject) {
|
---|
| 1840 | log_to_screen("Ejecting media to clear drive status.");
|
---|
| 1841 | eject_device(bkpinfo->media_device);
|
---|
| 1842 | inject_device(bkpinfo->media_device);
|
---|
| 1843 | }
|
---|
| 1844 | pause_for_N_seconds(5, "Letting DVD drive settle");
|
---|
| 1845 | res =
|
---|
| 1846 | eval_call_to_make_ISO(bkpinfo, bkpinfo->call_make_iso,
|
---|
| 1847 | bkpinfo->scratchdir,
|
---|
| 1848 | g_current_media_number,
|
---|
| 1849 | MONDO_LOGFILE,
|
---|
| 1850 | message_to_screen);
|
---|
| 1851 | retval += res;
|
---|
| 1852 | if (!bkpinfo->please_dont_eject) {
|
---|
| 1853 | log_to_screen("Ejecting media.");
|
---|
| 1854 | eject_device(bkpinfo->media_device);
|
---|
| 1855 | }
|
---|
| 1856 | if (res) {
|
---|
| 1857 | log_to_screen("Dagnabbit. It still failed.");
|
---|
| 1858 | } else {
|
---|
| 1859 | log_to_screen
|
---|
| 1860 | ("OK, this time I successfully backed up to DVD.");
|
---|
| 1861 | }
|
---|
| 1862 | }
|
---|
[1138] | 1863 | mr_free(tmp);
|
---|
[128] | 1864 | #endif
|
---|
| 1865 | if (g_backup_media_type == dvd && !bkpinfo->please_dont_eject) {
|
---|
| 1866 | eject_device(bkpinfo->media_device);
|
---|
| 1867 | }
|
---|
[1] | 1868 | }
|
---|
[1138] | 1869 | mr_free(message_to_screen);
|
---|
[128] | 1870 | } else {
|
---|
[1138] | 1871 | mr_asprintf(&message_to_screen, "Running mkisofs to make %s #%d",
|
---|
| 1872 | bkpinfo->backup_media_string,
|
---|
| 1873 | g_current_media_number);
|
---|
[1107] | 1874 | mr_msg(1, message_to_screen);
|
---|
[1139] | 1875 | mr_asprintf(&result_sz, "Call to mkisofs to make ISO (%s #%d) ",
|
---|
| 1876 | bkpinfo->backup_media_string,
|
---|
| 1877 | g_current_media_number);
|
---|
[128] | 1878 | if (bkpinfo->nonbootable_backup) {
|
---|
[1107] | 1879 | mr_msg(1, "Making nonbootable backup");
|
---|
[1139] | 1880 | res = eval_call_to_make_ISO(bkpinfo,
|
---|
| 1881 | "mkisofs -o '_ISO_' -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
|
---|
| 1882 | destfile, g_current_media_number,
|
---|
| 1883 | MONDO_LOGFILE, message_to_screen);
|
---|
[128] | 1884 | } else {
|
---|
[1107] | 1885 | mr_msg(1, "Making bootable backup");
|
---|
[1] | 1886 |
|
---|
| 1887 | #ifdef __FreeBSD__
|
---|
[128] | 1888 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
[1] | 1889 | #endif
|
---|
| 1890 |
|
---|
| 1891 |
|
---|
[1107] | 1892 | mr_msg(1, "make_cd_use_lilo is actually %d",
|
---|
[128] | 1893 | bkpinfo->make_cd_use_lilo);
|
---|
| 1894 | if (bkpinfo->make_cd_use_lilo) {
|
---|
[1107] | 1895 | mr_msg(1, "make_cd_use_lilo = TRUE");
|
---|
[1] | 1896 | // FIXME --- change mkisofs string to MONDO_MKISOFS_REGULAR_SYSLINUX/LILO depending on bkpinfo->make_cd_usE_lilo
|
---|
| 1897 | // and add ' .' at end
|
---|
| 1898 | #ifdef __IA64__
|
---|
[1107] | 1899 | mr_msg(1, "IA64 --> elilo");
|
---|
[128] | 1900 | res = eval_call_to_make_ISO(bkpinfo,
|
---|
| 1901 | //-b images/mindi-boot.2880.img
|
---|
[541] | 1902 | "mkisofs -no-emul-boot -b images/mindi-bootroot."
|
---|
| 1903 | IA64_BOOT_SIZE
|
---|
[906] | 1904 | ".img -c boot.cat -o '_ISO_' -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
|
---|
[128] | 1905 | destfile,
|
---|
| 1906 | g_current_media_number,
|
---|
| 1907 | MONDO_LOGFILE,
|
---|
| 1908 | message_to_screen);
|
---|
[1] | 1909 | #else
|
---|
| 1910 | // FIXME --- change mkisofs string to MONDO_MKISOFS_REGULAR_SYSLINUX/LILO depending on bkpinfo->make_cd_usE_lilo
|
---|
| 1911 | // and add ' .' at end
|
---|
[1107] | 1912 | mr_msg(1, "Non-ia64 --> lilo");
|
---|
[1138] | 1913 | res = eval_call_to_make_ISO(bkpinfo,
|
---|
| 1914 | "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#_ .",
|
---|
| 1915 | destfile,
|
---|
| 1916 | g_current_media_number,
|
---|
| 1917 | MONDO_LOGFILE,
|
---|
| 1918 | message_to_screen);
|
---|
[1] | 1919 | #endif
|
---|
[128] | 1920 | } else {
|
---|
[1107] | 1921 | mr_msg(1, "make_cd_use_lilo = FALSE");
|
---|
| 1922 | mr_msg(1, "Isolinux");
|
---|
[1137] | 1923 | res = eval_call_to_make_ISO(bkpinfo,
|
---|
| 1924 | "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#_ .",
|
---|
| 1925 | destfile,
|
---|
| 1926 | g_current_media_number,
|
---|
| 1927 | MONDO_LOGFILE,
|
---|
| 1928 | message_to_screen);
|
---|
[128] | 1929 | }
|
---|
| 1930 | }
|
---|
[1138] | 1931 | mr_free(message_to_screen);
|
---|
[128] | 1932 | if (res) {
|
---|
[1138] | 1933 | log_to_screen("%s...failed", result_sz);
|
---|
[128] | 1934 | } else {
|
---|
[1138] | 1935 | log_to_screen("%s...OK", result_sz);
|
---|
[128] | 1936 | }
|
---|
| 1937 | retval += res;
|
---|
[1139] | 1938 | mr_free(result_sz);
|
---|
[1] | 1939 | }
|
---|
[128] | 1940 |
|
---|
| 1941 | if (bkpinfo->backup_media_type == cdr
|
---|
| 1942 | || bkpinfo->backup_media_type == cdrw) {
|
---|
| 1943 | if (is_this_device_mounted(bkpinfo->media_device)) {
|
---|
[1107] | 1944 | mr_msg(2,
|
---|
[128] | 1945 | "Warning - %s mounted. I'm unmounting it before I burn to it.",
|
---|
| 1946 | bkpinfo->media_device);
|
---|
[1139] | 1947 | mr_asprintf(&tmp, "umount %s", bkpinfo->media_device);
|
---|
[128] | 1948 | run_program_and_log_output(tmp, FALSE);
|
---|
[1139] | 1949 | mr_free(tmp);
|
---|
[128] | 1950 | }
|
---|
[1] | 1951 | }
|
---|
| 1952 |
|
---|
[128] | 1953 | if (bkpinfo->call_burn_iso[0] != '\0') {
|
---|
[1107] | 1954 | mr_msg(2, "bkpinfo->call_burn_iso = %s", bkpinfo->call_burn_iso);
|
---|
[1139] | 1955 | mr_asprintf(&message_to_screen, "Burning %s #%d",
|
---|
| 1956 | bkpinfo->backup_media_string,
|
---|
| 1957 | g_current_media_number);
|
---|
[128] | 1958 | pause_and_ask_for_cdr(2, &cd_is_mountable);
|
---|
[1139] | 1959 | res = eval_call_to_make_ISO(bkpinfo, bkpinfo->call_burn_iso,
|
---|
| 1960 | destfile, g_current_media_number,
|
---|
| 1961 | MONDO_LOGFILE, message_to_screen);
|
---|
[128] | 1962 | if (res) {
|
---|
[1139] | 1963 | log_to_screen("%s...failed", message_to_screen);
|
---|
[128] | 1964 | } else {
|
---|
[1139] | 1965 | log_to_screen("%s...OK", message_to_screen);
|
---|
[128] | 1966 | }
|
---|
[1139] | 1967 | mr_free(message_to_screen);
|
---|
[128] | 1968 | retval += res;
|
---|
| 1969 | }
|
---|
[1] | 1970 |
|
---|
[1139] | 1971 | if (bkpinfo->call_after_iso != NULL) {
|
---|
| 1972 | mr_asprintf(&message_to_screen, "Running post-ISO call (%s #%d)",
|
---|
| 1973 | bkpinfo->backup_media_string,
|
---|
| 1974 | g_current_media_number);
|
---|
| 1975 | res = eval_call_to_make_ISO(bkpinfo, bkpinfo->call_after_iso,
|
---|
| 1976 | destfile, g_current_media_number,
|
---|
| 1977 | MONDO_LOGFILE, message_to_screen);
|
---|
[128] | 1978 | if (res) {
|
---|
[1139] | 1979 | log_to_screen("%s...failed", message_to_screen);
|
---|
[128] | 1980 | } else {
|
---|
[1139] | 1981 | log_to_screen("%s...OK", message_to_screen);
|
---|
[128] | 1982 | }
|
---|
[1139] | 1983 | mr_free(message_to_screen);
|
---|
[128] | 1984 | retval += res;
|
---|
[1] | 1985 | }
|
---|
| 1986 |
|
---|
[128] | 1987 | chdir(old_pwd);
|
---|
| 1988 | if (retval) {
|
---|
[1107] | 1989 | mr_msg(1, "WARNING - make_iso_fs returned an error");
|
---|
[1] | 1990 | }
|
---|
[1080] | 1991 | mr_free(old_pwd);
|
---|
[128] | 1992 | return (retval);
|
---|
[1] | 1993 | }
|
---|
| 1994 |
|
---|
| 1995 |
|
---|
| 1996 | bool is_dev_an_NTFS_dev(char *bigfile_fname)
|
---|
| 1997 | {
|
---|
[128] | 1998 | char *tmp;
|
---|
| 1999 | char *command;
|
---|
| 2000 | malloc_string(tmp);
|
---|
[1137] | 2001 | bool ret = TRUE;
|
---|
| 2002 | mr_asprintf(&command,
|
---|
| 2003 | "dd if=%s bs=512 count=1 2> /dev/null | strings | head -n1",
|
---|
| 2004 | bigfile_fname);
|
---|
[1107] | 2005 | mr_msg(1, "command = '%s'", command);
|
---|
[128] | 2006 | strcpy(tmp, call_program_and_get_last_line_of_output(command));
|
---|
[1107] | 2007 | mr_msg(1, "--> tmp = '%s'", tmp);
|
---|
[1137] | 2008 | mr_free(command);
|
---|
[128] | 2009 | if (strstr(tmp, "NTFS")) {
|
---|
| 2010 | iamhere("TRUE");
|
---|
| 2011 | } else {
|
---|
| 2012 | iamhere("FALSE");
|
---|
[1137] | 2013 | ret = FALSE;
|
---|
[128] | 2014 | }
|
---|
[1137] | 2015 | return(ret);
|
---|
[1] | 2016 | }
|
---|
| 2017 |
|
---|
| 2018 |
|
---|
| 2019 | /**
|
---|
| 2020 | * Back up big files by chopping them up.
|
---|
| 2021 | * This function backs up all "big" files (where "big" depends
|
---|
| 2022 | * on your backup media) in "chunks" (whose size again depends
|
---|
| 2023 | * on your media).
|
---|
| 2024 | *
|
---|
| 2025 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 2026 | * - @c backup_media_type
|
---|
| 2027 | * - @c optimal_set_size
|
---|
| 2028 | * @param biggielist_fname The path to a file containing a list of
|
---|
| 2029 | * all "big" files.
|
---|
| 2030 | * @return The number of errors encountered (0 for success)
|
---|
| 2031 | * @see slice_up_file_etc
|
---|
| 2032 | */
|
---|
| 2033 | int
|
---|
[541] | 2034 | make_slices_and_images(struct s_bkpinfo *bkpinfo, char *biggielist_fname)
|
---|
[1] | 2035 | {
|
---|
| 2036 |
|
---|
[128] | 2037 | /*@ pointers ******************************************* */
|
---|
[1142] | 2038 | FILE *fin = NULL;
|
---|
| 2039 | char *p = NULL;
|
---|
[1] | 2040 |
|
---|
[128] | 2041 | /*@ buffers ******************************************** */
|
---|
[1142] | 2042 | char *tmp = NULL;
|
---|
[1139] | 2043 | char *bigfile_fname = NULL;
|
---|
[1142] | 2044 | char *sz_devfile = NULL;
|
---|
[296] | 2045 | char *ntfsprog_fifo = NULL;
|
---|
[128] | 2046 | /*@ long *********************************************** */
|
---|
| 2047 | long biggie_file_number = 0;
|
---|
| 2048 | long noof_biggie_files = 0;
|
---|
| 2049 | long estimated_total_noof_slices = 0;
|
---|
[1] | 2050 |
|
---|
[128] | 2051 | /*@ int ************************************************ */
|
---|
| 2052 | int retval = 0;
|
---|
| 2053 | int res = 0;
|
---|
[1139] | 2054 | size_t n = 0;
|
---|
[128] | 2055 | pid_t pid;
|
---|
| 2056 | FILE *ftmp = NULL;
|
---|
| 2057 | bool delete_when_done;
|
---|
[296] | 2058 | bool use_ntfsprog;
|
---|
[684] | 2059 | off_t biggie_fsize;
|
---|
[1] | 2060 |
|
---|
[128] | 2061 | assert(bkpinfo != NULL);
|
---|
| 2062 | assert_string_is_neither_NULL_nor_zerolength(biggielist_fname);
|
---|
[1] | 2063 |
|
---|
[128] | 2064 | estimated_total_noof_slices =
|
---|
| 2065 | size_of_all_biggiefiles_K(bkpinfo) / bkpinfo->optimal_set_size + 1;
|
---|
[1] | 2066 |
|
---|
[1107] | 2067 | mr_msg(1, "size of all biggiefiles = %ld",
|
---|
[128] | 2068 | size_of_all_biggiefiles_K(bkpinfo));
|
---|
[1107] | 2069 | mr_msg(1, "estimated_total_noof_slices = %ld KB / %ld KB = %ld",
|
---|
[128] | 2070 | size_of_all_biggiefiles_K(bkpinfo), bkpinfo->optimal_set_size,
|
---|
| 2071 | estimated_total_noof_slices);
|
---|
[1] | 2072 |
|
---|
[128] | 2073 | if (length_of_file(biggielist_fname) < 6) {
|
---|
[1107] | 2074 | mr_msg(1, "No biggiefiles; fair enough...");
|
---|
[128] | 2075 | return (0);
|
---|
[1] | 2076 | }
|
---|
[1142] | 2077 | mr_asprintf(&tmp, "I am now backing up all large files.");
|
---|
[128] | 2078 | log_to_screen(tmp);
|
---|
| 2079 | noof_biggie_files = count_lines_in_file(biggielist_fname);
|
---|
| 2080 | open_progress_form("Backing up big files", tmp,
|
---|
| 2081 | "Please wait. This may take some time.", "",
|
---|
| 2082 | estimated_total_noof_slices);
|
---|
[1142] | 2083 | mr_free(tmp);
|
---|
| 2084 |
|
---|
[128] | 2085 | if (!(fin = fopen(biggielist_fname, "r"))) {
|
---|
| 2086 | log_OS_error("Unable to openin biggielist");
|
---|
| 2087 | return (1);
|
---|
[1] | 2088 | }
|
---|
[1142] | 2089 | for (mr_getline(&bigfile_fname, &n, fin); !feof(fin);
|
---|
| 2090 | mr_getline(&bigfile_fname, &n, fin), biggie_file_number++) {
|
---|
[296] | 2091 | use_ntfsprog = FALSE;
|
---|
[128] | 2092 | if (bigfile_fname[strlen(bigfile_fname) - 1] < 32) {
|
---|
| 2093 | bigfile_fname[strlen(bigfile_fname) - 1] = '\0';
|
---|
| 2094 | }
|
---|
| 2095 | biggie_fsize = length_of_file(bigfile_fname);
|
---|
| 2096 | delete_when_done = FALSE;
|
---|
| 2097 |
|
---|
| 2098 | if (!does_file_exist(bigfile_fname)) {
|
---|
| 2099 | ftmp = fopen(bigfile_fname, "w");
|
---|
| 2100 | paranoid_fclose(ftmp);
|
---|
| 2101 | delete_when_done = TRUE;
|
---|
| 2102 | } else {
|
---|
[812] | 2103 | // Call ntfsclone (formerly partimagehack) if it's a /dev entry
|
---|
| 2104 | // (i.e. a partition to be imaged)
|
---|
[1107] | 2105 | mr_msg(2, "bigfile_fname = %s", bigfile_fname);
|
---|
[296] | 2106 | use_ntfsprog = FALSE;
|
---|
[128] | 2107 | if (!strncmp(bigfile_fname, "/dev/", 5)
|
---|
| 2108 | && is_dev_an_NTFS_dev(bigfile_fname)) {
|
---|
[296] | 2109 | use_ntfsprog = TRUE;
|
---|
[1107] | 2110 | mr_msg(2,
|
---|
[296] | 2111 | "Calling ntfsclone in background because %s is an NTFS partition",
|
---|
[128] | 2112 | bigfile_fname);
|
---|
[1142] | 2113 | mr_asprintf(&sz_devfile, "%s/%d.%d.000",
|
---|
[812] | 2114 | bkpinfo->tmpdir,
|
---|
[128] | 2115 | (int) (random() % 32768),
|
---|
| 2116 | (int) (random() % 32768));
|
---|
| 2117 | mkfifo(sz_devfile, 0x770);
|
---|
[296] | 2118 | ntfsprog_fifo = sz_devfile;
|
---|
[128] | 2119 | switch (pid = fork()) {
|
---|
| 2120 | case -1:
|
---|
| 2121 | fatal_error("Fork failure");
|
---|
| 2122 | case 0:
|
---|
[1107] | 2123 | mr_msg(2,
|
---|
[296] | 2124 | "CHILD - fip - calling feed_into_ntfsprog(%s, %s)",
|
---|
[128] | 2125 | bigfile_fname, sz_devfile);
|
---|
[296] | 2126 | res = feed_into_ntfsprog(bigfile_fname, sz_devfile);
|
---|
[1142] | 2127 | mr_free(sz_devfile);
|
---|
[128] | 2128 | exit(res);
|
---|
| 2129 | break;
|
---|
| 2130 | default:
|
---|
[1107] | 2131 | mr_msg(2,
|
---|
[296] | 2132 | "feed_into_ntfsprog() called in background --- pid=%ld",
|
---|
[128] | 2133 | (long int) (pid));
|
---|
[1142] | 2134 | mr_free(sz_devfile);
|
---|
| 2135 | break;
|
---|
[128] | 2136 | }
|
---|
| 2137 | }
|
---|
[1142] | 2138 | // Otherwise, use good old 'dd' and 'bzip2'
|
---|
[128] | 2139 | else {
|
---|
[296] | 2140 | ntfsprog_fifo = NULL;
|
---|
[128] | 2141 | }
|
---|
[1] | 2142 |
|
---|
[1142] | 2143 | // Whether partition or biggiefile, just do your thang :-)
|
---|
| 2144 | mr_msg(5, "Bigfile #%ld is '%s' (%ld KB)",
|
---|
[128] | 2145 | biggie_file_number + 1, bigfile_fname,
|
---|
| 2146 | (long) biggie_fsize >> 10);
|
---|
| 2147 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 2148 | write_header_block_to_stream(biggie_fsize, bigfile_fname,
|
---|
[296] | 2149 | use_ntfsprog ?
|
---|
[128] | 2150 | BLK_START_A_PIHBIGGIE :
|
---|
| 2151 | BLK_START_A_NORMBIGGIE);
|
---|
| 2152 | }
|
---|
| 2153 | res =
|
---|
[541] | 2154 | slice_up_file_etc(bkpinfo, bigfile_fname,
|
---|
[296] | 2155 | ntfsprog_fifo, biggie_file_number,
|
---|
| 2156 | noof_biggie_files, use_ntfsprog);
|
---|
[128] | 2157 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
[684] | 2158 | write_header_block_to_stream((off_t)0,
|
---|
[128] | 2159 | calc_checksum_of_file
|
---|
| 2160 | (bigfile_fname),
|
---|
| 2161 | BLK_STOP_A_BIGGIE);
|
---|
| 2162 | }
|
---|
| 2163 | retval += res;
|
---|
| 2164 | p = strrchr(bigfile_fname, '/');
|
---|
| 2165 | if (p) {
|
---|
| 2166 | p++;
|
---|
| 2167 | } else {
|
---|
| 2168 | p = bigfile_fname;
|
---|
| 2169 | }
|
---|
| 2170 | if (res) {
|
---|
[1142] | 2171 | mr_asprintf(&tmp, "Archiving %s ... Failed!", bigfile_fname);
|
---|
[128] | 2172 | } else {
|
---|
[1142] | 2173 | mr_asprintf(&tmp, "Archiving %s ... OK!", bigfile_fname);
|
---|
[128] | 2174 | }
|
---|
[1142] | 2175 | mr_msg(4,tmp);
|
---|
| 2176 | mr_free(tmp);
|
---|
[128] | 2177 | if (delete_when_done) {
|
---|
| 2178 | unlink(bigfile_fname);
|
---|
| 2179 | delete_when_done = FALSE;
|
---|
| 2180 | }
|
---|
| 2181 | }
|
---|
| 2182 | if (!g_text_mode) {
|
---|
| 2183 | newtDrawRootText(0, g_noof_rows - 2, tmp);
|
---|
| 2184 | newtRefresh();
|
---|
| 2185 | }
|
---|
| 2186 | }
|
---|
[1142] | 2187 | mr_free(bigfile_fname);
|
---|
| 2188 | paranoid_fclose(fin);
|
---|
| 2189 |
|
---|
[1107] | 2190 | mr_msg(1, "Finished backing up bigfiles");
|
---|
| 2191 | mr_msg(1, "estimated slices = %ld; actual slices = %ld",
|
---|
[128] | 2192 | estimated_total_noof_slices, g_current_progress);
|
---|
| 2193 | close_progress_form();
|
---|
| 2194 | return (retval);
|
---|
[1] | 2195 | }
|
---|
| 2196 |
|
---|
| 2197 |
|
---|
| 2198 | /**
|
---|
| 2199 | * Single-threaded version of @c make_afioballs_and_images().
|
---|
| 2200 | * @see make_afioballs_and_images
|
---|
| 2201 | */
|
---|
[541] | 2202 | int make_afioballs_and_images_OLD(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 2203 | {
|
---|
| 2204 |
|
---|
[128] | 2205 | /*@ int ************************************************** */
|
---|
| 2206 | int retval = 0;
|
---|
| 2207 | long int curr_set_no = 0;
|
---|
| 2208 | int res = 0;
|
---|
[1] | 2209 |
|
---|
[128] | 2210 | /*@ buffers ********************************************** */
|
---|
[1142] | 2211 | char *curr_filelist_fname = NULL;
|
---|
| 2212 | char *curr_afioball_fname = NULL;
|
---|
| 2213 | char *curr_xattr_list_fname = NULL;
|
---|
| 2214 | char *curr_acl_list_fname = NULL;
|
---|
| 2215 | char *media_usage_comment = NULL;
|
---|
| 2216 | char *tmp= mr_malloc(MAX_STR_LEN * 2);
|
---|
[1] | 2217 |
|
---|
[1142] | 2218 | /* BERLIOS: Useless ?
|
---|
| 2219 | mr_asprintf(&tmp, "%s/archives/filelist.full", bkpinfo->scratchdir);
|
---|
| 2220 | */
|
---|
[128] | 2221 | malloc_string(media_usage_comment);
|
---|
| 2222 | log_to_screen("Archiving regular files");
|
---|
[1] | 2223 |
|
---|
[1142] | 2224 | open_progress_form(_("Backing up filesystem"),
|
---|
| 2225 | _("I am backing up your live filesystem now."),
|
---|
| 2226 | _("Please wait. This may take a couple of hours."),
|
---|
| 2227 | _("Working..."),
|
---|
[128] | 2228 | get_last_filelist_number(bkpinfo) + 1);
|
---|
| 2229 |
|
---|
[1142] | 2230 | mr_asprintf(&curr_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir,
|
---|
| 2231 | 0L);
|
---|
[128] | 2232 |
|
---|
[1142] | 2233 | curr_set_no = 0;
|
---|
| 2234 | while (does_file_exist(curr_filelist_fname)) {
|
---|
[128] | 2235 | /* backup this set of files */
|
---|
[1142] | 2236 | mr_asprintf(&curr_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
|
---|
| 2237 | bkpinfo->tmpdir, curr_set_no, bkpinfo->zip_suffix);
|
---|
[128] | 2238 |
|
---|
[1107] | 2239 | mr_msg(1, "EXAT'g set %ld", curr_set_no);
|
---|
[948] | 2240 | if (g_getfattr) {
|
---|
[1142] | 2241 | mr_asprintf(&curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
|
---|
[128] | 2242 | bkpinfo->tmpdir, curr_set_no);
|
---|
[948] | 2243 | get_fattr_list(curr_filelist_fname, curr_xattr_list_fname);
|
---|
| 2244 | }
|
---|
| 2245 | if (g_getfacl) {
|
---|
[1142] | 2246 | mr_asprintf(&curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
|
---|
[128] | 2247 | bkpinfo->tmpdir, curr_set_no);
|
---|
[948] | 2248 | get_acl_list(curr_filelist_fname, curr_acl_list_fname);
|
---|
| 2249 | }
|
---|
[128] | 2250 |
|
---|
[1107] | 2251 | mr_msg(1, "Archiving set %ld", curr_set_no);
|
---|
[1142] | 2252 | res = archive_this_fileset(bkpinfo, curr_filelist_fname,
|
---|
[128] | 2253 | curr_afioball_fname, curr_set_no);
|
---|
| 2254 | retval += res;
|
---|
| 2255 | if (res) {
|
---|
[1142] | 2256 | mr_asprintf(&tmp,
|
---|
| 2257 | "Errors occurred while archiving set %ld. Perhaps your live filesystem changed?",
|
---|
| 2258 | curr_set_no);
|
---|
[128] | 2259 | log_to_screen(tmp);
|
---|
[1142] | 2260 | mr_free(tmp);
|
---|
[128] | 2261 | }
|
---|
| 2262 |
|
---|
| 2263 | strcpy(media_usage_comment, percent_media_full_comment(bkpinfo));
|
---|
| 2264 |
|
---|
| 2265 | /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
|
---|
| 2266 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 2267 | register_in_tape_catalog(fileset, curr_set_no, -1,
|
---|
| 2268 | curr_afioball_fname);
|
---|
| 2269 | maintain_collection_of_recent_archives(bkpinfo->tmpdir,
|
---|
| 2270 | curr_afioball_fname);
|
---|
| 2271 | iamhere("Writing EXAT files");
|
---|
[1142] | 2272 | res += write_EXAT_files_to_tape(bkpinfo, curr_xattr_list_fname,
|
---|
| 2273 | curr_acl_list_fname);
|
---|
| 2274 | // archives themselves
|
---|
[128] | 2275 | res = move_files_to_stream(bkpinfo, curr_afioball_fname, NULL);
|
---|
| 2276 | } else {
|
---|
[948] | 2277 | if (g_getfacl) {
|
---|
| 2278 | if (g_getfattr) {
|
---|
| 2279 | res = move_files_to_cd(bkpinfo, curr_filelist_fname,
|
---|
| 2280 | curr_xattr_list_fname,
|
---|
| 2281 | curr_acl_list_fname,
|
---|
| 2282 | curr_afioball_fname, NULL);
|
---|
| 2283 | } else {
|
---|
| 2284 | res = move_files_to_cd(bkpinfo, curr_filelist_fname,
|
---|
| 2285 | curr_acl_list_fname,
|
---|
| 2286 | curr_afioball_fname, NULL);
|
---|
| 2287 | }
|
---|
| 2288 | } else {
|
---|
| 2289 | if (g_getfattr) {
|
---|
| 2290 | res = move_files_to_cd(bkpinfo, curr_filelist_fname,
|
---|
| 2291 | curr_xattr_list_fname,
|
---|
| 2292 | curr_afioball_fname, NULL);
|
---|
| 2293 | } else {
|
---|
| 2294 | res = move_files_to_cd(bkpinfo, curr_filelist_fname,
|
---|
| 2295 | curr_afioball_fname, NULL);
|
---|
| 2296 | }
|
---|
| 2297 | }
|
---|
[128] | 2298 | }
|
---|
| 2299 | retval += res;
|
---|
| 2300 | g_current_progress++;
|
---|
| 2301 | update_progress_form(media_usage_comment);
|
---|
[1] | 2302 |
|
---|
[128] | 2303 | if (res) {
|
---|
[1142] | 2304 | mr_asprintf(&tmp, "Failed to add archive %ld's files to CD dir\n",
|
---|
| 2305 | curr_set_no);
|
---|
[128] | 2306 | log_to_screen(tmp);
|
---|
[1142] | 2307 | mr_free(tmp);
|
---|
[128] | 2308 | fatal_error
|
---|
| 2309 | ("Is your hard disk is full? If not, please send the author the logfile.");
|
---|
| 2310 | }
|
---|
[1142] | 2311 | mr_free(curr_filelist_fname);
|
---|
| 2312 | mr_free(curr_afioball_fname);
|
---|
| 2313 | mr_free(curr_xattr_list_fname);
|
---|
| 2314 | mr_free(curr_acl_list_fname);
|
---|
| 2315 | mr_asprintf(&curr_filelist_fname, FILELIST_FNAME_RAW_SZ,
|
---|
| 2316 | bkpinfo->tmpdir, ++curr_set_no);
|
---|
[1] | 2317 | }
|
---|
[1142] | 2318 | mr_free(curr_filelist_fname);
|
---|
[128] | 2319 | close_progress_form();
|
---|
| 2320 | if (retval) {
|
---|
[1142] | 2321 | log_to_screen
|
---|
| 2322 | ("Your regular files have been archived (with errors).");
|
---|
[128] | 2323 | } else {
|
---|
[1142] | 2324 | log_to_screen
|
---|
| 2325 | ("Your regular files have been archived successfully.");
|
---|
[128] | 2326 | }
|
---|
[1080] | 2327 | mr_free(media_usage_comment);
|
---|
[128] | 2328 | return (retval);
|
---|
[1] | 2329 | }
|
---|
| 2330 |
|
---|
[128] | 2331 | /* @} - end of LLarchiveGroup */
|
---|
| 2332 |
|
---|
| 2333 |
|
---|
[1] | 2334 | /**
|
---|
| 2335 | * Wrapper around @c make_afioballs_and_images().
|
---|
| 2336 | * @param bkpinfo the backup information structure. Only the
|
---|
| 2337 | * @c backup_media_type field is used within this function.
|
---|
| 2338 | * @return return code of make_afioballs_and_images
|
---|
| 2339 | * @see make_afioballs_and_images
|
---|
| 2340 | * @ingroup MLarchiveGroup
|
---|
| 2341 | */
|
---|
[541] | 2342 | int make_those_afios_phase(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 2343 | {
|
---|
[128] | 2344 | /*@ int ******************************************* */
|
---|
| 2345 | int res = 0;
|
---|
| 2346 | int retval = 0;
|
---|
[1] | 2347 |
|
---|
[128] | 2348 | assert(bkpinfo != NULL);
|
---|
[1] | 2349 |
|
---|
[128] | 2350 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
| 2351 | "Archiving regular files to media ");
|
---|
[1] | 2352 |
|
---|
[128] | 2353 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
[684] | 2354 | write_header_block_to_stream((off_t)0, "start-of-afioballs",
|
---|
[128] | 2355 | BLK_START_AFIOBALLS);
|
---|
[1] | 2356 | #if __FreeBSD__ == 5
|
---|
[1107] | 2357 | mr_msg(1,
|
---|
[128] | 2358 | "Using single-threaded make_afioballs_and_images() to suit b0rken FreeBSD 5.0");
|
---|
[541] | 2359 | res = make_afioballs_and_images_OLD(bkpinfo);
|
---|
[1] | 2360 | #else
|
---|
[541] | 2361 | res = make_afioballs_and_images_OLD(bkpinfo);
|
---|
[1] | 2362 | #endif
|
---|
[684] | 2363 | write_header_block_to_stream((off_t)0, "stop-afioballs",
|
---|
[128] | 2364 | BLK_STOP_AFIOBALLS);
|
---|
| 2365 | } else {
|
---|
[541] | 2366 | res = make_afioballs_and_images(bkpinfo);
|
---|
[128] | 2367 | }
|
---|
[1] | 2368 |
|
---|
[128] | 2369 | retval += res;
|
---|
| 2370 | if (res) {
|
---|
| 2371 | mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
|
---|
[1107] | 2372 | mr_msg(1, "make_afioballs_and_images returned an error");
|
---|
[128] | 2373 | } else {
|
---|
| 2374 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
| 2375 | }
|
---|
| 2376 | return (retval);
|
---|
[1] | 2377 | }
|
---|
| 2378 |
|
---|
| 2379 | /**
|
---|
| 2380 | * Wrapper around @c make_slices_and_images().
|
---|
| 2381 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 2382 | * - @c backup_media_type
|
---|
| 2383 | * - @c scratchdir
|
---|
| 2384 | * - @c tmpdir
|
---|
| 2385 | * @return The number of errors encountered (0 for success)
|
---|
| 2386 | * @ingroup MLarchiveGroup
|
---|
| 2387 | */
|
---|
[128] | 2388 | int make_those_slices_phase(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 2389 | {
|
---|
| 2390 |
|
---|
[128] | 2391 | /*@ int ***************************************************** */
|
---|
| 2392 | int res = 0;
|
---|
| 2393 | int retval = 0;
|
---|
[1] | 2394 |
|
---|
[128] | 2395 | /*@ buffers ************************************************** */
|
---|
[1143] | 2396 | char *biggielist = NULL;
|
---|
| 2397 | char *command = NULL;
|
---|
| 2398 | char *blah = NULL;
|
---|
| 2399 | char *xattr_fname = NULL;
|
---|
[1146] | 2400 | char *acl_fname = NULL;
|
---|
[1] | 2401 |
|
---|
[128] | 2402 | assert(bkpinfo != NULL);
|
---|
| 2403 | /* slice big files */
|
---|
| 2404 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
| 2405 | "Archiving large files to media ");
|
---|
[1154] | 2406 | mr_asprintf(&biggielist, "%s/archives/biggielist.txt", bkpinfo->scratchdir);
|
---|
[948] | 2407 | if (g_getfattr) {
|
---|
[1154] | 2408 | mr_asprintf(&xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
|
---|
[948] | 2409 | }
|
---|
| 2410 | if (g_getfacl) {
|
---|
[1154] | 2411 | mr_asprintf(&acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
|
---|
[948] | 2412 | }
|
---|
[1] | 2413 |
|
---|
[1154] | 2414 | mr_asprintf(&command, "cp %s/biggielist.txt %s", bkpinfo->tmpdir, biggielist);
|
---|
[128] | 2415 | paranoid_system(command);
|
---|
[1147] | 2416 | mr_free(command);
|
---|
| 2417 |
|
---|
| 2418 | mr_asprintf(&blah, "biggielist = %s", biggielist);
|
---|
[1107] | 2419 | mr_msg(2, blah);
|
---|
[1147] | 2420 | mr_free(blah);
|
---|
[128] | 2421 |
|
---|
| 2422 | if (!does_file_exist(biggielist)) {
|
---|
[1107] | 2423 | mr_msg(1, "BTW, the biggielist does not exist");
|
---|
[128] | 2424 | }
|
---|
| 2425 |
|
---|
[948] | 2426 | if (g_getfattr) {
|
---|
| 2427 | get_fattr_list(biggielist, xattr_fname);
|
---|
[1154] | 2428 | mr_asprintf(&command, "cp %s %s/archives/", xattr_fname, bkpinfo->scratchdir);
|
---|
[948] | 2429 | paranoid_system(command);
|
---|
[1147] | 2430 | mr_free(command);
|
---|
[948] | 2431 | }
|
---|
| 2432 | if (g_getfacl) {
|
---|
| 2433 | get_acl_list(biggielist, acl_fname);
|
---|
[1154] | 2434 | mr_asprintf(&command, "cp %s %s/archives/", acl_fname, bkpinfo->scratchdir);
|
---|
[948] | 2435 | paranoid_system(command);
|
---|
[1147] | 2436 | mr_free(command);
|
---|
[948] | 2437 | }
|
---|
[128] | 2438 |
|
---|
| 2439 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 2440 | res += write_EXAT_files_to_tape(bkpinfo, xattr_fname, acl_fname);
|
---|
[1147] | 2441 | mr_asprintf(&blah, "%ld", count_lines_in_file(biggielist));
|
---|
[684] | 2442 | write_header_block_to_stream((off_t)0, blah, BLK_START_BIGGIEFILES);
|
---|
[1147] | 2443 | mr_free(blah);
|
---|
[128] | 2444 | }
|
---|
[1154] | 2445 | if (g_getfattr) {
|
---|
| 2446 | mr_free(xattr_fname);
|
---|
| 2447 | }
|
---|
| 2448 | if (g_getfacl) {
|
---|
| 2449 | mr_free(acl_fname);
|
---|
| 2450 | }
|
---|
| 2451 |
|
---|
[128] | 2452 | res = make_slices_and_images(bkpinfo, biggielist);
|
---|
[1154] | 2453 | mr_free(biggielist);
|
---|
| 2454 |
|
---|
[128] | 2455 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
[684] | 2456 | write_header_block_to_stream((off_t)0, "end-of-biggiefiles",
|
---|
[128] | 2457 | BLK_STOP_BIGGIEFILES);
|
---|
| 2458 | }
|
---|
| 2459 | retval += res;
|
---|
| 2460 | if (res) {
|
---|
[1107] | 2461 | mr_msg(1, "make_slices_and_images returned an error");
|
---|
[128] | 2462 | mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
|
---|
| 2463 | } else {
|
---|
| 2464 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
| 2465 | }
|
---|
| 2466 | return (retval);
|
---|
[1] | 2467 | }
|
---|
| 2468 |
|
---|
| 2469 |
|
---|
| 2470 | /**
|
---|
| 2471 | * @addtogroup LLarchiveGroup
|
---|
| 2472 | * @{
|
---|
| 2473 | */
|
---|
| 2474 | /**
|
---|
| 2475 | * Function pointer to an appropriate @c move_files_to_cd routine.
|
---|
| 2476 | * You can set this to your own function (for example, one to
|
---|
| 2477 | * transfer files over the network) or leave it as is.
|
---|
| 2478 | */
|
---|
[541] | 2479 | int (*move_files_to_cd) (struct s_bkpinfo *, char *, ...) =
|
---|
[128] | 2480 | _move_files_to_cd;
|
---|
[1] | 2481 |
|
---|
| 2482 | /**
|
---|
| 2483 | * Move some files to the ISO scratch directory.
|
---|
| 2484 | * This function moves files specified as parameters, into the directory
|
---|
| 2485 | * @c bkpinfo->scratchdir, where the files that will be stored on the next
|
---|
| 2486 | * CD are waiting.
|
---|
| 2487 | *
|
---|
| 2488 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 2489 | * - @c media_size
|
---|
| 2490 | * - @c scratchdir
|
---|
| 2491 | * @param files_to_add The files to add to the scratchdir.
|
---|
| 2492 | * @warning The list of @c files_to_add must be terminated with @c NULL.
|
---|
| 2493 | * @note If and when the space occupied by the scratchdir would exceed
|
---|
| 2494 | * the capacity of the current CD,
|
---|
| 2495 | * <tt>write_iso_and_go_on(bkpinfo, FALSE)</tt> is called and the
|
---|
| 2496 | * scratchdir is emptied.
|
---|
| 2497 | *
|
---|
| 2498 | * @return The number of errors encountered (0 for success)
|
---|
| 2499 | */
|
---|
[541] | 2500 | int _move_files_to_cd(struct s_bkpinfo *bkpinfo, char *files_to_add, ...)
|
---|
[1] | 2501 | {
|
---|
| 2502 |
|
---|
[128] | 2503 | /*@ int ************************************************************ */
|
---|
| 2504 | int retval = 0;
|
---|
[1] | 2505 | int res = 0;
|
---|
| 2506 |
|
---|
[128] | 2507 | /*@ buffers ******************************************************** */
|
---|
[1154] | 2508 | char *tmp = NULL;
|
---|
| 2509 | char *curr_file = NULL;
|
---|
| 2510 | char *cf = NULL;
|
---|
[1] | 2511 |
|
---|
[128] | 2512 | /*@ long ************************************************************ */
|
---|
| 2513 | va_list ap;
|
---|
| 2514 | long long would_occupy;
|
---|
[1] | 2515 |
|
---|
[128] | 2516 | assert(bkpinfo != NULL);
|
---|
| 2517 | would_occupy = space_occupied_by_cd(bkpinfo->scratchdir);
|
---|
| 2518 | va_start(ap, files_to_add); // initialize the variable arguments
|
---|
| 2519 | for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
|
---|
| 2520 | if (!cf) {
|
---|
| 2521 | continue;
|
---|
| 2522 | }
|
---|
[1154] | 2523 | mr_asprintf(&curr_file, cf);
|
---|
[128] | 2524 | if (!does_file_exist(curr_file)) {
|
---|
[1107] | 2525 | mr_msg(1,
|
---|
[128] | 2526 | "Warning - you're trying to add a non-existent file - '%s' to the CD",
|
---|
| 2527 | curr_file);
|
---|
| 2528 | } else {
|
---|
[1107] | 2529 | mr_msg(8, "Trying to add file %s to CD", curr_file);
|
---|
[128] | 2530 | would_occupy += length_of_file(curr_file) / 1024;
|
---|
| 2531 | }
|
---|
[1154] | 2532 | mr_free(curr_file);
|
---|
[1] | 2533 | }
|
---|
[128] | 2534 | va_end(ap);
|
---|
[1] | 2535 |
|
---|
[128] | 2536 | if (bkpinfo->media_size[g_current_media_number] <= 0) {
|
---|
| 2537 | fatal_error("move_files_to_cd() - unknown media size");
|
---|
[1] | 2538 | }
|
---|
[128] | 2539 | if (would_occupy / 1024 > bkpinfo->media_size[g_current_media_number]) {
|
---|
[1154] | 2540 | /* FALSE because this is not the last CD we'll write */
|
---|
| 2541 | res = write_iso_and_go_on(bkpinfo, FALSE);
|
---|
[128] | 2542 | retval += res;
|
---|
| 2543 | if (res) {
|
---|
[1107] | 2544 | mr_msg(1, "WARNING - write_iso_and_go_on returned an error");
|
---|
[128] | 2545 | }
|
---|
| 2546 | }
|
---|
[1] | 2547 |
|
---|
[128] | 2548 | va_start(ap, files_to_add); // initialize the variable arguments
|
---|
| 2549 | for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
|
---|
| 2550 | if (!cf) {
|
---|
| 2551 | continue;
|
---|
| 2552 | }
|
---|
[1154] | 2553 | mr_asprintf(&curr_file, cf);
|
---|
[1] | 2554 |
|
---|
[1154] | 2555 | mr_asprintf(&tmp, "mv -f %s %s/archives/", curr_file,
|
---|
| 2556 | bkpinfo->scratchdir);
|
---|
[128] | 2557 | res = run_program_and_log_output(tmp, 5);
|
---|
| 2558 | retval += res;
|
---|
| 2559 | if (res) {
|
---|
[1107] | 2560 | mr_msg(1, "(move_files_to_cd) '%s' failed", tmp);
|
---|
[128] | 2561 | } else {
|
---|
[1107] | 2562 | mr_msg(8, "Moved %s to CD OK", tmp);
|
---|
[128] | 2563 | }
|
---|
[1154] | 2564 | mr_free(tmp);
|
---|
| 2565 | mr_free(curr_file);
|
---|
[128] | 2566 | // unlink (curr_file);
|
---|
[1] | 2567 | }
|
---|
[128] | 2568 | va_end(ap);
|
---|
| 2569 |
|
---|
| 2570 | if (retval) {
|
---|
[1107] | 2571 | mr_msg(1,
|
---|
[128] | 2572 | "Warning - errors occurred while I was adding files to CD dir");
|
---|
[1] | 2573 | }
|
---|
[128] | 2574 | return (retval);
|
---|
[1] | 2575 | }
|
---|
| 2576 |
|
---|
| 2577 | /* @} - end of LLarchiveGroup */
|
---|
| 2578 |
|
---|
| 2579 |
|
---|
| 2580 | /**
|
---|
| 2581 | * Offer to write boot and data disk images to 3.5" floppy disks.
|
---|
| 2582 | * @param bkpinfo The backup information structure. Only the
|
---|
| 2583 | * @c backup_media_type field is used in this function.
|
---|
| 2584 | * @param imagesdir The directory containing the floppy images (usually
|
---|
[1044] | 2585 | * /var/cache/mindi).
|
---|
[1] | 2586 | *
|
---|
| 2587 | * @return The number of errors encountered (0 for success)
|
---|
| 2588 | * @see write_image_to_floppy
|
---|
| 2589 | * @see format_disk
|
---|
| 2590 | * @ingroup MLarchiveGroup
|
---|
| 2591 | */
|
---|
[128] | 2592 | int offer_to_write_floppies(struct s_bkpinfo *bkpinfo, char *imagesdir)
|
---|
[1] | 2593 | {
|
---|
[128] | 2594 | /*@ buffer ************************************************************ */
|
---|
[1154] | 2595 | char *tmp = NULL;
|
---|
| 2596 | char *comment = NULL;
|
---|
| 2597 | char *bootdisk_dev =NULL;
|
---|
| 2598 | char *datadisk_dev = NULL;
|
---|
| 2599 | char *bootdisk_file = NULL;
|
---|
| 2600 | char *rootdisk_file = NULL;
|
---|
[1] | 2601 |
|
---|
[128] | 2602 | /*@ int *************************************************************** */
|
---|
| 2603 | int i = 0;
|
---|
[1] | 2604 | int res = 0;
|
---|
| 2605 |
|
---|
[128] | 2606 | /*@ bool ************************************************************** */
|
---|
| 2607 | bool format_first;
|
---|
| 2608 | bool root_disk_exists = FALSE;
|
---|
[1] | 2609 |
|
---|
[128] | 2610 | assert(bkpinfo != NULL);
|
---|
| 2611 | assert_string_is_neither_NULL_nor_zerolength(imagesdir);
|
---|
[1] | 2612 |
|
---|
[128] | 2613 | if (!ask_me_yes_or_no
|
---|
| 2614 | ("Write boot and data disk images to 3.5\" floppy disks?")) {
|
---|
| 2615 | return (0);
|
---|
| 2616 | }
|
---|
| 2617 | if (does_device_exist(DEFAULT_1722MB_DISK)) {
|
---|
[1] | 2618 | #ifdef __FreeBSD__
|
---|
[128] | 2619 | // tell the system that this is a 1.72m floppy
|
---|
| 2620 | system("/usr/sbin/fdcontrol -F 1722 /dev/fd0.1722");
|
---|
[1] | 2621 | #endif
|
---|
[1154] | 2622 | mr_asprintf(&bootdisk_dev, DEFAULT_1722MB_DISK);
|
---|
[128] | 2623 | } else if (does_device_exist(BACKUP_1722MB_DISK)) {
|
---|
[1154] | 2624 | mr_asprintf(&bootdisk_dev, "/dev/fd0H1722");
|
---|
[128] | 2625 | } else {
|
---|
[1107] | 2626 | mr_msg(1, "Warning - can't find a 1.72MB floppy device *sigh*");
|
---|
[1154] | 2627 | mr_asprintf(&bootdisk_dev, DEFAULT_1722MB_DISK);
|
---|
[128] | 2628 | }
|
---|
[1154] | 2629 | mr_asprintf(&datadisk_dev, "/dev/fd0");
|
---|
[128] | 2630 | if (!does_device_exist(datadisk_dev)) {
|
---|
[1107] | 2631 | mr_msg(1, "Warning - can't find a 1.44MB floppy device *sigh*");
|
---|
[128] | 2632 | }
|
---|
[1154] | 2633 | format_first = ask_me_yes_or_no
|
---|
[128] | 2634 | ("Do you want me to format the disks before I write to them?");
|
---|
[1] | 2635 |
|
---|
[1154] | 2636 | /* boot disk */
|
---|
[128] | 2637 | if (ask_me_OK_or_cancel("About to write boot disk")) {
|
---|
| 2638 | log_to_screen("Writing boot floppy");
|
---|
[1] | 2639 | #ifdef __FreeBSD__
|
---|
[1154] | 2640 | mr_asprintf(&tmp, "%s/mindi-kern.1722.img", imagesdir);
|
---|
[128] | 2641 | if (format_first) {
|
---|
| 2642 | format_disk(bootdisk_dev);
|
---|
| 2643 | }
|
---|
| 2644 | res += write_image_to_floppy(bootdisk_dev, tmp);
|
---|
[1154] | 2645 | mr_free(tmp);
|
---|
| 2646 |
|
---|
[128] | 2647 | if (ask_me_OK_or_cancel("About to write 1.44MB mfsroot disk")) {
|
---|
| 2648 | log_to_screen("Writing mfsroot floppy");
|
---|
| 2649 | if (format_first) {
|
---|
| 2650 | format_disk(datadisk_dev);
|
---|
| 2651 | }
|
---|
[1154] | 2652 | mr_asprintf(&tmp, "%s/mindi-mfsroot.1440.img", imagesdir);
|
---|
[128] | 2653 | write_image_to_floppy(datadisk_dev, tmp);
|
---|
[1154] | 2654 | mr_free(tmp);
|
---|
[128] | 2655 | }
|
---|
[1] | 2656 | #else
|
---|
[1154] | 2657 | mr_asprintf(&bootdisk_file, "%s/mindi-bootroot.1722.img", imagesdir);
|
---|
[128] | 2658 | if (does_file_exist(bootdisk_file)) {
|
---|
| 2659 | if (format_first) {
|
---|
| 2660 | format_disk(bootdisk_dev);
|
---|
| 2661 | }
|
---|
| 2662 | res += write_image_to_floppy(bootdisk_dev, bootdisk_file);
|
---|
| 2663 | } else {
|
---|
[1154] | 2664 | mr_free(bootdisk_file);
|
---|
| 2665 | mr_asprintf(&bootdisk_file, "%s/mindi-boot.1440.img", imagesdir);
|
---|
| 2666 | mr_asprintf(&rootdisk_file, "%s/mindi-root.1440.img", imagesdir);
|
---|
[128] | 2667 | root_disk_exists = TRUE;
|
---|
| 2668 | if (!does_file_exist(rootdisk_file)
|
---|
| 2669 | || !does_file_exist(bootdisk_file)) {
|
---|
| 2670 | popup_and_OK
|
---|
| 2671 | ("Cannot write boot/root floppies. Files not found.");
|
---|
| 2672 | log_to_screen
|
---|
| 2673 | ("Failed to find boot/root floppy images. Oh dear.");
|
---|
[1154] | 2674 | mr_free(bootdisk_file);
|
---|
| 2675 | mr_free(rootdisk_file);
|
---|
| 2676 | mr_free(bootdisk_dev);
|
---|
[128] | 2677 | return (1);
|
---|
| 2678 | }
|
---|
| 2679 | if (format_first) {
|
---|
| 2680 | format_disk(datadisk_dev);
|
---|
| 2681 | }
|
---|
| 2682 | res += write_image_to_floppy(datadisk_dev, bootdisk_file);
|
---|
| 2683 | if (ask_me_OK_or_cancel("About to write root disk")) {
|
---|
| 2684 | log_to_screen("Writing root floppy");
|
---|
| 2685 | if (format_first) {
|
---|
| 2686 | format_disk(datadisk_dev);
|
---|
| 2687 | }
|
---|
[1154] | 2688 | mr_asprintf(&tmp, "cat %s > %s", rootdisk_file, datadisk_dev);
|
---|
[1107] | 2689 | mr_msg(1, "tmp = '%s'", tmp);
|
---|
[128] | 2690 | res +=
|
---|
| 2691 | run_external_binary_with_percentage_indicator_NEW
|
---|
| 2692 | ("Writing root floppy", tmp);
|
---|
[1] | 2693 | // res += write_image_to_floppy (datadisk_dev, rootdisk_file);
|
---|
[1154] | 2694 | mr_free(tmp);
|
---|
[128] | 2695 | }
|
---|
[1154] | 2696 | mr_free(rootdisk_file);
|
---|
| 2697 |
|
---|
[128] | 2698 | }
|
---|
[1154] | 2699 | mr_free(bootdisk_file);
|
---|
[1] | 2700 | #endif
|
---|
| 2701 | }
|
---|
[1154] | 2702 | mr_free(bootdisk_dev);
|
---|
| 2703 |
|
---|
[128] | 2704 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 2705 | log_to_screen
|
---|
| 2706 | ("FYI, the data disks are stored on tape/CD for your convenience.");
|
---|
| 2707 | return (0);
|
---|
[1] | 2708 | }
|
---|
[128] | 2709 | for (i = 1; i < 99; i++) {
|
---|
[1154] | 2710 | mr_asprintf(&tmp, "%s/mindi-data-%d.img", imagesdir, i);
|
---|
[1107] | 2711 | mr_msg(3, tmp);
|
---|
[128] | 2712 | if (!does_file_exist(tmp)) {
|
---|
[1107] | 2713 | mr_msg(3, "...not found");
|
---|
[128] | 2714 | break;
|
---|
| 2715 | }
|
---|
[1154] | 2716 | mr_asprintf(&comment, "About to write data disk #%d", i);
|
---|
[128] | 2717 | if (ask_me_OK_or_cancel(comment)) {
|
---|
[1154] | 2718 | mr_free(comment);
|
---|
| 2719 | mr_asprintf(&comment, "Writing data disk #%3d", i);
|
---|
[128] | 2720 | log_to_screen(comment);
|
---|
[1154] | 2721 | mr_free(comment);
|
---|
[128] | 2722 | if (format_first) {
|
---|
| 2723 | res += format_disk(datadisk_dev);
|
---|
| 2724 | }
|
---|
| 2725 | res += write_image_to_floppy(datadisk_dev, tmp);
|
---|
| 2726 | }
|
---|
[1154] | 2727 | mr_free(tmp);
|
---|
[128] | 2728 | }
|
---|
[1154] | 2729 | /* In case of break free mem as well */
|
---|
[1080] | 2730 | mr_free(tmp);
|
---|
| 2731 | mr_free(datadisk_dev);
|
---|
[128] | 2732 | return (res);
|
---|
[1] | 2733 | }
|
---|
| 2734 |
|
---|
| 2735 |
|
---|
| 2736 | /**
|
---|
| 2737 | * Wrapper around @c offer_to_write_floppies().
|
---|
| 2738 | * @param bkpinfo The backup information structure. Used only
|
---|
| 2739 | * in the call to @c offer_to_write_floppies().
|
---|
| 2740 | * @return 0 if the boot floppies were found (not necessarily written OK),
|
---|
| 2741 | * 1 otherwise.
|
---|
| 2742 | * @see offer_to_write_floppies
|
---|
| 2743 | * @ingroup MLarchiveGroup
|
---|
| 2744 | */
|
---|
| 2745 |
|
---|
[1154] | 2746 | int offer_to_write_boot_floppies_to_physical_disks(struct s_bkpinfo *bkpinfo) {
|
---|
| 2747 |
|
---|
[128] | 2748 | int res = 0;
|
---|
[1] | 2749 |
|
---|
[128] | 2750 | assert(bkpinfo != NULL);
|
---|
[1] | 2751 |
|
---|
[128] | 2752 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
| 2753 | "Writing boot+data floppy images to disk");
|
---|
[1] | 2754 |
|
---|
[128] | 2755 | if (!bkpinfo->nonbootable_backup) {
|
---|
[1] | 2756 | #ifdef __FreeBSD__
|
---|
[1044] | 2757 | if (!does_file_exist("/var/cache/mindi/mindi-kern.1722.img"))
|
---|
[1] | 2758 | #else
|
---|
[1044] | 2759 | if (!does_file_exist("/var/cache/mindi/mindi-bootroot.1722.img")
|
---|
[1154] | 2760 | && !does_file_exist("/var/cache/mindi/mindi-boot.1440.img")
|
---|
| 2761 | && !does_file_exist("/var/cache/mindi/mindi-boot.2880.img")
|
---|
| 2762 | && !does_file_exist("/var/cache/mindi/mindi-boot.5760.img"))
|
---|
[1] | 2763 | #endif
|
---|
[128] | 2764 | {
|
---|
| 2765 | mvaddstr_and_log_it(g_currentY++, 74, "No Imgs");
|
---|
[1044] | 2766 | if (does_file_exist("/var/cache/mindi/mondorescue.iso")) {
|
---|
[128] | 2767 | popup_and_OK
|
---|
[1044] | 2768 | ("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] | 2769 | res++;
|
---|
| 2770 | }
|
---|
| 2771 | } else {
|
---|
[1044] | 2772 | offer_to_write_floppies(bkpinfo, "/var/cache/mindi");
|
---|
[128] | 2773 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
| 2774 | }
|
---|
| 2775 | } else {
|
---|
| 2776 | popup_and_OK
|
---|
| 2777 | ("Since you opted for a nonbootable backup, no boot floppies were created.");
|
---|
| 2778 | }
|
---|
| 2779 |
|
---|
| 2780 | return (res);
|
---|
[1] | 2781 | }
|
---|
| 2782 |
|
---|
| 2783 |
|
---|
| 2784 | /**
|
---|
| 2785 | * @addtogroup LLarchiveGroup
|
---|
| 2786 | * @{
|
---|
| 2787 | */
|
---|
| 2788 | /**
|
---|
| 2789 | * Function pointer to an appropriate @c move_files_to_stream routine.
|
---|
| 2790 | * You can set this to your own function (for example, one to
|
---|
| 2791 | * transfer files over the network) or leave it as is.
|
---|
| 2792 | */
|
---|
[128] | 2793 | int (*move_files_to_stream) (struct s_bkpinfo *, char *, ...) =
|
---|
| 2794 | _move_files_to_stream;
|
---|
[1] | 2795 |
|
---|
| 2796 | /**
|
---|
| 2797 | * Copy some files to tape.
|
---|
| 2798 | * This function copies the files specified as parameters into the tape stream.
|
---|
| 2799 | *
|
---|
| 2800 | * @param bkpinfo The backup information structure. Used only in the call to
|
---|
| 2801 | * @c write_file_to_stream_from_file().
|
---|
| 2802 | *
|
---|
| 2803 | * @param files_to_add The files to copy to the tape stream.
|
---|
| 2804 | * @warning The list of @c files_to_add must be terminated with @c NULL.
|
---|
| 2805 | * @note Files may be split across multiple tapes if necessary.
|
---|
| 2806 | *
|
---|
| 2807 | * @return The number of errors encountered (0 for success)
|
---|
| 2808 | */
|
---|
| 2809 | int
|
---|
[128] | 2810 | _move_files_to_stream(struct s_bkpinfo *bkpinfo, char *files_to_add, ...)
|
---|
[1] | 2811 | {
|
---|
| 2812 |
|
---|
[128] | 2813 | /*@ int ************************************************************ */
|
---|
| 2814 | int retval = 0;
|
---|
[1] | 2815 | int res = 0;
|
---|
[128] | 2816 | /*@ buffers ******************************************************** */
|
---|
[1] | 2817 |
|
---|
[128] | 2818 | /*@ char *********************************************************** */
|
---|
[1] | 2819 | char start_chr;
|
---|
| 2820 | char stop_chr;
|
---|
[1154] | 2821 | char *curr_file = NULL;
|
---|
| 2822 | char *cf = NULL;
|
---|
[128] | 2823 | /*@ long long ****************************************************** */
|
---|
[684] | 2824 | off_t length_of_incoming_file = (off_t)0;
|
---|
[128] | 2825 | t_archtype type;
|
---|
| 2826 | va_list ap;
|
---|
[1] | 2827 |
|
---|
[128] | 2828 | assert(bkpinfo != NULL);
|
---|
| 2829 | va_start(ap, files_to_add);
|
---|
| 2830 | for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
|
---|
| 2831 | if (!cf) {
|
---|
| 2832 | continue;
|
---|
| 2833 | }
|
---|
[1154] | 2834 | mr_asprintf(&curr_file, cf);
|
---|
[128] | 2835 | if (!does_file_exist(curr_file)) {
|
---|
[1107] | 2836 | mr_msg(1,
|
---|
[128] | 2837 | "Warning - you're trying to add a non-existent file - '%s' to the tape",
|
---|
| 2838 | curr_file);
|
---|
| 2839 | }
|
---|
[1154] | 2840 | /* create header chars */
|
---|
[128] | 2841 | start_chr = BLK_START_AN_AFIO_OR_SLICE;
|
---|
| 2842 | stop_chr = BLK_STOP_AN_AFIO_OR_SLICE;
|
---|
[1154] | 2843 | /* ask for new tape if necessary */
|
---|
[128] | 2844 | length_of_incoming_file = length_of_file(curr_file);
|
---|
| 2845 | write_header_block_to_stream(length_of_incoming_file, curr_file,
|
---|
| 2846 | start_chr);
|
---|
| 2847 | if (strstr(curr_file, ".afio.") || strstr(curr_file, ".star.")) {
|
---|
| 2848 | type = fileset;
|
---|
| 2849 | } else if (strstr(curr_file, "slice")) {
|
---|
| 2850 | type = biggieslice;
|
---|
| 2851 | } else {
|
---|
| 2852 | type = other;
|
---|
| 2853 | }
|
---|
| 2854 | res = write_file_to_stream_from_file(bkpinfo, curr_file);
|
---|
| 2855 | retval += res;
|
---|
| 2856 | unlink(curr_file);
|
---|
[1154] | 2857 | mr_free(curr_file);
|
---|
| 2858 | /* write closing header */
|
---|
[684] | 2859 | write_header_block_to_stream((off_t)0, "finished-writing-file", stop_chr);
|
---|
[128] | 2860 | }
|
---|
| 2861 | va_end(ap);
|
---|
[1] | 2862 |
|
---|
[128] | 2863 | if (retval) {
|
---|
[1107] | 2864 | mr_msg(1,
|
---|
[128] | 2865 | "Warning - errors occurred while I was adding file to tape");
|
---|
| 2866 | }
|
---|
| 2867 | return (retval);
|
---|
[1] | 2868 | }
|
---|
| 2869 |
|
---|
| 2870 | /* @} - end of LLarchiveGroup */
|
---|
| 2871 |
|
---|
| 2872 |
|
---|
| 2873 | /**
|
---|
| 2874 | * @addtogroup utilityGroup
|
---|
| 2875 | * @{
|
---|
| 2876 | */
|
---|
| 2877 | /**
|
---|
| 2878 | * Make sure the user has a valid CD-R(W) in the CD drive.
|
---|
| 2879 | * @param cdrw_dev Set to the CD-R(W) device checked.
|
---|
| 2880 | * @param keep_looping If TRUE, keep pestering user until they insist
|
---|
| 2881 | * or insert a correct CD; if FALSE, only check once.
|
---|
| 2882 | * @return 0 (there was an OK CD in the drive) or 1 (there wasn't).
|
---|
| 2883 | */
|
---|
[128] | 2884 | int interrogate_disk_currently_in_cdrw_drive(char *cdrw_dev,
|
---|
| 2885 | bool keep_looping)
|
---|
[1] | 2886 | {
|
---|
[128] | 2887 | char *tmp;
|
---|
| 2888 | int res = 0;
|
---|
| 2889 | char *bkp;
|
---|
| 2890 | char *cdrecord;
|
---|
[1] | 2891 |
|
---|
[128] | 2892 | malloc_string(tmp);
|
---|
| 2893 | malloc_string(bkp);
|
---|
| 2894 | malloc_string(cdrecord);
|
---|
| 2895 | strcpy(bkp, cdrw_dev);
|
---|
| 2896 | if (find_cdrw_device(cdrw_dev)) {
|
---|
| 2897 | strcpy(cdrw_dev, bkp);
|
---|
| 2898 | } else {
|
---|
| 2899 | if (!system("which cdrecord > /dev/null 2> /dev/null")) {
|
---|
| 2900 | sprintf(cdrecord, "cdrecord dev=%s -atip", cdrw_dev);
|
---|
| 2901 | } else if (!system("which dvdrecord > /dev/null 2> /dev/null")) {
|
---|
| 2902 | sprintf(cdrecord, "cdrecord dev=%s -atip", cdrw_dev);
|
---|
| 2903 | } else {
|
---|
| 2904 | cdrecord[0] = '\0';
|
---|
[1107] | 2905 | mr_msg(2, "Oh well. I guess I'll just pray then.");
|
---|
[128] | 2906 | }
|
---|
| 2907 | if (cdrecord[0]) {
|
---|
| 2908 | if (!keep_looping) {
|
---|
| 2909 | retract_CD_tray_and_defeat_autorun();
|
---|
| 2910 | res = run_program_and_log_output(cdrecord, 5);
|
---|
| 2911 | } else {
|
---|
| 2912 | while ((res = run_program_and_log_output(cdrecord, 5))) {
|
---|
| 2913 | retract_CD_tray_and_defeat_autorun();
|
---|
| 2914 | if (ask_me_yes_or_no
|
---|
| 2915 | ("Unable to examine CD. Are you sure this is a valid CD-R(W) CD?"))
|
---|
| 2916 | {
|
---|
[1107] | 2917 | mr_msg(1, "Well, he insisted...");
|
---|
[128] | 2918 | break;
|
---|
| 2919 | }
|
---|
| 2920 | }
|
---|
| 2921 | }
|
---|
| 2922 | }
|
---|
| 2923 | }
|
---|
[1] | 2924 | // retract_CD_tray_and_defeat_autorun();
|
---|
[1080] | 2925 | mr_free(tmp);
|
---|
| 2926 | mr_free(cdrecord);
|
---|
| 2927 | mr_free(bkp);
|
---|
[128] | 2928 | return (res);
|
---|
[1] | 2929 | }
|
---|
| 2930 |
|
---|
| 2931 |
|
---|
| 2932 | /**
|
---|
| 2933 | * Asks the user to put a CD-R(W) in the drive.
|
---|
| 2934 | * @param ask_for_one_if_more_than_this (unused)
|
---|
| 2935 | * @param pmountable If non-NULL, pointed-to value is set to TRUE if the CD is mountable, FALSE otherwise.
|
---|
| 2936 | */
|
---|
| 2937 | void
|
---|
[128] | 2938 | pause_and_ask_for_cdr(int ask_for_one_if_more_than_this, bool * pmountable)
|
---|
[1] | 2939 | {
|
---|
| 2940 |
|
---|
[128] | 2941 | /*@ buffers ********************************************* */
|
---|
[1154] | 2942 | char *tmp = NULL;
|
---|
| 2943 | char *szmsg = NULL;
|
---|
| 2944 | char *cdrom_dev = NULL;
|
---|
| 2945 | char *cdrw_dev = NULL;
|
---|
| 2946 | char *our_serial_str = NULL;
|
---|
[128] | 2947 | bool ok_go_ahead_burn_it;
|
---|
| 2948 | int cd_number = -1;
|
---|
| 2949 | int attempt_to_mount_returned_this = 999;
|
---|
[1154] | 2950 | char *mtpt = NULL;
|
---|
| 2951 | char *szcdno = NULL;
|
---|
| 2952 | char *szserfname = NULL;
|
---|
| 2953 | char *szunmount = NULL;
|
---|
[1] | 2954 |
|
---|
[128] | 2955 | malloc_string(tmp);
|
---|
| 2956 | malloc_string(szmsg);
|
---|
| 2957 | malloc_string(cdrom_dev);
|
---|
| 2958 | malloc_string(cdrw_dev);
|
---|
| 2959 | malloc_string(mtpt);
|
---|
| 2960 | malloc_string(szcdno);
|
---|
| 2961 | malloc_string(szserfname);
|
---|
| 2962 | malloc_string(our_serial_str);
|
---|
| 2963 | malloc_string(szunmount);
|
---|
[1] | 2964 |
|
---|
[128] | 2965 | sprintf(szmsg, "I am about to burn %s #%d",
|
---|
| 2966 | media_descriptor_string(g_backup_media_type),
|
---|
| 2967 | g_current_media_number);
|
---|
| 2968 | log_to_screen(szmsg);
|
---|
| 2969 | if (g_current_media_number < ask_for_one_if_more_than_this) {
|
---|
| 2970 | return;
|
---|
| 2971 | }
|
---|
| 2972 | log_to_screen("Scanning CD-ROM drive...");
|
---|
| 2973 | sprintf(mtpt, "/tmp/cd.mtpt.%ld.%ld", (long int) random(),
|
---|
| 2974 | (long int) random());
|
---|
| 2975 | make_hole_for_dir(mtpt);
|
---|
[1] | 2976 |
|
---|
[128] | 2977 | gotos_make_me_puke:
|
---|
| 2978 | ok_go_ahead_burn_it = TRUE;
|
---|
| 2979 | if (!find_cdrom_device(cdrom_dev, FALSE)) {
|
---|
[1] | 2980 | /* When enabled, it made CD eject-and-retract when wrong CD inserted.. Weird
|
---|
[1107] | 2981 | mr_msg(2, "paafcd: Retracting CD-ROM drive if possible" );
|
---|
[1] | 2982 | retract_CD_tray_and_defeat_autorun();
|
---|
| 2983 | */
|
---|
[128] | 2984 | sprintf(tmp, "umount %s", cdrom_dev);
|
---|
| 2985 | run_program_and_log_output(tmp, 1);
|
---|
| 2986 | sprintf(szcdno, "%s/archives/THIS-CD-NUMBER", mtpt);
|
---|
| 2987 | sprintf(szserfname, "%s/archives/SERIAL-STRING", mtpt);
|
---|
| 2988 | sprintf(szunmount, "umount %s", mtpt);
|
---|
| 2989 | cd_number = -1;
|
---|
| 2990 | our_serial_str[0] = '\0';
|
---|
| 2991 | sprintf(tmp, "mount %s %s", cdrom_dev, mtpt);
|
---|
| 2992 | if ((attempt_to_mount_returned_this =
|
---|
| 2993 | run_program_and_log_output(tmp, 1))) {
|
---|
[1107] | 2994 | mr_msg(4, "Failed to mount %s at %s", cdrom_dev, mtpt);
|
---|
[128] | 2995 | log_to_screen("If there's a CD/DVD in the drive, it's blank.");
|
---|
| 2996 | /*
|
---|
| 2997 | if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE))
|
---|
| 2998 | {
|
---|
| 2999 | ok_go_ahead_burn_it = FALSE;
|
---|
| 3000 | log_to_screen("There isn't a writable CD/DVD in the drive.");
|
---|
| 3001 | }
|
---|
| 3002 | else
|
---|
| 3003 | {
|
---|
| 3004 | log_to_screen("Confirmed. There is a blank CD/DVD in the drive.");
|
---|
| 3005 | }
|
---|
| 3006 | */
|
---|
| 3007 | } else if (!does_file_exist(szcdno)
|
---|
| 3008 | || !does_file_exist(szserfname)) {
|
---|
| 3009 | log_to_screen
|
---|
| 3010 | ("%s has data on it but it's probably not a Mondo CD.",
|
---|
| 3011 | media_descriptor_string(g_backup_media_type));
|
---|
| 3012 | } else {
|
---|
| 3013 | log_to_screen("%s found in drive. It's a Mondo disk.",
|
---|
| 3014 | media_descriptor_string(g_backup_media_type));
|
---|
| 3015 | cd_number = atoi(last_line_of_file(szcdno));
|
---|
| 3016 | sprintf(tmp, "cat %s 2> /dev/null", szserfname);
|
---|
| 3017 | strcpy(our_serial_str,
|
---|
| 3018 | call_program_and_get_last_line_of_output(tmp));
|
---|
| 3019 | // FIXME - should be able to use last_line_of_file(), surely?
|
---|
| 3020 | }
|
---|
| 3021 | run_program_and_log_output(szunmount, 1);
|
---|
[1107] | 3022 | mr_msg(2, "paafcd: cd_number = %d", cd_number);
|
---|
| 3023 | mr_msg(2, "our serial str = %s; g_serial_string = %s",
|
---|
[128] | 3024 | our_serial_str, g_serial_string);
|
---|
| 3025 | if (cd_number > 0 && !strcmp(our_serial_str, g_serial_string)) {
|
---|
[1107] | 3026 | mr_msg(2, "This %s is part of this backup set!",
|
---|
[128] | 3027 | media_descriptor_string(g_backup_media_type));
|
---|
| 3028 | ok_go_ahead_burn_it = FALSE;
|
---|
| 3029 | if (cd_number == g_current_media_number - 1) {
|
---|
| 3030 | log_to_screen
|
---|
| 3031 | ("I think you've left the previous %s in the drive.",
|
---|
| 3032 | media_descriptor_string(g_backup_media_type));
|
---|
| 3033 | } else {
|
---|
| 3034 | log_to_screen
|
---|
| 3035 | ("Please remove this %s. It is part of the backup set you're making now.",
|
---|
| 3036 | media_descriptor_string(g_backup_media_type));
|
---|
| 3037 | }
|
---|
| 3038 | } else {
|
---|
| 3039 | log_to_screen("...but not part of _our_ backup set.");
|
---|
| 3040 | }
|
---|
| 3041 | } else {
|
---|
[1107] | 3042 | mr_msg(2,
|
---|
[128] | 3043 | "paafcd: Can't find CD-ROM drive. Perhaps it has a blank %s in it?",
|
---|
| 3044 | media_descriptor_string(g_backup_media_type));
|
---|
| 3045 | if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE)) {
|
---|
| 3046 | ok_go_ahead_burn_it = FALSE;
|
---|
| 3047 | log_to_screen("There isn't a writable %s in the drive.",
|
---|
| 3048 | media_descriptor_string(g_backup_media_type));
|
---|
| 3049 | }
|
---|
[1] | 3050 | }
|
---|
| 3051 |
|
---|
| 3052 | /*
|
---|
| 3053 | if (g_current_media_number > ask_for_one_if_more_than_this)
|
---|
| 3054 | {
|
---|
| 3055 | ok_go_ahead_burn_it = FALSE;
|
---|
| 3056 | log_it("paafcd: %d > %d, so I'll definitely pause.", g_current_media_number > ask_for_one_if_more_than_this);
|
---|
| 3057 | }
|
---|
| 3058 | */
|
---|
| 3059 |
|
---|
[128] | 3060 | if (!ok_go_ahead_burn_it) {
|
---|
| 3061 | eject_device(cdrom_dev);
|
---|
| 3062 | sprintf(tmp,
|
---|
| 3063 | "I am about to burn %s #%d of the backup set. Please insert %s and press Enter.",
|
---|
| 3064 | media_descriptor_string(g_backup_media_type),
|
---|
| 3065 | g_current_media_number,
|
---|
| 3066 | media_descriptor_string(g_backup_media_type));
|
---|
| 3067 | popup_and_OK(tmp);
|
---|
| 3068 | goto gotos_make_me_puke;
|
---|
| 3069 | } else {
|
---|
[1107] | 3070 | mr_msg(2, "paafcd: OK, going ahead and burning it.");
|
---|
[128] | 3071 | }
|
---|
[1] | 3072 |
|
---|
[1107] | 3073 | mr_msg(2,
|
---|
[128] | 3074 | "paafcd: OK, I assume I have a blank/reusable %s in the drive...",
|
---|
| 3075 | media_descriptor_string(g_backup_media_type));
|
---|
[1] | 3076 |
|
---|
[128] | 3077 | // if (ask_for_one_if_more_than_this>1) { popup_and_OK(szmsg); }
|
---|
[1] | 3078 |
|
---|
[128] | 3079 | log_to_screen("Proceeding w/ %s in drive.",
|
---|
| 3080 | media_descriptor_string(g_backup_media_type));
|
---|
[1080] | 3081 | mr_free(tmp);
|
---|
| 3082 | mr_free(szmsg);
|
---|
| 3083 | mr_free(cdrom_dev);
|
---|
| 3084 | mr_free(cdrw_dev);
|
---|
| 3085 | mr_free(mtpt);
|
---|
| 3086 | mr_free(szcdno);
|
---|
| 3087 | mr_free(szserfname);
|
---|
| 3088 | mr_free(our_serial_str);
|
---|
| 3089 | mr_free(szunmount);
|
---|
[128] | 3090 | if (pmountable) {
|
---|
| 3091 | if (attempt_to_mount_returned_this) {
|
---|
| 3092 | *pmountable = FALSE;
|
---|
| 3093 | } else {
|
---|
| 3094 | *pmountable = TRUE;
|
---|
| 3095 | }
|
---|
| 3096 | }
|
---|
[1] | 3097 |
|
---|
| 3098 | }
|
---|
| 3099 |
|
---|
| 3100 |
|
---|
| 3101 | /**
|
---|
| 3102 | * Set the <tt>N</tt>th bit of @c array to @c true_or_false.
|
---|
| 3103 | * @param array The bit array (as a @c char pointer).
|
---|
| 3104 | * @param N The bit number to set or reset.
|
---|
| 3105 | * @param true_or_false If TRUE then set bit @c N, if FALSE then reset bit @c N.
|
---|
| 3106 | * @see get_bit_N_of_array
|
---|
| 3107 | */
|
---|
[128] | 3108 | void set_bit_N_of_array(char *array, int N, bool true_or_false)
|
---|
[1] | 3109 | {
|
---|
[128] | 3110 | int bit_number;
|
---|
| 3111 | int mask, orig_val, to_add;
|
---|
| 3112 | int element_number;
|
---|
[1] | 3113 |
|
---|
[128] | 3114 | assert(array != NULL);
|
---|
[1] | 3115 |
|
---|
[128] | 3116 | element_number = N / 8;
|
---|
| 3117 | bit_number = N % 8;
|
---|
| 3118 | to_add = (1 << bit_number);
|
---|
| 3119 | mask = 255 - to_add;
|
---|
| 3120 | orig_val = array[element_number] & mask;
|
---|
| 3121 | // log_it("array[%d]=%02x; %02x&%02x = %02x", element_number, array[element_number], mask, orig_val);
|
---|
| 3122 | if (true_or_false) {
|
---|
| 3123 | array[element_number] = orig_val | to_add;
|
---|
| 3124 | }
|
---|
[1] | 3125 | }
|
---|
| 3126 |
|
---|
| 3127 | /* @} - end of utilityGroup */
|
---|
| 3128 |
|
---|
| 3129 |
|
---|
| 3130 | /**
|
---|
| 3131 | * Chop up @c filename.
|
---|
| 3132 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 3133 | * - @c backup_media_type
|
---|
| 3134 | * - @c compression_level
|
---|
| 3135 | * - @c optimal_set_size
|
---|
| 3136 | * - @c tmpdir
|
---|
| 3137 | * - @c use_lzo
|
---|
| 3138 | * - @c zip_exe
|
---|
| 3139 | * - @c zip_suffix
|
---|
| 3140 | *
|
---|
| 3141 | * @param biggie_filename The file to chop up.
|
---|
[296] | 3142 | * @param ntfsprog_fifo The FIFO to ntfsclone if this is an imagedev, NULL otherwise.
|
---|
[1] | 3143 | * @param biggie_file_number The sequence number of this biggie file (starting from 0).
|
---|
| 3144 | * @param noof_biggie_files The number of biggie files there are total.
|
---|
| 3145 | * @return The number of errors encountered (0 for success)
|
---|
| 3146 | * @see make_slices_and_images
|
---|
| 3147 | * @ingroup LLarchiveGroup
|
---|
| 3148 | */
|
---|
| 3149 | int
|
---|
[541] | 3150 | slice_up_file_etc(struct s_bkpinfo *bkpinfo, char *biggie_filename,
|
---|
[296] | 3151 | char *ntfsprog_fifo, long biggie_file_number,
|
---|
| 3152 | long noof_biggie_files, bool use_ntfsprog)
|
---|
[1] | 3153 | {
|
---|
| 3154 |
|
---|
[128] | 3155 | /*@ buffers ************************************************** */
|
---|
[1154] | 3156 | char *tmp = NULL;
|
---|
| 3157 | char *checksum_line = NULL;
|
---|
| 3158 | char *command = NULL;
|
---|
| 3159 | char *tempblock = NULL;
|
---|
| 3160 | char *curr_slice_fname_uncompressed = NULL;
|
---|
| 3161 | char *curr_slice_fname_compressed = NULL;
|
---|
| 3162 | char *file_to_archive = NULL;
|
---|
| 3163 | char *file_to_openin = NULL;
|
---|
[128] | 3164 | /*@ pointers ************************************************** */
|
---|
[1154] | 3165 | char *pB = NULL;
|
---|
| 3166 | FILE *fin = NULL;
|
---|
| 3167 | FILE *fout = NULL;
|
---|
[1] | 3168 |
|
---|
[128] | 3169 | /*@ bool ****************************************************** */
|
---|
| 3170 | bool finished = FALSE;
|
---|
[1] | 3171 |
|
---|
[128] | 3172 | /*@ long ****************************************************** */
|
---|
| 3173 | size_t blksize = 0;
|
---|
| 3174 | long slice_num = 0;
|
---|
| 3175 | long i;
|
---|
| 3176 | long optimal_set_size;
|
---|
| 3177 | bool should_I_compress_slices;
|
---|
[1154] | 3178 | char *suffix = NULL; // for compressed slices
|
---|
[1] | 3179 |
|
---|
[128] | 3180 | /*@ long long ************************************************** */
|
---|
[684] | 3181 | off_t totalread = (off_t)0;
|
---|
| 3182 | off_t totallength = (off_t)0;
|
---|
| 3183 | off_t length;
|
---|
[1] | 3184 |
|
---|
[128] | 3185 | /*@ int ******************************************************** */
|
---|
| 3186 | int retval = 0;
|
---|
| 3187 | int res = 0;
|
---|
[1154] | 3188 | size_t n = 0;
|
---|
[1] | 3189 |
|
---|
[128] | 3190 | /*@ structures ************************************************** */
|
---|
| 3191 | struct s_filename_and_lstat_info biggiestruct;
|
---|
[1] | 3192 | // struct stat statbuf;
|
---|
| 3193 |
|
---|
[128] | 3194 | assert(bkpinfo != NULL);
|
---|
| 3195 | assert_string_is_neither_NULL_nor_zerolength(biggie_filename);
|
---|
[1] | 3196 |
|
---|
[128] | 3197 | biggiestruct.for_backward_compatibility = '\n';
|
---|
[296] | 3198 | biggiestruct.use_ntfsprog = use_ntfsprog;
|
---|
[128] | 3199 | optimal_set_size = bkpinfo->optimal_set_size;
|
---|
[1] | 3200 |
|
---|
[128] | 3201 | if (optimal_set_size < 999) {
|
---|
| 3202 | fatal_error("bkpinfo->optimal_set_size is insanely small");
|
---|
| 3203 | }
|
---|
[296] | 3204 | if (ntfsprog_fifo) {
|
---|
| 3205 | file_to_openin = ntfsprog_fifo;
|
---|
[1155] | 3206 | mr_asprintf(&checksum_line, "IGNORE");
|
---|
[1107] | 3207 | mr_msg(2,
|
---|
[128] | 3208 | "Not calculating checksum for %s: it would take too long",
|
---|
| 3209 | biggie_filename);
|
---|
[296] | 3210 | if ( !find_home_of_exe("ntfsresize")) {
|
---|
| 3211 | fatal_error("ntfsresize not found");
|
---|
| 3212 | }
|
---|
[1155] | 3213 | mr_asprintf(&command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", biggie_filename);
|
---|
[296] | 3214 | log_it("command = %s", command);
|
---|
[1155] | 3215 | mr_asprintf(&tmp, call_program_and_get_last_line_of_output(command));
|
---|
| 3216 | mr_free(command);
|
---|
| 3217 |
|
---|
[296] | 3218 | log_it("res of it = %s", tmp);
|
---|
[684] | 3219 | totallength = (off_t)atoll(tmp);
|
---|
[1155] | 3220 | mr_free(tmp);
|
---|
[128] | 3221 | } else {
|
---|
| 3222 | file_to_openin = biggie_filename;
|
---|
[693] | 3223 | if (strchr(biggie_filename,'\'') != NULL) {
|
---|
[1155] | 3224 | mr_asprintf(&command, "md5sum \"%s\"", biggie_filename);
|
---|
[693] | 3225 | } else {
|
---|
[1155] | 3226 | mr_asprintf(&command, "md5sum '%s'", biggie_filename);
|
---|
[693] | 3227 | }
|
---|
[128] | 3228 | if (!(fin = popen(command, "r"))) {
|
---|
| 3229 | log_OS_error("Unable to popen-in command");
|
---|
[1155] | 3230 | mr_free(command);
|
---|
[128] | 3231 | return (1);
|
---|
| 3232 | }
|
---|
[1155] | 3233 | mr_free(command);
|
---|
| 3234 | mr_getline(&checksum_line, &n, fin);
|
---|
[128] | 3235 | pclose(fin);
|
---|
[167] | 3236 | totallength = length_of_file (biggie_filename);
|
---|
[128] | 3237 | }
|
---|
| 3238 | lstat(biggie_filename, &biggiestruct.properties);
|
---|
[1155] | 3239 | if (strlen(biggie_filename) <= MAX_STR_LEN) {
|
---|
| 3240 | strcpy(biggiestruct.filename, biggie_filename);
|
---|
| 3241 | } else {
|
---|
| 3242 | fatal_error("biggie_filename too big");
|
---|
| 3243 | }
|
---|
[128] | 3244 | pB = strchr(checksum_line, ' ');
|
---|
| 3245 | if (!pB) {
|
---|
| 3246 | pB = strchr(checksum_line, '\t');
|
---|
| 3247 | }
|
---|
| 3248 | if (pB) {
|
---|
| 3249 | *pB = '\0';
|
---|
| 3250 | }
|
---|
[1155] | 3251 | if (strlen(checksum_line) <= 64) {
|
---|
| 3252 | strcpy(biggiestruct.checksum, checksum_line);
|
---|
| 3253 | } else {
|
---|
| 3254 | fatal_error("checksum_line too big");
|
---|
| 3255 | }
|
---|
| 3256 | mr_free(checksum_line);
|
---|
[1] | 3257 |
|
---|
[1155] | 3258 | mr_asprintf(&tmp, slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, ""));
|
---|
[1164] | 3259 | fout = mr_fopen(tmp, "w");
|
---|
[1155] | 3260 | mr_free(tmp);
|
---|
| 3261 |
|
---|
[128] | 3262 | (void) fwrite((void *) &biggiestruct, 1, sizeof(biggiestruct), fout);
|
---|
[1164] | 3263 | mr_fclose(fout);
|
---|
[128] | 3264 | length = totallength / optimal_set_size / 1024;
|
---|
[1107] | 3265 | mr_msg(1, "Opening in %s; slicing it and writing to CD/tape",
|
---|
[128] | 3266 | file_to_openin);
|
---|
| 3267 | if (!(fin = fopen(file_to_openin, "r"))) {
|
---|
| 3268 | log_OS_error("Unable to openin biggie_filename");
|
---|
[1155] | 3269 | mr_asprintf(&tmp, "Cannot archive bigfile '%s': not found",
|
---|
| 3270 | biggie_filename);
|
---|
[128] | 3271 | log_to_screen(tmp);
|
---|
[1080] | 3272 | mr_free(tmp);
|
---|
[128] | 3273 | return (1);
|
---|
| 3274 | }
|
---|
| 3275 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 3276 | res =
|
---|
| 3277 | move_files_to_stream(bkpinfo,
|
---|
| 3278 | slice_fname(biggie_file_number, 0,
|
---|
| 3279 | bkpinfo->tmpdir, ""), NULL);
|
---|
| 3280 | } else {
|
---|
| 3281 | res =
|
---|
[541] | 3282 | move_files_to_cd(bkpinfo,
|
---|
[128] | 3283 | slice_fname(biggie_file_number, 0,
|
---|
| 3284 | bkpinfo->tmpdir, ""), NULL);
|
---|
| 3285 | }
|
---|
[1164] | 3286 | if (is_this_file_compressed(biggie_filename)
|
---|
| 3287 | || bkpinfo->compression_level == 0) {
|
---|
| 3288 | mr_asprintf(&suffix, "");
|
---|
| 3289 | should_I_compress_slices = FALSE;
|
---|
| 3290 | } else {
|
---|
| 3291 | mr_asprintf(&suffix, bkpinfo->zip_suffix);
|
---|
| 3292 | should_I_compress_slices = TRUE;
|
---|
| 3293 | }
|
---|
[128] | 3294 | i = bkpinfo->optimal_set_size / 256;
|
---|
| 3295 | for (slice_num = 1; !finished; slice_num++) {
|
---|
[1155] | 3296 | mr_asprintf(&curr_slice_fname_uncompressed,
|
---|
[128] | 3297 | slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir,
|
---|
| 3298 | ""));
|
---|
[1155] | 3299 | mr_asprintf(&curr_slice_fname_compressed,
|
---|
[128] | 3300 | slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir,
|
---|
| 3301 | suffix));
|
---|
[1] | 3302 |
|
---|
[1155] | 3303 | mr_asprintf(&tmp, percent_media_full_comment(bkpinfo));
|
---|
[128] | 3304 | update_progress_form(tmp);
|
---|
[1155] | 3305 | mr_free(tmp);
|
---|
| 3306 |
|
---|
[128] | 3307 | if (!(fout = fopen(curr_slice_fname_uncompressed, "w"))) {
|
---|
| 3308 | log_OS_error(curr_slice_fname_uncompressed);
|
---|
[1155] | 3309 | mr_free(curr_slice_fname_uncompressed);
|
---|
| 3310 | mr_free(curr_slice_fname_compressed);
|
---|
| 3311 | mr_free(suffix);
|
---|
[128] | 3312 | return (1);
|
---|
[1] | 3313 | }
|
---|
[1155] | 3314 | tempblock = mr_malloc(256 * 1024);
|
---|
[128] | 3315 | if ((i == bkpinfo->optimal_set_size / 256)
|
---|
| 3316 | && (totalread < 1.1 * totallength)) {
|
---|
| 3317 | for (i = 0; i < bkpinfo->optimal_set_size / 256; i++) {
|
---|
| 3318 | blksize = fread(tempblock, 1, 256 * 1024, fin);
|
---|
| 3319 | if (blksize > 0) {
|
---|
| 3320 | totalread = totalread + blksize;
|
---|
| 3321 | (void) fwrite(tempblock, 1, blksize, fout);
|
---|
| 3322 | } else {
|
---|
| 3323 | break;
|
---|
| 3324 | }
|
---|
| 3325 | }
|
---|
| 3326 | } else {
|
---|
| 3327 | i = 0;
|
---|
| 3328 | }
|
---|
[1155] | 3329 | mr_free(tempblock);
|
---|
[128] | 3330 | paranoid_fclose(fout);
|
---|
| 3331 | if (i > 0) // length_of_file (curr_slice_fname_uncompressed)
|
---|
[1] | 3332 | {
|
---|
[128] | 3333 | if (!does_file_exist(curr_slice_fname_uncompressed)) {
|
---|
[1107] | 3334 | mr_msg(2,
|
---|
[128] | 3335 | "Warning - '%s' doesn't exist. How can I compress slice?",
|
---|
| 3336 | curr_slice_fname_uncompressed);
|
---|
| 3337 | }
|
---|
| 3338 | if (should_I_compress_slices && bkpinfo->compression_level > 0) {
|
---|
[1155] | 3339 | mr_asprintf(&command, "%s -%d %s", bkpinfo->zip_exe,
|
---|
| 3340 | bkpinfo->compression_level,
|
---|
| 3341 | curr_slice_fname_uncompressed);
|
---|
[1107] | 3342 | mr_msg(2, command);
|
---|
[128] | 3343 | if ((res = system(command))) {
|
---|
| 3344 | log_OS_error(command);
|
---|
| 3345 | }
|
---|
[1155] | 3346 | mr_free(command);
|
---|
[128] | 3347 | // did_I_compress_slice = TRUE;
|
---|
| 3348 | } else {
|
---|
[1155] | 3349 | /* BERLIOS: Useless
|
---|
| 3350 | mr_asprintf(&command, "mv %s %s 2>> %s",
|
---|
| 3351 | curr_slice_fname_uncompressed,
|
---|
| 3352 | curr_slice_fname_compressed, MONDO_LOGFILE);
|
---|
| 3353 | */
|
---|
[128] | 3354 | res = 0; // don't do it :)
|
---|
| 3355 | // did_I_compress_slice = FALSE;
|
---|
| 3356 | }
|
---|
| 3357 | retval += res;
|
---|
| 3358 | if (res) {
|
---|
[1107] | 3359 | mr_msg(2, "Failed to compress the slice");
|
---|
[128] | 3360 | }
|
---|
| 3361 | if (bkpinfo->use_lzo
|
---|
| 3362 | && strcmp(curr_slice_fname_compressed,
|
---|
| 3363 | curr_slice_fname_uncompressed)) {
|
---|
| 3364 | unlink(curr_slice_fname_uncompressed);
|
---|
| 3365 | }
|
---|
| 3366 | if (res) {
|
---|
[1155] | 3367 | mr_asprintf(&tmp, "Problem with slice # %ld", slice_num);
|
---|
[128] | 3368 | } else {
|
---|
[1155] | 3369 | mr_asprintf(&tmp,
|
---|
| 3370 | "%s - Bigfile #%ld, slice #%ld compressed OK ",
|
---|
| 3371 | biggie_filename, biggie_file_number + 1,
|
---|
| 3372 | slice_num);
|
---|
[128] | 3373 | }
|
---|
| 3374 | if (!g_text_mode) {
|
---|
| 3375 | newtDrawRootText(0, g_noof_rows - 2, tmp);
|
---|
| 3376 | newtRefresh();
|
---|
| 3377 | } else {
|
---|
[1107] | 3378 | mr_msg(2, tmp);
|
---|
[128] | 3379 | }
|
---|
[1155] | 3380 | mr_free(tmp);
|
---|
| 3381 | mr_asprintf(&file_to_archive, curr_slice_fname_compressed);
|
---|
[128] | 3382 | g_current_progress++;
|
---|
| 3383 | } else { /* if i==0 then ... */
|
---|
[1] | 3384 |
|
---|
[128] | 3385 | finished = TRUE;
|
---|
[1155] | 3386 | mr_asprintf(&file_to_archive, curr_slice_fname_uncompressed);
|
---|
[128] | 3387 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 3388 | break;
|
---|
| 3389 | }
|
---|
| 3390 | }
|
---|
| 3391 |
|
---|
| 3392 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 3393 | register_in_tape_catalog(biggieslice, biggie_file_number,
|
---|
| 3394 | slice_num, file_to_archive);
|
---|
| 3395 | maintain_collection_of_recent_archives(bkpinfo->tmpdir,
|
---|
| 3396 | file_to_archive);
|
---|
| 3397 | res = move_files_to_stream(bkpinfo, file_to_archive, NULL);
|
---|
| 3398 | } else {
|
---|
[541] | 3399 | res = move_files_to_cd(bkpinfo, file_to_archive, NULL);
|
---|
[128] | 3400 | }
|
---|
[1155] | 3401 | mr_free(file_to_archive);
|
---|
[128] | 3402 | retval += res;
|
---|
| 3403 | if (res) {
|
---|
[1155] | 3404 | mr_asprintf(&tmp,
|
---|
| 3405 | "Failed to add slice %ld of bigfile %ld to scratchdir",
|
---|
| 3406 | slice_num, biggie_file_number + 1);
|
---|
[128] | 3407 | log_to_screen(tmp);
|
---|
[1155] | 3408 | mr_free(tmp);
|
---|
[128] | 3409 | fatal_error
|
---|
| 3410 | ("Hard disk full. You should have bought a bigger one.");
|
---|
| 3411 | }
|
---|
[1155] | 3412 | mr_free(curr_slice_fname_uncompressed);
|
---|
| 3413 | mr_free(curr_slice_fname_compressed);
|
---|
[1] | 3414 | }
|
---|
[1155] | 3415 | mr_free(suffix);
|
---|
[128] | 3416 | paranoid_fclose(fin);
|
---|
| 3417 | if (retval) {
|
---|
[1155] | 3418 | mr_asprintf(&tmp, "Sliced bigfile #%ld...FAILED",
|
---|
| 3419 | biggie_file_number + 1);
|
---|
[128] | 3420 | } else {
|
---|
[1155] | 3421 | mr_asprintf(&tmp, "Sliced bigfile #%ld...OK!",
|
---|
| 3422 | biggie_file_number + 1);
|
---|
[1] | 3423 | }
|
---|
[1107] | 3424 | mr_msg(1, tmp);
|
---|
[1080] | 3425 | mr_free(tmp);
|
---|
[128] | 3426 | return (retval);
|
---|
[1] | 3427 | }
|
---|
| 3428 |
|
---|
| 3429 |
|
---|
| 3430 | /**
|
---|
| 3431 | * Remove the archives in @c d.
|
---|
| 3432 | * This could possibly include any of:
|
---|
| 3433 | * - all afioballs (compressed and not)
|
---|
| 3434 | * - all filelists
|
---|
| 3435 | * - all slices
|
---|
| 3436 | * - all checksums
|
---|
| 3437 | * - a zero filler file
|
---|
| 3438 | *
|
---|
| 3439 | * @param d The directory to wipe the archives from.
|
---|
| 3440 | * @ingroup utilityGroup
|
---|
| 3441 | */
|
---|
[128] | 3442 | void wipe_archives(char *d)
|
---|
[1] | 3443 | {
|
---|
[128] | 3444 | /*@ buffers ********************************************* */
|
---|
[1155] | 3445 | char *tmp = NULL;
|
---|
| 3446 | char *dir = NULL;
|
---|
[1] | 3447 |
|
---|
[128] | 3448 | assert_string_is_neither_NULL_nor_zerolength(d);
|
---|
[1] | 3449 |
|
---|
[1155] | 3450 | mr_asprintf(&dir, "%s/archives", d);
|
---|
| 3451 | mr_asprintf(&tmp, "find %s -name '*.afio*' -exec rm -f '{}' \\;", dir);
|
---|
[128] | 3452 | run_program_and_log_output(tmp, FALSE);
|
---|
[1155] | 3453 | mr_free(tmp);
|
---|
| 3454 | mr_asprintf(&tmp, "find %s -name '*list.[0-9]*' -exec rm -f '{}' \\;",
|
---|
| 3455 | dir);
|
---|
[128] | 3456 | run_program_and_log_output(tmp, FALSE);
|
---|
[1155] | 3457 | mr_free(tmp);
|
---|
| 3458 |
|
---|
| 3459 | mr_asprintf(&tmp, "find %s -name 'slice*' -exec rm -f '{}' \\;", dir);
|
---|
[128] | 3460 | run_program_and_log_output(tmp, FALSE);
|
---|
[1155] | 3461 | mr_free(tmp);
|
---|
| 3462 |
|
---|
| 3463 | mr_asprintf(&tmp, "rm -f %s/cklist*", dir);
|
---|
[128] | 3464 | run_program_and_log_output(tmp, FALSE);
|
---|
[1155] | 3465 | mr_free(tmp);
|
---|
| 3466 |
|
---|
| 3467 | mr_asprintf(&tmp, "rm -f %s/zero", dir);
|
---|
[128] | 3468 | run_program_and_log_output(tmp, FALSE);
|
---|
[1155] | 3469 | mr_free(tmp);
|
---|
| 3470 |
|
---|
[1107] | 3471 | mr_msg(1, "Wiped %s's archives", dir);
|
---|
[1155] | 3472 | mr_asprintf(&tmp, "ls -l %s", dir);
|
---|
[128] | 3473 | run_program_and_log_output(tmp, FALSE);
|
---|
[1080] | 3474 | mr_free(tmp);
|
---|
[1155] | 3475 |
|
---|
[1080] | 3476 | mr_free(dir);
|
---|
[1] | 3477 | }
|
---|
| 3478 |
|
---|
| 3479 |
|
---|
| 3480 | /**
|
---|
| 3481 | * @addtogroup LLarchiveGroup
|
---|
| 3482 | * @{
|
---|
| 3483 | */
|
---|
| 3484 | /**
|
---|
| 3485 | * Write the final ISO image.
|
---|
| 3486 | * @param bkpinfo The backup information structure. Used only
|
---|
| 3487 | * in the call to @c write_iso_and_go_on().
|
---|
| 3488 | * @return The number of errors encountered (0 for success)
|
---|
| 3489 | * @see write_iso_and_go_on
|
---|
| 3490 | * @see make_iso_fs
|
---|
| 3491 | * @bug The final ISO is written even if there are no files on it. In practice,
|
---|
| 3492 | * however, this occurs rarely.
|
---|
| 3493 | */
|
---|
[541] | 3494 | int write_final_iso_if_necessary(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 3495 | {
|
---|
[128] | 3496 | /*@ int ***************************************************** */
|
---|
| 3497 | int res;
|
---|
[1] | 3498 |
|
---|
[128] | 3499 | /*@ buffers ************************************************** */
|
---|
[1155] | 3500 | char *tmp = NULL;
|
---|
[1] | 3501 |
|
---|
[128] | 3502 | assert(bkpinfo != NULL);
|
---|
[1] | 3503 |
|
---|
| 3504 | // 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
|
---|
| 3505 |
|
---|
[1155] | 3506 | mr_asprintf(&tmp, "Writing the final ISO");
|
---|
[1107] | 3507 | mr_msg(2, tmp);
|
---|
[1193] | 3508 | /* BERLIOS: Doesn't work on allocated chains anymore
|
---|
[128] | 3509 | center_string(tmp, 80);
|
---|
[1193] | 3510 | */
|
---|
[1] | 3511 | #ifndef _XWIN
|
---|
[128] | 3512 | if (!g_text_mode) {
|
---|
| 3513 | newtPushHelpLine(tmp);
|
---|
| 3514 | }
|
---|
[1] | 3515 | #endif
|
---|
[1155] | 3516 | mr_free(tmp);
|
---|
[541] | 3517 | res = write_iso_and_go_on(bkpinfo, TRUE);
|
---|
[1] | 3518 | #ifndef _XWIN
|
---|
[128] | 3519 | if (!g_text_mode) {
|
---|
| 3520 | newtPopHelpLine();
|
---|
| 3521 | }
|
---|
[1] | 3522 | #endif
|
---|
[1107] | 3523 | mr_msg(2, "Returning from writing final ISO (res=%d)", res);
|
---|
[128] | 3524 | return (res);
|
---|
[1] | 3525 | }
|
---|
| 3526 |
|
---|
| 3527 |
|
---|
| 3528 | /**
|
---|
[20] | 3529 | * Write an ISO image to <tt>[bkpinfo->isodir]/bkpinfo->prefix-[g_current_media_number].iso</tt>.
|
---|
[1] | 3530 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 3531 | * - @c backup_media_type
|
---|
[20] | 3532 | * - @c prefix
|
---|
[1] | 3533 | * - @c isodir
|
---|
| 3534 | * - @c manual_cd_tray
|
---|
| 3535 | * - @c media_size
|
---|
| 3536 | * - @c nfs_mount
|
---|
| 3537 | * - @c nfs_remote_dir
|
---|
| 3538 | * - @c scratchdir
|
---|
| 3539 | * - @c verify_data
|
---|
| 3540 | *
|
---|
| 3541 | * @param last_cd If TRUE, this is the last CD to write; if FALSE, it's not.
|
---|
| 3542 | * @return The number of errors encountered (0 for success)
|
---|
| 3543 | * @see make_iso_fs
|
---|
| 3544 | */
|
---|
[541] | 3545 | int write_iso_and_go_on(struct s_bkpinfo *bkpinfo, bool last_cd)
|
---|
[1] | 3546 | {
|
---|
[128] | 3547 | /*@ pointers **************************************************** */
|
---|
| 3548 | FILE *fout;
|
---|
[1] | 3549 |
|
---|
[128] | 3550 | /*@ buffers ***************************************************** */
|
---|
| 3551 | char *tmp;
|
---|
| 3552 | char *cdno_fname;
|
---|
| 3553 | char *lastcd_fname;
|
---|
| 3554 | char *isofile;
|
---|
[1] | 3555 |
|
---|
[128] | 3556 | /*@ bool ******************************************************** */
|
---|
| 3557 | bool that_one_was_ok;
|
---|
| 3558 | bool using_nfs;
|
---|
| 3559 | bool orig_vfy_flag_val;
|
---|
[1] | 3560 |
|
---|
[128] | 3561 | /*@ int *********************************************************** */
|
---|
| 3562 | int res = 0;
|
---|
[1] | 3563 |
|
---|
[128] | 3564 | assert(bkpinfo != NULL);
|
---|
| 3565 | orig_vfy_flag_val = bkpinfo->verify_data;
|
---|
| 3566 | if (bkpinfo->media_size[g_current_media_number] <= 0) {
|
---|
| 3567 | fatal_error("write_iso_and_go_on() - unknown media size");
|
---|
| 3568 | }
|
---|
[1] | 3569 |
|
---|
[128] | 3570 | if (strlen(bkpinfo->nfs_mount) > 1) {
|
---|
| 3571 | using_nfs = TRUE;
|
---|
| 3572 | } else {
|
---|
| 3573 | using_nfs = FALSE;
|
---|
| 3574 | }
|
---|
[1107] | 3575 | mr_msg(1, "OK, time to make %s #%d",
|
---|
[1155] | 3576 | bkpinfo->backup_media_string,
|
---|
[128] | 3577 | g_current_media_number);
|
---|
[1] | 3578 |
|
---|
[128] | 3579 | /* label the ISO with its number */
|
---|
[1] | 3580 |
|
---|
[1155] | 3581 | mr_asprintf(&cdno_fname, "%s/archives/THIS-CD-NUMBER",
|
---|
| 3582 | bkpinfo->scratchdir);
|
---|
[128] | 3583 | fout = fopen(cdno_fname, "w");
|
---|
| 3584 | fprintf(fout, "%d", g_current_media_number);
|
---|
| 3585 | paranoid_fclose(fout);
|
---|
[1155] | 3586 | mr_free(cdno_fname);
|
---|
[1] | 3587 |
|
---|
[1213] | 3588 | mr_asprintf(&tmp, "cp -f %s/autorun %s/", MONDO_SHARE,
|
---|
[1155] | 3589 | bkpinfo->scratchdir);
|
---|
[128] | 3590 | if (run_program_and_log_output(tmp, FALSE)) {
|
---|
[1107] | 3591 | mr_msg(2, "Warning - unable to copy autorun to scratchdir");
|
---|
[1] | 3592 | }
|
---|
[1155] | 3593 | mr_free(tmp);
|
---|
[128] | 3594 |
|
---|
| 3595 | /* last CD or not? Label accordingly */
|
---|
[1155] | 3596 | mr_asprintf(&lastcd_fname, "%s/archives/NOT-THE-LAST",
|
---|
| 3597 | bkpinfo->scratchdir);
|
---|
[128] | 3598 | if (last_cd) {
|
---|
| 3599 | unlink(lastcd_fname);
|
---|
[1107] | 3600 | mr_msg(2,
|
---|
[128] | 3601 | "OK, you're telling me this is the last CD. Fair enough.");
|
---|
| 3602 | } else {
|
---|
| 3603 | fout = fopen(lastcd_fname, "w");
|
---|
| 3604 | fprintf(fout,
|
---|
| 3605 | "You're listening to 90.3 WPLN, Nashville Public Radio.\n");
|
---|
| 3606 | paranoid_fclose(fout);
|
---|
[1] | 3607 | }
|
---|
[1155] | 3608 | mr_free(lastcd_fname);
|
---|
| 3609 |
|
---|
[128] | 3610 | if (space_occupied_by_cd(bkpinfo->scratchdir) / 1024 >
|
---|
| 3611 | bkpinfo->media_size[g_current_media_number]) {
|
---|
[1155] | 3612 | mr_asprintf(&tmp,
|
---|
[1087] | 3613 | "Warning! %s is too big. It occupies %ld KB, which is more than the %ld KB allowed.",
|
---|
| 3614 | media_descriptor_string(bkpinfo->backup_media_type),
|
---|
[128] | 3615 | (long) space_occupied_by_cd(bkpinfo->scratchdir),
|
---|
| 3616 | (long) bkpinfo->media_size[g_current_media_number]);
|
---|
| 3617 | log_to_screen(tmp);
|
---|
[1155] | 3618 | mr_free(tmp);
|
---|
[128] | 3619 | }
|
---|
[1087] | 3620 | if (bkpinfo->backup_media_type != usb) {
|
---|
[1155] | 3621 | mr_asprintf(&isofile, "%s/%s/%s-%d.iso", bkpinfo->isodir,
|
---|
[128] | 3622 | bkpinfo->nfs_remote_dir, bkpinfo->prefix,
|
---|
| 3623 | g_current_media_number);
|
---|
[1087] | 3624 | } else {
|
---|
| 3625 | }
|
---|
[128] | 3626 | for (that_one_was_ok = FALSE; !that_one_was_ok;) {
|
---|
[1087] | 3627 | if (bkpinfo->backup_media_type != usb) {
|
---|
| 3628 | res = make_iso_fs(bkpinfo, isofile);
|
---|
| 3629 | } else {
|
---|
| 3630 | }
|
---|
[128] | 3631 | if (g_current_media_number == 1 && !res
|
---|
| 3632 | && (bkpinfo->backup_media_type == cdr
|
---|
| 3633 | || bkpinfo->backup_media_type == cdrw)) {
|
---|
| 3634 | if (find_cdrom_device(tmp, FALSE)) // make sure find_cdrom_device() finds, records CD-R's loc
|
---|
| 3635 | {
|
---|
[1107] | 3636 | mr_msg(3, "*Sigh* Mike, I hate your computer.");
|
---|
[128] | 3637 | bkpinfo->manual_cd_tray = TRUE;
|
---|
| 3638 | } // if it can't be found then force pausing
|
---|
| 3639 | else {
|
---|
[1107] | 3640 | mr_msg(3, "Great. Found Mike's CD-ROM drive.");
|
---|
[128] | 3641 | }
|
---|
[1] | 3642 | }
|
---|
[128] | 3643 | if (bkpinfo->verify_data && !res) {
|
---|
| 3644 | log_to_screen
|
---|
| 3645 | ("Please reboot from the 1st %s in Compare Mode, as a precaution.",
|
---|
| 3646 | media_descriptor_string(g_backup_media_type));
|
---|
| 3647 | chdir("/");
|
---|
| 3648 | iamhere("Before calling verify_cd_image()");
|
---|
| 3649 | res += verify_cd_image(bkpinfo);
|
---|
| 3650 | iamhere("After calling verify_cd_image()");
|
---|
[1] | 3651 | }
|
---|
[128] | 3652 | if (!res) {
|
---|
| 3653 | that_one_was_ok = TRUE;
|
---|
| 3654 | } else {
|
---|
[1155] | 3655 | mr_asprintf(&tmp, "Failed to burn %s #%d. Retry?",
|
---|
| 3656 | bkpinfo->backup_media_string,
|
---|
| 3657 | g_current_media_number);
|
---|
[128] | 3658 | res = ask_me_yes_or_no(tmp);
|
---|
[1155] | 3659 | mr_free(tmp);
|
---|
[128] | 3660 | if (!res) {
|
---|
| 3661 | if (ask_me_yes_or_no("Abort the backup?")) {
|
---|
| 3662 | fatal_error("FAILED TO BACKUP");
|
---|
| 3663 | } else {
|
---|
| 3664 | break;
|
---|
| 3665 | }
|
---|
| 3666 | } else {
|
---|
[1107] | 3667 | mr_msg(2, "Retrying, at user's request...");
|
---|
[128] | 3668 | res = 0;
|
---|
| 3669 | }
|
---|
| 3670 | }
|
---|
[1] | 3671 | }
|
---|
[1155] | 3672 | mr_free(isofile);
|
---|
| 3673 |
|
---|
[128] | 3674 | g_current_media_number++;
|
---|
| 3675 | if (g_current_media_number > MAX_NOOF_MEDIA) {
|
---|
| 3676 | fatal_error("Too many CD-R(W)'s. Use tape or net.");
|
---|
| 3677 | }
|
---|
| 3678 | wipe_archives(bkpinfo->scratchdir);
|
---|
[1155] | 3679 | mr_asprintf(&tmp, "rm -Rf %s/images/*gz %s/images/*data*img",
|
---|
| 3680 | bkpinfo->scratchdir, bkpinfo->scratchdir);
|
---|
[128] | 3681 | if (system(tmp)) {
|
---|
[1155] | 3682 | mr_msg(2,
|
---|
| 3683 | "Error occurred when I tried to delete the redundant IMGs and GZs");
|
---|
[128] | 3684 | }
|
---|
[1155] | 3685 | mr_free(tmp);
|
---|
[1] | 3686 |
|
---|
[128] | 3687 | if (last_cd) {
|
---|
[1107] | 3688 | mr_msg(2, "This was your last CD.");
|
---|
[128] | 3689 | } else {
|
---|
[1107] | 3690 | mr_msg(2, "Continuing to backup your data...");
|
---|
[128] | 3691 | }
|
---|
[1] | 3692 |
|
---|
[128] | 3693 | bkpinfo->verify_data = orig_vfy_flag_val;
|
---|
| 3694 | return (0);
|
---|
[1] | 3695 | }
|
---|
| 3696 |
|
---|
| 3697 | /* @} - end of LLarchiveGroup */
|
---|
| 3698 |
|
---|
| 3699 |
|
---|
| 3700 | /**
|
---|
| 3701 | * Verify the user's data.
|
---|
| 3702 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 3703 | * - @c backup_data
|
---|
| 3704 | * - @c backup_media_type
|
---|
| 3705 | * - @c media_device
|
---|
| 3706 | * - @c verify_data
|
---|
| 3707 | *
|
---|
| 3708 | * @return The number of errors encountered (0 for success)
|
---|
| 3709 | * @ingroup verifyGroup
|
---|
| 3710 | */
|
---|
| 3711 | int verify_data(struct s_bkpinfo *bkpinfo)
|
---|
| 3712 | {
|
---|
[128] | 3713 | int res = 0, retval = 0, cdno = 0;
|
---|
[1155] | 3714 | char *tmp = NULL;
|
---|
[128] | 3715 | long diffs = 0;
|
---|
[1] | 3716 |
|
---|
[128] | 3717 | assert(bkpinfo != NULL);
|
---|
| 3718 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 3719 | chdir("/");
|
---|
| 3720 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
| 3721 | "Verifying archives against live filesystem");
|
---|
| 3722 | if (bkpinfo->backup_media_type == cdstream) {
|
---|
| 3723 | strcpy(bkpinfo->media_device, "/dev/cdrom");
|
---|
| 3724 | }
|
---|
| 3725 | verify_tape_backups(bkpinfo);
|
---|
| 3726 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
| 3727 | } else if (bkpinfo->backup_data)
|
---|
| 3728 | //bkpinfo->backup_media_type == cdrw || bkpinfo->backup_media_type == cdr))
|
---|
[1] | 3729 | {
|
---|
[1107] | 3730 | mr_msg(2,
|
---|
[128] | 3731 | "Not verifying again. Per-CD/ISO verification already carried out.");
|
---|
| 3732 | paranoid_system
|
---|
| 3733 | ("cat /tmp/changed.files.* > /tmp/changed.files 2> /dev/null");
|
---|
| 3734 | } else {
|
---|
| 3735 | g_current_media_number = cdno;
|
---|
| 3736 | if (bkpinfo->backup_media_type != iso) {
|
---|
| 3737 | find_cdrom_device(bkpinfo->media_device, FALSE); // replace 0,0,0 with /dev/cdrom
|
---|
[1] | 3738 | }
|
---|
[128] | 3739 | chdir("/");
|
---|
| 3740 | for (cdno = 1; cdno < 99 && bkpinfo->verify_data; cdno++) {
|
---|
| 3741 | if (cdno != g_current_media_number) {
|
---|
[1107] | 3742 | mr_msg(2,
|
---|
[128] | 3743 | "Warning - had to change g_current_media_number from %d to %d",
|
---|
| 3744 | g_current_media_number, cdno);
|
---|
| 3745 | g_current_media_number = cdno;
|
---|
| 3746 | }
|
---|
| 3747 | if (bkpinfo->backup_media_type != iso) {
|
---|
| 3748 | insist_on_this_cd_number(bkpinfo, cdno);
|
---|
| 3749 | }
|
---|
| 3750 | res = verify_cd_image(bkpinfo); // sets verify_data to FALSE if it's time to stop verifying
|
---|
| 3751 | retval += res;
|
---|
| 3752 | if (res) {
|
---|
[1155] | 3753 | mr_asprintf(&tmp,
|
---|
| 3754 | "Warnings/errors were reported while checking %s #%d",
|
---|
| 3755 | bkpinfo->backup_media_string,
|
---|
| 3756 | g_current_media_number);
|
---|
[128] | 3757 | log_to_screen(tmp);
|
---|
[1155] | 3758 | mr_free(tmp);
|
---|
[1] | 3759 |
|
---|
[128] | 3760 | }
|
---|
[1] | 3761 | }
|
---|
[1155] | 3762 | mr_asprintf(&tmp,
|
---|
| 3763 | "grep 'afio: ' %s | sed 's/afio: //' | grep -vE '^/dev/.*$' >> /tmp/changed.files",
|
---|
| 3764 | MONDO_LOGFILE);
|
---|
[128] | 3765 | system(tmp);
|
---|
[1155] | 3766 | mr_free(tmp);
|
---|
[128] | 3767 |
|
---|
[1155] | 3768 | mr_asprintf(&tmp,
|
---|
| 3769 | "grep 'star: ' %s | sed 's/star: //' | grep -vE '^/dev/.*$' >> /tmp/changed.files",
|
---|
| 3770 | MONDO_LOGFILE);
|
---|
[128] | 3771 | system(tmp);
|
---|
[1155] | 3772 | mr_free(tmp);
|
---|
| 3773 |
|
---|
[128] | 3774 | run_program_and_log_output("umount " MNT_CDROM, FALSE);
|
---|
| 3775 | eject_device(bkpinfo->media_device);
|
---|
[1] | 3776 | }
|
---|
[128] | 3777 | diffs = count_lines_in_file("/tmp/changed.files");
|
---|
[1] | 3778 |
|
---|
[128] | 3779 | if (diffs > 0) {
|
---|
| 3780 | if (retval == 0) {
|
---|
| 3781 | retval = (int) (-diffs);
|
---|
| 3782 | }
|
---|
[1] | 3783 | }
|
---|
[128] | 3784 | return (retval);
|
---|
[1] | 3785 | }
|
---|
| 3786 |
|
---|
| 3787 |
|
---|
| 3788 | /**
|
---|
| 3789 | * @addtogroup utilityGroup
|
---|
| 3790 | * @{
|
---|
| 3791 | */
|
---|
| 3792 | /**
|
---|
| 3793 | * Write an image to a real 3.5" floppy disk.
|
---|
| 3794 | * @param device The device to write to (e.g. @c /dev/fd0)
|
---|
| 3795 | * @param datafile The image to write to @p device.
|
---|
| 3796 | * @return The number of errors encountered (0 for success)
|
---|
| 3797 | * @see write_image_to_floppy
|
---|
| 3798 | */
|
---|
[128] | 3799 | int write_image_to_floppy_SUB(char *device, char *datafile)
|
---|
[1] | 3800 | {
|
---|
[128] | 3801 | /*@ int *************************************************************** */
|
---|
| 3802 | int res = 0;
|
---|
[1] | 3803 | int percentage = 0;
|
---|
| 3804 | int blockno = 0;
|
---|
[128] | 3805 | int maxblocks = 0;
|
---|
[1] | 3806 |
|
---|
[128] | 3807 | /*@ buffers************************************************************ */
|
---|
| 3808 | char *tmp;
|
---|
[1] | 3809 | char blk[1024];
|
---|
| 3810 | char *title;
|
---|
| 3811 |
|
---|
[128] | 3812 | /*@ pointers ********************************************************** */
|
---|
[1] | 3813 | char *p;
|
---|
[128] | 3814 | FILE *fout, *fin;
|
---|
[1] | 3815 |
|
---|
| 3816 |
|
---|
[128] | 3817 | /* pretty stuff */
|
---|
| 3818 | if (!(p = strrchr(datafile, '/'))) {
|
---|
| 3819 | p = datafile;
|
---|
| 3820 | } else {
|
---|
| 3821 | p++;
|
---|
[1] | 3822 | }
|
---|
[1155] | 3823 | mr_asprintf(&title, "Writing %s to floppy", p);
|
---|
[128] | 3824 | open_evalcall_form(title);
|
---|
[1155] | 3825 | mr_free(title);
|
---|
| 3826 |
|
---|
[128] | 3827 | /* functional stuff */
|
---|
| 3828 | for (p = device + strlen(device); p != device && isdigit(*(p - 1));
|
---|
| 3829 | p--);
|
---|
| 3830 | maxblocks = atoi(p);
|
---|
| 3831 | if (!maxblocks) {
|
---|
| 3832 | maxblocks = 1440;
|
---|
[1] | 3833 | }
|
---|
[1155] | 3834 | mr_asprintf(&tmp, "maxblocks = %d; p=%s", maxblocks, p);
|
---|
[1107] | 3835 | mr_msg(2, tmp);
|
---|
[1155] | 3836 | mr_free(tmp);
|
---|
| 3837 |
|
---|
[128] | 3838 | /* copy data from image to floppy */
|
---|
| 3839 | if (!(fin = fopen(datafile, "r"))) {
|
---|
| 3840 | log_OS_error("Cannot open img");
|
---|
| 3841 | return (1);
|
---|
[1] | 3842 | }
|
---|
[128] | 3843 | if (!(fout = fopen(device, "w"))) {
|
---|
| 3844 | log_OS_error("Cannot open fdd");
|
---|
| 3845 | return (1);
|
---|
| 3846 | }
|
---|
| 3847 | for (blockno = 0; blockno < maxblocks; blockno++) {
|
---|
| 3848 | percentage = blockno * 100 / maxblocks;
|
---|
| 3849 | if (fread(blk, 1, 1024, fin) != 1024) {
|
---|
| 3850 | if (feof(fin)) {
|
---|
[1107] | 3851 | mr_msg(1,
|
---|
[128] | 3852 | "img read err - img ended prematurely - non-fatal error");
|
---|
| 3853 | sleep(3);
|
---|
| 3854 | return (res);
|
---|
| 3855 | }
|
---|
| 3856 | res++;
|
---|
| 3857 | log_to_screen("img read err");
|
---|
| 3858 | }
|
---|
| 3859 | if (fwrite(blk, 1, 1024, fout) != 1024) {
|
---|
| 3860 | res++;
|
---|
| 3861 | log_to_screen("fdd write err");
|
---|
| 3862 | }
|
---|
| 3863 | if (((blockno + 1) % 128) == 0) {
|
---|
[1155] | 3864 | sync(); /* fflush doesn't work; dunno why */
|
---|
[128] | 3865 | update_evalcall_form(percentage);
|
---|
| 3866 | }
|
---|
| 3867 | }
|
---|
| 3868 | paranoid_fclose(fin);
|
---|
| 3869 | paranoid_fclose(fout);
|
---|
| 3870 | close_evalcall_form();
|
---|
| 3871 | return (res);
|
---|
[1] | 3872 | }
|
---|
| 3873 |
|
---|
| 3874 |
|
---|
| 3875 | /**
|
---|
| 3876 | * Wrapper around @c write_image_to_floppy_SUB().
|
---|
| 3877 | * This function, unlike @c write_image_to_floppy_SUB(),
|
---|
| 3878 | * gives the user the opportunity to retry if the write fails.
|
---|
| 3879 | * @see write_image_to_floppy_SUB
|
---|
| 3880 | */
|
---|
[128] | 3881 | int write_image_to_floppy(char *device, char *datafile)
|
---|
[1] | 3882 | {
|
---|
[128] | 3883 | /*@ int ************************************************************** */
|
---|
| 3884 | int res = 0;
|
---|
[1] | 3885 |
|
---|
[128] | 3886 | assert_string_is_neither_NULL_nor_zerolength(device);
|
---|
| 3887 | assert_string_is_neither_NULL_nor_zerolength(datafile);
|
---|
[1] | 3888 |
|
---|
[128] | 3889 | while ((res = write_image_to_floppy_SUB(device, datafile))) {
|
---|
| 3890 | if (!ask_me_yes_or_no("Failed to write image to floppy. Retry?")) {
|
---|
| 3891 | return (res);
|
---|
| 3892 | }
|
---|
[1] | 3893 | }
|
---|
[128] | 3894 | return (res);
|
---|
[1] | 3895 | }
|
---|
| 3896 |
|
---|
| 3897 | /* @} - end of utilityGroup */
|
---|
[259] | 3898 |
|
---|
[1152] | 3899 | void setenv_mondo_var(void) {
|
---|
[259] | 3900 |
|
---|
[1152] | 3901 | char *tmp = NULL;
|
---|
| 3902 | char *p = NULL;
|
---|
[1256] | 3903 | char *path_min = "/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
|
---|
[1152] | 3904 |
|
---|
| 3905 | mr_setenv("MONDO_SHARE",MONDO_SHARE);
|
---|
| 3906 | mr_setenv("MONDORESTORECFG",MONDORESTORECFG);
|
---|
| 3907 | mr_setenv("MONDO_CACHE",MONDO_CACHE);
|
---|
[1256] | 3908 | /* Add the ARCH environment variable for ia64 purposes */
|
---|
| 3909 | mr_setenv("ARCH", get_architecture());
|
---|
[1152] | 3910 |
|
---|
[1256] | 3911 |
|
---|
[1152] | 3912 | if ((p = getenv("PATH")) == NULL) {
|
---|
[1158] | 3913 | mr_asprintf(&tmp, path_min);
|
---|
| 3914 | } else {
|
---|
| 3915 | mr_asprintf(&tmp, "%s:%s",p, path_min);
|
---|
[1152] | 3916 | }
|
---|
| 3917 | mr_setenv("PATH",tmp);
|
---|
| 3918 | mr_free(tmp);
|
---|
[259] | 3919 | }
|
---|