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