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