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