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