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