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