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