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