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