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