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