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