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