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