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