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