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