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