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