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