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