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