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