[1] | 1 | /***************************************************************************
|
---|
| 2 | mondo-cli.c
|
---|
| 3 | -------------------
|
---|
| 4 | begin : Fri Apr 19 16:40:35 EDT 2002
|
---|
| 5 | copyright : (C) 2002 Mondo Hugo Rabson
|
---|
| 6 | email : Hugo Rabson <hugorabson@msn.com>
|
---|
| 7 | edited by : by Stan Benoit 4/2002
|
---|
| 8 | email : troff@nakedsoul.org
|
---|
[116] | 9 | cvsid : $Id: libmondo-cli.c 1977 2008-06-02 08:49:01Z bruno $
|
---|
[1] | 10 | ***************************************************************************/
|
---|
| 11 |
|
---|
| 12 | /***************************************************************************
|
---|
| 13 | * *
|
---|
| 14 | * This program is free software; you can redistribute it and/or modify *
|
---|
| 15 | * it under the terms of the GNU General Public License as published by *
|
---|
| 16 | * the Free Software Foundation; either version 2 of the License, or *
|
---|
| 17 | * (at your option) any later version. *
|
---|
| 18 | * *
|
---|
| 19 | ***************************************************************************/
|
---|
| 20 |
|
---|
| 21 | /***************************************************************************
|
---|
| 22 | UPDATE LOG
|
---|
| 23 |
|
---|
| 24 |
|
---|
| 25 | 08/04
|
---|
| 26 | - if user specifies a dumb -T value, abort
|
---|
| 27 |
|
---|
| 28 | 07/22
|
---|
| 29 | - handle -Q sensibly (don't abort if only -Q supplied)
|
---|
| 30 |
|
---|
| 31 | 07/17
|
---|
| 32 | - better checking of NFS dir's validity
|
---|
| 33 |
|
---|
| 34 | 06/19
|
---|
| 35 | - added AUX_VER
|
---|
| 36 |
|
---|
| 37 | 04/17
|
---|
| 38 | - added '-b' support
|
---|
| 39 | 04/03
|
---|
| 40 | - added star support
|
---|
| 41 |
|
---|
| 42 | 02/06
|
---|
| 43 | - fixed "Please give /dev entry" error msg
|
---|
| 44 |
|
---|
| 45 | 01/20/2004
|
---|
| 46 | - added 2.6.x-kernel "device = /dev/...." support to param reader
|
---|
| 47 | - better handling of SCSI and /dev entries
|
---|
| 48 | - touch /boot/boot.b if necessary
|
---|
| 49 |
|
---|
| 50 | 09/26/2003
|
---|
| 51 | - typo in command-line handling of 'r'
|
---|
| 52 |
|
---|
| 53 | 09/25
|
---|
| 54 | - added DVD write support
|
---|
| 55 |
|
---|
| 56 | 09/24
|
---|
| 57 | - if tape backup (-t) but user doesn't specify tape drive then
|
---|
| 58 | make an educated guess using find_tape_device_and_size()
|
---|
| 59 |
|
---|
| 60 | 09/18
|
---|
| 61 | - insist on partimagehack being present if -x found
|
---|
| 62 |
|
---|
| 63 | 09/16
|
---|
| 64 | - added support for multiple -I's and -E's in call to mondoarchive
|
---|
| 65 | - the '-D' flag doesn't take a value now
|
---|
| 66 |
|
---|
| 67 | 07/14
|
---|
| 68 | - fatal error if -E too short
|
---|
| 69 |
|
---|
| 70 | 05/14
|
---|
| 71 | - if 'n' and user doesn't have rights to write to output dir
|
---|
| 72 | then error out
|
---|
| 73 |
|
---|
| 74 | 05/05
|
---|
| 75 | - added Joshua Oreman's FreeBSD patches
|
---|
| 76 |
|
---|
| 77 | 05/04
|
---|
| 78 | - added Herman Kuster's multi-level bkp patch
|
---|
| 79 |
|
---|
| 80 | 05/02
|
---|
| 81 | - write errors to screen, not just to log
|
---|
| 82 |
|
---|
| 83 | 04/25
|
---|
| 84 | - added lots of assert()'s and log_OS_error()'s
|
---|
| 85 |
|
---|
| 86 | 04/21
|
---|
| 87 | - line 570 --- resolve boot device if softlink
|
---|
| 88 |
|
---|
| 89 | 04/08
|
---|
| 90 | - changed a bunch of fprintf(stderr,...)'s to log_it()'s
|
---|
| 91 | - fixed final / removal in retrieve_switches_from_command_line()
|
---|
| 92 |
|
---|
| 93 | 04/04
|
---|
| 94 | - added -e
|
---|
| 95 |
|
---|
| 96 | 03/15
|
---|
| 97 | - reject relative paths if -d flag (Alessandro Polverini)
|
---|
| 98 |
|
---|
| 99 | 01/02/2003
|
---|
| 100 | - added -J flag (to let user specify incoming filelist)
|
---|
| 101 |
|
---|
| 102 | 12/13/2002
|
---|
| 103 | - various strcpy() calls replaced with strncpy() calls
|
---|
| 104 |
|
---|
| 105 | 12/10
|
---|
| 106 | - added g_loglevel
|
---|
| 107 |
|
---|
| 108 | 11/25
|
---|
| 109 | - line 614 --- if commmand-line param ends in '/' then drop that '/'
|
---|
| 110 |
|
---|
| 111 | 11/19
|
---|
| 112 | - rewrote finish() to kill processes more softly
|
---|
| 113 | - if user calls with '-l RAW' then
|
---|
| 114 |
|
---|
| 115 | 09/01 - 09/30
|
---|
| 116 | - added -N to let user exclude all NFS-related mounts and devices
|
---|
| 117 | - run_program_and_log_output() now takes boolean operator to specify
|
---|
| 118 | whether it will log its activities in the event of _success_
|
---|
| 119 |
|
---|
| 120 | 08/01 - 08/31
|
---|
| 121 | - if no device specified when backing up to tape streamer then assume /dev/st0
|
---|
| 122 | - abort if tape user specifies tape size (just for testing porpoises)
|
---|
| 123 | - tape users no longer need to specify tape size
|
---|
| 124 | - added some comments
|
---|
| 125 | - added bkpinfo->backup_media_type
|
---|
| 126 | - renamed from mondo-archive.c to mondo-cli.c
|
---|
| 127 |
|
---|
| 128 | 07/01 - 07/31
|
---|
| 129 | - better check for mkfs.vfat
|
---|
| 130 | - more sanity-checking for -d flag
|
---|
| 131 | - if isodir does not exist then abort
|
---|
| 132 | - removed "the rest are..." comment from log
|
---|
| 133 | - do not permit '-H' and '-t' in the same command line
|
---|
| 134 | - if not '-o' then insist on vfat-friendly kernel
|
---|
| 135 |
|
---|
| 136 | 06/01 - 06/30
|
---|
| 137 | - added signal-trapping
|
---|
| 138 | - added '-W' (won't make bootable CD or floppies) flag
|
---|
| 139 | - added missing 'j++' to -s switch's code
|
---|
| 140 | - expanded -s switch
|
---|
| 141 | - added -u switch
|
---|
| 142 | - if dvdrecord exists and cdrecord doesn't then use
|
---|
| 143 | dvdrecord instead of cdrecord
|
---|
| 144 |
|
---|
| 145 | 04/01 - 04/30
|
---|
| 146 | - if CD-ROM is supermounted then unmount, run, and remount
|
---|
| 147 | - replace MONDO_VERSION #define with VERSION from ../config.h
|
---|
| 148 | - if CD-ROM is mounted at start then abort
|
---|
| 149 | - improved homedir-locating code
|
---|
| 150 | - improved "backup will occupy N CD's" calculation a bit
|
---|
| 151 | - added -m (manual CD tray) flag
|
---|
| 152 |
|
---|
| 153 |
|
---|
| 154 | *******************************************************************/
|
---|
| 155 |
|
---|
| 156 | /**
|
---|
| 157 | * @file
|
---|
| 158 | * Functions for handling command-line arguments passed to mondoarchive.
|
---|
| 159 | */
|
---|
| 160 |
|
---|
| 161 | /** @def BOOT_LOADER_CHARS The characters allowed for boot loader on this platform. */
|
---|
| 162 |
|
---|
| 163 | #include <pthread.h>
|
---|
[1917] | 164 | #include "my-stuff.h"
|
---|
| 165 | #include "mondostructures.h"
|
---|
| 166 | #include "libmondo-cli-EXT.h"
|
---|
| 167 | #include "libmondo.h"
|
---|
[1] | 168 |
|
---|
| 169 | extern int g_loglevel;
|
---|
| 170 | extern bool g_text_mode;
|
---|
[116] | 171 | extern char g_startdir[MAX_STR_LEN]; ///< ????? @bug ?????
|
---|
[1917] | 172 | extern char *MONDO_OPTIONS;
|
---|
[1] | 173 |
|
---|
| 174 | /*@ file pointer **************************************************/
|
---|
| 175 | extern FILE *g_tape_stream;
|
---|
| 176 |
|
---|
| 177 | /*@ long long *****************************************************/
|
---|
| 178 | extern long long g_tape_posK;
|
---|
| 179 |
|
---|
| 180 | /*@ long **********************************************************/
|
---|
| 181 | extern long g_noof_sets;
|
---|
| 182 |
|
---|
| 183 | /*@ bool******** **************************************************/
|
---|
[116] | 184 | bool g_debugging = FALSE; ///< ????? @bug ????? @ingroup globalGroup
|
---|
| 185 | bool g_running_live = FALSE; ///< ????? @bug ????? @ingroup globalGroup
|
---|
[1] | 186 | extern bool g_cd_recovery;
|
---|
| 187 |
|
---|
[1656] | 188 | extern void setup_tmpdir(char *path);
|
---|
[1] | 189 | extern double g_kernel_version;
|
---|
| 190 | extern int g_current_media_number;
|
---|
| 191 | extern pid_t g_main_pid;
|
---|
[116] | 192 | extern char *resolve_softlinks_to_get_to_actual_device_file(char *);
|
---|
[1] | 193 |
|
---|
[948] | 194 | /* Do we use extended attributes and acl ?
|
---|
| 195 | * By default no, use --acl & --attr options to force their usage */
|
---|
[1917] | 196 | extern char *g_getfacl;
|
---|
| 197 | extern char *g_getfattr;
|
---|
[1] | 198 |
|
---|
[1645] | 199 | /* Reference to global bkpinfo */
|
---|
| 200 | extern struct s_bkpinfo *bkpinfo;
|
---|
| 201 |
|
---|
[1977] | 202 | extern void free_MR_global_filenames(void);
|
---|
| 203 |
|
---|
[1] | 204 | /**
|
---|
| 205 | * @addtogroup cliGroup
|
---|
| 206 | * @{
|
---|
| 207 | */
|
---|
| 208 | /**
|
---|
| 209 | * Populate @p bkpinfo from the command-line parameters stored in @p argc and @p argv.
|
---|
| 210 | * @param argc The argument count, including the program name; @p argc passed to main().
|
---|
| 211 | * @param argv The argument vector; @p argv passed to main().
|
---|
| 212 | * @param bkpinfo The backup information structure to populate.
|
---|
| 213 | * @return The number of problems with the command line (0 for success).
|
---|
| 214 | */
|
---|
| 215 | int
|
---|
[1645] | 216 | handle_incoming_parameters(int argc, char *argv[])
|
---|
[1] | 217 | {
|
---|
[116] | 218 | /*@ int *** */
|
---|
| 219 | int res = 0;
|
---|
| 220 | int retval = 0;
|
---|
| 221 | int i = 0, j;
|
---|
[1] | 222 |
|
---|
[116] | 223 | /*@ buffers *************** */
|
---|
| 224 | char *tmp;
|
---|
| 225 | char flag_val[128][MAX_STR_LEN];
|
---|
| 226 | bool flag_set[128];
|
---|
[1] | 227 |
|
---|
[1702] | 228 | tmp = malloc(9*MAX_STR_LEN);
|
---|
[116] | 229 | for (i = 0; i < 128; i++) {
|
---|
| 230 | flag_val[i][0] = '\0';
|
---|
| 231 | flag_set[i] = FALSE;
|
---|
| 232 | }
|
---|
[541] | 233 | // strcpy (bkpinfo->scratchdir, "/home");
|
---|
[116] | 234 | for (j = 1; j <= MAX_NOOF_MEDIA; j++) {
|
---|
| 235 | bkpinfo->media_size[j] = 650;
|
---|
| 236 | } /* default */
|
---|
| 237 | res =
|
---|
| 238 | retrieve_switches_from_command_line(argc, argv, flag_val,
|
---|
| 239 | flag_set);
|
---|
| 240 | retval += res;
|
---|
| 241 | if (!retval) {
|
---|
[1645] | 242 | res = process_switches(flag_val, flag_set);
|
---|
[116] | 243 | retval += res;
|
---|
| 244 | }
|
---|
[1] | 245 | /*
|
---|
| 246 | if (!retval)
|
---|
| 247 | {
|
---|
| 248 | */
|
---|
[116] | 249 | log_msg(3, "Switches:-");
|
---|
| 250 | for (i = 0; i < 128; i++) {
|
---|
| 251 | if (flag_set[i]) {
|
---|
| 252 | sprintf(tmp, "-%c %s", i, flag_val[i]);
|
---|
| 253 | log_msg(3, tmp);
|
---|
| 254 | }
|
---|
[1] | 255 | }
|
---|
| 256 | // }
|
---|
[116] | 257 | sprintf(tmp, "rm -Rf %s/tmp.mondo.*", bkpinfo->tmpdir);
|
---|
| 258 | paranoid_system(tmp);
|
---|
| 259 | sprintf(tmp, "rm -Rf %s/mondo.scratch.*", bkpinfo->scratchdir);
|
---|
| 260 | paranoid_system(tmp);
|
---|
| 261 | sprintf(bkpinfo->scratchdir + strlen(bkpinfo->scratchdir),
|
---|
| 262 | "/mondo.scratch.%ld", random() % 32767);
|
---|
| 263 | sprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
|
---|
| 264 | paranoid_system(tmp);
|
---|
| 265 | sprintf(tmp, "mkdir -p %s", bkpinfo->scratchdir);
|
---|
| 266 | paranoid_system(tmp);
|
---|
| 267 | paranoid_free(tmp);
|
---|
| 268 | return (retval);
|
---|
[1] | 269 | }
|
---|
| 270 |
|
---|
| 271 |
|
---|
| 272 |
|
---|
| 273 |
|
---|
| 274 | /**
|
---|
| 275 | * Store the sizespec(s) stored in @p value into @p bkpinfo.
|
---|
| 276 | * @param bkpinfo The backup information structure; the @c bkpinfo->media_size field will be populated.
|
---|
| 277 | * @param value The sizespec (e.g. "2g", "40m").
|
---|
| 278 | * @return 0, always.
|
---|
| 279 | * @bug Return code not needed.
|
---|
| 280 | */
|
---|
[1645] | 281 | int process_the_s_switch(char *value)
|
---|
[1] | 282 | {
|
---|
[116] | 283 | int j;
|
---|
| 284 | char tmp[MAX_STR_LEN], *p, comment[MAX_STR_LEN];
|
---|
[1] | 285 |
|
---|
[116] | 286 | assert(bkpinfo != NULL);
|
---|
| 287 | assert(value != NULL);
|
---|
[1] | 288 |
|
---|
[116] | 289 | bkpinfo->media_size[0] = -1; /* dummy value */
|
---|
| 290 | for (j = 1, p = value; j < MAX_NOOF_MEDIA && strchr(p, ',');
|
---|
| 291 | j++, p = strchr(p, ',') + 1) {
|
---|
| 292 | strncpy(tmp, p, MAX_STR_LEN);
|
---|
| 293 | *(strchr(tmp, ',')) = '\0';
|
---|
| 294 | bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(tmp);
|
---|
| 295 | sprintf(comment, "media_size[%d] = %ld", j,
|
---|
| 296 | bkpinfo->media_size[j]);
|
---|
| 297 | log_msg(3, comment);
|
---|
[1] | 298 | }
|
---|
[116] | 299 | for (; j <= MAX_NOOF_MEDIA; j++) {
|
---|
| 300 | bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(p);
|
---|
[1] | 301 | }
|
---|
| 302 | // bkpinfo->media_size[0] = bkpinfo->media_size[MAX_NOOF_MEDIA];
|
---|
[116] | 303 | for (j = 1; j <= MAX_NOOF_MEDIA; j++) {
|
---|
| 304 | if (bkpinfo->media_size[j] <= 0) {
|
---|
| 305 | log_msg(1, "You gave media #%d an invalid size\n", j);
|
---|
| 306 | return (-1);
|
---|
| 307 | }
|
---|
| 308 | }
|
---|
| 309 | return (0);
|
---|
[1] | 310 | }
|
---|
| 311 |
|
---|
| 312 |
|
---|
| 313 |
|
---|
| 314 | /**
|
---|
| 315 | * Process mondoarchive's command-line switches.
|
---|
| 316 | * @param bkpinfo The backup information structure to populate.
|
---|
| 317 | * @param flag_val An array of the argument passed to each switch (the letter is the index).
|
---|
| 318 | * If a switch is not set or has no argument, the field in @p flag_val doesn't matter.
|
---|
| 319 | * @param flag_set An array of <tt>bool</tt>s indexed by switch letter: TRUE if it's set,
|
---|
| 320 | * FALSE if it's not.
|
---|
| 321 | * @return The number of problems with the switches, or 0 for success.
|
---|
| 322 | * @bug Maybe include a list of all switches (inc. intentionally undocumented ones not in the manual!) here?
|
---|
| 323 | */
|
---|
| 324 | int
|
---|
[1645] | 325 | process_switches(char flag_val[128][MAX_STR_LEN], bool flag_set[128])
|
---|
[1] | 326 | {
|
---|
| 327 |
|
---|
[116] | 328 | /*@ ints *** */
|
---|
| 329 | int i = 0;
|
---|
| 330 | int retval = 0;
|
---|
| 331 | int percent = 0;
|
---|
[1] | 332 |
|
---|
[116] | 333 | /*@ buffers ** */
|
---|
| 334 | char *tmp;
|
---|
[542] | 335 | char *tmp1;
|
---|
[116] | 336 | char *psz;
|
---|
[603] | 337 | char *p;
|
---|
| 338 | char *q;
|
---|
[1] | 339 |
|
---|
[949] | 340 | long itbs = 0L;
|
---|
[1] | 341 |
|
---|
[289] | 342 | struct stat buf;
|
---|
| 343 |
|
---|
[116] | 344 | malloc_string(tmp);
|
---|
| 345 | malloc_string(psz);
|
---|
[1] | 346 |
|
---|
[116] | 347 | assert(bkpinfo != NULL);
|
---|
| 348 | assert(flag_val != NULL);
|
---|
| 349 | assert(flag_set != NULL);
|
---|
[1] | 350 |
|
---|
[116] | 351 | bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
|
---|
[1] | 352 |
|
---|
[1977] | 353 | /* compulsory */
|
---|
[116] | 354 | i = flag_set['c'] + flag_set['i'] + flag_set['n'] +
|
---|
| 355 | flag_set['t'] + flag_set['u'] + flag_set['r'] +
|
---|
[1690] | 356 | flag_set['w'] + flag_set['C'] + flag_set['U'];
|
---|
[1977] | 357 | if ((i == 0) && (! bkpinfo->restore_data)) {
|
---|
[116] | 358 | retval++;
|
---|
[541] | 359 | log_to_screen("You must specify the media type\n");
|
---|
[1] | 360 | }
|
---|
[116] | 361 | if (i > 1) {
|
---|
| 362 | retval++;
|
---|
[541] | 363 | log_to_screen("Please specify only one media type\n");
|
---|
[1] | 364 | }
|
---|
[1977] | 365 |
|
---|
[116] | 366 | if (flag_set['K']) {
|
---|
| 367 | g_loglevel = atoi(flag_val['K']);
|
---|
[1977] | 368 | log_msg(1,"Loglevel forced to %d",g_loglevel);
|
---|
[116] | 369 | if (g_loglevel < 3) {
|
---|
| 370 | g_loglevel = 3;
|
---|
| 371 | }
|
---|
[1] | 372 | }
|
---|
[1977] | 373 |
|
---|
| 374 | if ((flag_set['L'] && flag_set['0']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 375 | retval++;
|
---|
[541] | 376 | log_to_screen("You cannot have 'no compression' _and_ LZOP.\n");
|
---|
[1] | 377 | }
|
---|
[1977] | 378 | if (! bkpinfo->restore_data) {
|
---|
| 379 | bkpinfo->backup_data = flag_set['O'];
|
---|
| 380 | }
|
---|
[116] | 381 | bkpinfo->verify_data = flag_set['V'];
|
---|
[1977] | 382 |
|
---|
[116] | 383 | if (flag_set['I'] && !bkpinfo->backup_data) {
|
---|
[541] | 384 | log_to_screen("-I switch is ignored if just verifying");
|
---|
[116] | 385 | }
|
---|
| 386 | if (flag_set['E'] && !bkpinfo->backup_data) {
|
---|
[541] | 387 | log_to_screen("-E switch is ignored if just verifying");
|
---|
[116] | 388 | }
|
---|
[1] | 389 |
|
---|
[116] | 390 | if (!find_home_of_exe("afio")) {
|
---|
| 391 | if (find_home_of_exe("star")) {
|
---|
| 392 | flag_set['R'] = TRUE;
|
---|
| 393 | log_msg(1, "Using star instead of afio");
|
---|
| 394 | } else {
|
---|
| 395 | fatal_error
|
---|
| 396 | ("Neither afio nor star is installed. Please install at least one.");
|
---|
| 397 | }
|
---|
[1] | 398 | }
|
---|
| 399 |
|
---|
[116] | 400 | if (flag_set['R']) {
|
---|
| 401 | bkpinfo->use_star = TRUE;
|
---|
| 402 | if (flag_set['L']) {
|
---|
| 403 | fatal_error("You may not use star and lzop at the same time.");
|
---|
| 404 | }
|
---|
| 405 | if (!find_home_of_exe("star")) {
|
---|
| 406 | fatal_error
|
---|
| 407 | ("Please install 'star' RPM or tarball if you are going to use -R. Thanks.");
|
---|
| 408 | }
|
---|
[1] | 409 | }
|
---|
[1977] | 410 |
|
---|
| 411 | if ((flag_set['W']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 412 | bkpinfo->nonbootable_backup = TRUE;
|
---|
| 413 | log_to_screen("Warning - you have opted for non-bootable backup");
|
---|
| 414 | if (flag_set['f'] || flag_set['l']) {
|
---|
| 415 | log_to_screen
|
---|
[541] | 416 | ("You don't need to specify bootloader or bootdevice");
|
---|
[116] | 417 | }
|
---|
[1] | 418 | }
|
---|
[1977] | 419 |
|
---|
| 420 | if ((flag_set['t'] && flag_set['H']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 421 | fatal_error
|
---|
| 422 | ("Sorry, you may not nuke w/o warning from tape. Drop -H, please.");
|
---|
| 423 | }
|
---|
[1977] | 424 |
|
---|
[116] | 425 | if (flag_set['I']) {
|
---|
| 426 | if (!strcmp(bkpinfo->include_paths, "/")) {
|
---|
| 427 | log_msg(2, "'/' is pleonastic.");
|
---|
| 428 | bkpinfo->include_paths[0] = '\0';
|
---|
| 429 | }
|
---|
| 430 | if (bkpinfo->include_paths[0]) {
|
---|
| 431 | strcat(bkpinfo->include_paths, " ");
|
---|
| 432 | }
|
---|
[542] | 433 | asprintf(&tmp1, flag_val['I']);
|
---|
[603] | 434 | p = tmp1;
|
---|
| 435 | q = tmp1;
|
---|
[542] | 436 |
|
---|
| 437 | /* Cut the flag_val['I'] in parts containing all paths to test them */
|
---|
| 438 | while (p != NULL) {
|
---|
| 439 | q = strchr(p, ' ');
|
---|
| 440 | if (q != NULL) {
|
---|
| 441 | *q = '\0';
|
---|
[1977] | 442 | if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
|
---|
[542] | 443 | log_msg(1, "ERROR ! %s doesn't exist", p);
|
---|
| 444 | fatal_error("ERROR ! You specified a directory to include which doesn't exist");
|
---|
| 445 | }
|
---|
[633] | 446 | p = q+1 ;
|
---|
[542] | 447 | } else {
|
---|
[1977] | 448 | if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
|
---|
[542] | 449 | log_msg(1, "ERROR ! %s doesn't exist", p);
|
---|
| 450 | fatal_error("ERROR ! You specified a directory to include which doesn't exist");
|
---|
| 451 | }
|
---|
| 452 | p = NULL;
|
---|
| 453 | }
|
---|
[289] | 454 | }
|
---|
[542] | 455 | paranoid_free(tmp1);
|
---|
| 456 |
|
---|
[116] | 457 | strncpy(bkpinfo->include_paths + strlen(bkpinfo->include_paths),
|
---|
| 458 | flag_val['I'],
|
---|
[543] | 459 | 4*MAX_STR_LEN - strlen(bkpinfo->include_paths));
|
---|
[116] | 460 | log_msg(1, "include_paths is now '%s'", bkpinfo->include_paths);
|
---|
| 461 | if (bkpinfo->include_paths[0] == '-') {
|
---|
| 462 | retval++;
|
---|
[541] | 463 | log_to_screen("Please supply a sensible value with '-I'\n");
|
---|
[116] | 464 | }
|
---|
| 465 | }
|
---|
[1] | 466 |
|
---|
[116] | 467 | if (g_kernel_version >= 2.6 && !flag_set['d']
|
---|
[1977] | 468 | && (flag_set['c'] || flag_set['w']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 469 | fatal_error
|
---|
| 470 | ("If you are using the 2.6.x kernel, please specify the CD-R(W) device.");
|
---|
[1] | 471 | }
|
---|
| 472 |
|
---|
[116] | 473 |
|
---|
| 474 | if (flag_set['J']) {
|
---|
| 475 | if (flag_set['I']) {
|
---|
| 476 | retval++;
|
---|
| 477 | log_to_screen
|
---|
[541] | 478 | ("Please do not use -J in combination with -I. If you want to make a list of files to backup, that's fine, use -J <filename> but please don't muddy the waters by combining -J with -I. Thanks. :-)");
|
---|
[116] | 479 | }
|
---|
| 480 | bkpinfo->make_filelist = FALSE;
|
---|
| 481 | strcpy(bkpinfo->include_paths, flag_val['J']);
|
---|
[1] | 482 | }
|
---|
[1977] | 483 |
|
---|
| 484 | if ((flag_set['c'] || flag_set['w'] || flag_set['C'] || flag_set['r']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 485 | if (!flag_set['r'] && g_kernel_version <= 2.5
|
---|
| 486 | && strstr(flag_val['d'], "/dev/")) {
|
---|
| 487 | fatal_error
|
---|
| 488 | ("Please don't give a /dev entry. Give a SCSI node for the parameter of the -d flag.");
|
---|
| 489 | }
|
---|
| 490 | if (flag_set['r'] && g_kernel_version <= 2.5
|
---|
| 491 | && !strstr(flag_val['d'], "/dev/")) {
|
---|
| 492 | fatal_error
|
---|
| 493 | ("Please give a /dev entry, not a SCSI node, as the parameter of the -d flag.");
|
---|
| 494 | }
|
---|
| 495 | if (g_kernel_version >= 2.6 && !strstr(flag_val['d'], "/dev/")) {
|
---|
| 496 | log_to_screen
|
---|
[541] | 497 | ("Linus says 2.6 has a broken ide-scsi module. Proceed at your own risk...");
|
---|
[116] | 498 | }
|
---|
| 499 |
|
---|
| 500 | if (system("which cdrecord > /dev/null 2> /dev/null")
|
---|
| 501 | && system("which dvdrecord > /dev/null 2> /dev/null")) {
|
---|
| 502 | fatal_error
|
---|
| 503 | ("Please install dvdrecord/cdrecord and try again.");
|
---|
| 504 | }
|
---|
| 505 | if (flag_set['C']) {
|
---|
| 506 | bkpinfo->cdrw_speed = atoi(flag_val['C']);
|
---|
| 507 | if (bkpinfo->cdrw_speed < 1) {
|
---|
| 508 | fatal_error
|
---|
| 509 | ("You specified a silly speed for a CD-R[W] drive");
|
---|
| 510 | }
|
---|
| 511 | if (!flag_set['L']) {
|
---|
| 512 | log_to_screen
|
---|
[541] | 513 | ("You must use -L with -C. Therefore I am setting it for you.");
|
---|
[116] | 514 | flag_set['L'] = 1;
|
---|
| 515 | flag_val['L'][0] = '\0';
|
---|
| 516 | }
|
---|
| 517 | } else {
|
---|
| 518 | log_msg(3, "flag_val['c'] = %s", flag_val['c']);
|
---|
| 519 | log_msg(3, "flag_val['w'] = %s", flag_val['w']);
|
---|
| 520 | // log_msg(3, "flag_set['r'] = %i", flag_set['r'] );
|
---|
| 521 | if (flag_set['c']) {
|
---|
| 522 | bkpinfo->cdrw_speed = atoi(flag_val['c']);
|
---|
| 523 | } else if (flag_set['w']) {
|
---|
| 524 | bkpinfo->cdrw_speed = atoi(flag_val['w']);
|
---|
| 525 | } else if (flag_set['r']) {
|
---|
| 526 | bkpinfo->cdrw_speed = 1; /*atoi(flag_val['r']); */
|
---|
| 527 | }
|
---|
| 528 |
|
---|
| 529 | if (bkpinfo->cdrw_speed < 1) {
|
---|
| 530 | fatal_error
|
---|
| 531 | ("You specified a silly speed for a CD-R[W] drive");
|
---|
| 532 | }
|
---|
| 533 | }
|
---|
[1] | 534 | }
|
---|
[1977] | 535 |
|
---|
| 536 | if ((flag_set['t'] && !flag_set['d']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 537 | log_it("Hmm! No tape drive specified. Let's see what we can do.");
|
---|
| 538 | if (find_tape_device_and_size(flag_val['d'], tmp)) {
|
---|
| 539 | fatal_error
|
---|
| 540 | ("Tape device not specified. I couldn't find it either.");
|
---|
| 541 | }
|
---|
| 542 | flag_set['d'] = TRUE;
|
---|
| 543 | sprintf(tmp,
|
---|
[541] | 544 | "You didn't specify a tape streamer device. I'm assuming %s",
|
---|
[116] | 545 | flag_val['d']);
|
---|
| 546 | log_to_screen(tmp);
|
---|
| 547 | percent = 0;
|
---|
| 548 | }
|
---|
| 549 |
|
---|
[1687] | 550 | if (flag_set['U']) // USB
|
---|
| 551 | {
|
---|
| 552 | if (! flag_set['d']) {
|
---|
| 553 | fatal_error
|
---|
[1977] | 554 | ("You need to specify a device file with -d for bootable USB device usage");
|
---|
[1687] | 555 | }
|
---|
[1977] | 556 | if ((!flag_set['s']) && (! bkpinfo->restore_data)) {
|
---|
[1687] | 557 | fatal_error("You did not specify a size (-s) for your USB device. Aborting");
|
---|
| 558 | }
|
---|
| 559 | }
|
---|
| 560 |
|
---|
[116] | 561 | if (flag_set['r']) // DVD
|
---|
| 562 | {
|
---|
| 563 | if (flag_set['m']) {
|
---|
| 564 | fatal_error
|
---|
| 565 | ("Manual CD tray (-m) not yet supported in conjunction w/ DVD drives. Drop -m.");
|
---|
| 566 | }
|
---|
| 567 | if (!flag_set['d']) {
|
---|
| 568 | if (!find_dvd_device(flag_val['d'], FALSE)) {
|
---|
| 569 | flag_set['d'] = TRUE;
|
---|
[541] | 570 | log_to_screen("I guess DVD drive is at %s", flag_val['d']);
|
---|
[116] | 571 | }
|
---|
| 572 | }
|
---|
| 573 | if (strchr(flag_val['d'], ',')) {
|
---|
| 574 | fatal_error
|
---|
| 575 | ("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag.");
|
---|
| 576 | }
|
---|
[1977] | 577 | if (! bkpinfo->restore_data) {
|
---|
| 578 | if (!find_home_of_exe("growisofs")) {
|
---|
| 579 | fatal_error
|
---|
| 580 | ("Please install growisofs (probably part of dvd+rw-tools). If you want DVD support, you need it.");
|
---|
| 581 | }
|
---|
| 582 | if (!find_home_of_exe("dvd+rw-format")) {
|
---|
| 583 | fatal_error
|
---|
| 584 | ("Please install dvd+rw-format (probably part of dvd+rw-tools). If you want DVD support, you need it.");
|
---|
| 585 | }
|
---|
| 586 | if (!flag_set['s']) {
|
---|
| 587 | sprintf(flag_val['s'], "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB
|
---|
| 588 | strcat(flag_val['s'], "m");
|
---|
| 589 | log_to_screen
|
---|
| 590 | ("You did not specify a size (-s) for DVD. I'm guessing %s.",
|
---|
| 591 | flag_val['s']);
|
---|
| 592 | flag_set['s'] = 1;
|
---|
| 593 | }
|
---|
[116] | 594 | }
|
---|
[1] | 595 | /*
|
---|
| 596 | if (flag_set['Z']) {
|
---|
| 597 | bkpinfo->blank_dvd_first = TRUE;
|
---|
| 598 | }
|
---|
| 599 | */
|
---|
[116] | 600 | }
|
---|
[1] | 601 |
|
---|
[116] | 602 | if (flag_set['t'] || flag_set['u']) { /* tape size */
|
---|
| 603 | if (strchr(flag_val['d'], ',')) {
|
---|
| 604 | fatal_error
|
---|
| 605 | ("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag.");
|
---|
| 606 | }
|
---|
[1977] | 607 | if ((flag_set['O']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 608 | if (flag_set['s']) {
|
---|
| 609 | if (flag_set['t']) {
|
---|
| 610 | fatal_error
|
---|
| 611 | ("For the moment, please don't specify a tape size. Mondo should handle end-of-tape gracefully anyway.");
|
---|
| 612 | }
|
---|
[1645] | 613 | if (process_the_s_switch(flag_val['s'])) {
|
---|
[116] | 614 | fatal_error("Bad -s switch");
|
---|
| 615 | }
|
---|
| 616 | } else if (flag_set['u'] || flag_set['t']) {
|
---|
| 617 | for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
|
---|
| 618 | bkpinfo->media_size[i] = 0;
|
---|
| 619 | }
|
---|
| 620 | } else {
|
---|
| 621 | retval++;
|
---|
| 622 | log_to_screen("Tape size not specified.\n");
|
---|
| 623 | }
|
---|
| 624 | }
|
---|
[1977] | 625 | } else if (! bkpinfo->restore_data) { /* CD|USB size */
|
---|
[116] | 626 | if (flag_set['s']) {
|
---|
[1645] | 627 | if (process_the_s_switch(flag_val['s'])) {
|
---|
[116] | 628 | fatal_error("Bad -s switch");
|
---|
| 629 | }
|
---|
| 630 | }
|
---|
| 631 | if (flag_set['w']) {
|
---|
| 632 | bkpinfo->wipe_media_first = TRUE;
|
---|
| 633 | } /* CD-RW */
|
---|
[1] | 634 | }
|
---|
[1977] | 635 |
|
---|
[116] | 636 | if (flag_set['n']) {
|
---|
| 637 | strncpy(bkpinfo->nfs_mount, flag_val['n'], MAX_STR_LEN);
|
---|
| 638 | if (!flag_set['d']) {
|
---|
| 639 | strncpy(bkpinfo->nfs_remote_dir, "/", MAX_STR_LEN);
|
---|
| 640 | }
|
---|
[910] | 641 | sprintf(tmp, "mount | grep -E \"^%s .*\" | cut -d' ' -f3",
|
---|
[116] | 642 | bkpinfo->nfs_mount);
|
---|
| 643 | strncpy(bkpinfo->isodir,
|
---|
| 644 | call_program_and_get_last_line_of_output(tmp),
|
---|
| 645 | MAX_STR_LEN / 4);
|
---|
| 646 | if (strlen(bkpinfo->isodir) < 3) {
|
---|
| 647 | retval++;
|
---|
[541] | 648 | log_to_screen("NFS share is not mounted. Please mount it.\n");
|
---|
[116] | 649 | }
|
---|
| 650 | log_msg(3, "mount = %s", bkpinfo->nfs_mount);
|
---|
| 651 | log_msg(3, "isodir= %s", bkpinfo->isodir);
|
---|
[1] | 652 | }
|
---|
[1977] | 653 |
|
---|
[116] | 654 | if (flag_set['c']) {
|
---|
| 655 | bkpinfo->backup_media_type = cdr;
|
---|
[1] | 656 | }
|
---|
[116] | 657 | if (flag_set['C']) {
|
---|
| 658 | bkpinfo->backup_media_type = cdstream;
|
---|
[1] | 659 | }
|
---|
[116] | 660 | if (flag_set['i']) {
|
---|
| 661 | bkpinfo->backup_media_type = iso;
|
---|
| 662 | }
|
---|
| 663 | if (flag_set['n']) {
|
---|
| 664 | bkpinfo->backup_media_type = nfs;
|
---|
[1848] | 665 | /* Never try to eject a NFS device */
|
---|
| 666 | bkpinfo->please_dont_eject = TRUE;
|
---|
[116] | 667 | }
|
---|
| 668 | if (flag_set['r']) {
|
---|
| 669 | bkpinfo->backup_media_type = dvd;
|
---|
| 670 | }
|
---|
| 671 | if (flag_set['t']) {
|
---|
| 672 | bkpinfo->backup_media_type = tape;
|
---|
| 673 | }
|
---|
| 674 | if (flag_set['u']) {
|
---|
| 675 | bkpinfo->backup_media_type = udev;
|
---|
| 676 | }
|
---|
| 677 | if (flag_set['w']) {
|
---|
| 678 | bkpinfo->backup_media_type = cdrw;
|
---|
| 679 | }
|
---|
[1687] | 680 | if (flag_set['U']) {
|
---|
| 681 | bkpinfo->backup_media_type = usb;
|
---|
[1745] | 682 | /* Never try to eject a USB device */
|
---|
[1746] | 683 | bkpinfo->please_dont_eject = TRUE;
|
---|
[1687] | 684 | }
|
---|
[948] | 685 | if (flag_set['z']) {
|
---|
| 686 | if (find_home_of_exe("getfattr")) {
|
---|
| 687 | asprintf(&g_getfattr,"getfattr");
|
---|
| 688 | }
|
---|
| 689 | if (find_home_of_exe("getfacl")) {
|
---|
| 690 | asprintf(&g_getfacl,"getfacl");
|
---|
| 691 | }
|
---|
| 692 | }
|
---|
[1] | 693 |
|
---|
[805] | 694 | /* optional, popular */
|
---|
[116] | 695 | if (flag_set['g']) {
|
---|
| 696 | g_text_mode = FALSE;
|
---|
| 697 | }
|
---|
[805] | 698 |
|
---|
[116] | 699 | if (flag_set['E']) {
|
---|
| 700 | if (bkpinfo->exclude_paths[0]) {
|
---|
| 701 | strcat(bkpinfo->exclude_paths, " ");
|
---|
| 702 | }
|
---|
[542] | 703 | asprintf(&tmp1, flag_val['E']);
|
---|
[605] | 704 | p = tmp1;
|
---|
| 705 | q = tmp1;
|
---|
[542] | 706 |
|
---|
| 707 | /* Cut the flag_val['E'] in parts containing all paths to test them */
|
---|
| 708 | while (p != NULL) {
|
---|
| 709 | q = strchr(p, ' ');
|
---|
| 710 | if (q != NULL) {
|
---|
| 711 | *q = '\0';
|
---|
[805] | 712 | /* Fix bug 14 where ending / cause a problem later
|
---|
| 713 | * so handled here for the moment */
|
---|
| 714 | q--;
|
---|
[809] | 715 | if (*q == '/') {
|
---|
[805] | 716 | *q = '\0';
|
---|
| 717 | }
|
---|
| 718 | q++;
|
---|
| 719 | /* End of bug fix */
|
---|
[1977] | 720 | if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
|
---|
[542] | 721 | log_msg(1, "WARNING ! %s doesn't exist", p);
|
---|
| 722 | }
|
---|
[633] | 723 | p = q+1 ;
|
---|
[542] | 724 | } else {
|
---|
[1977] | 725 | if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
|
---|
[542] | 726 | log_msg(1, "WARNING ! %s doesn't exist", p);
|
---|
| 727 | }
|
---|
| 728 | p = NULL;
|
---|
| 729 | }
|
---|
[289] | 730 | }
|
---|
[542] | 731 | paranoid_free(tmp1);
|
---|
| 732 |
|
---|
[116] | 733 | strncpy(bkpinfo->exclude_paths + strlen(bkpinfo->exclude_paths),
|
---|
| 734 | flag_val['E'],
|
---|
[543] | 735 | 4*MAX_STR_LEN - strlen(bkpinfo->exclude_paths));
|
---|
[116] | 736 | }
|
---|
[1977] | 737 |
|
---|
[116] | 738 | if (flag_set['e']) {
|
---|
| 739 | bkpinfo->please_dont_eject = TRUE;
|
---|
| 740 | }
|
---|
[1977] | 741 |
|
---|
| 742 | if ((flag_set['N']) && (! bkpinfo->restore_data)) // exclude NFS mounts & devices
|
---|
[116] | 743 | {
|
---|
[1] | 744 | // strncpy(psz, list_of_NFS_devices_and_mounts(), MAX_STR_LEN);
|
---|
[116] | 745 | strncpy(psz, list_of_NFS_mounts_only(), MAX_STR_LEN);
|
---|
| 746 | if (bkpinfo->exclude_paths[0]) {
|
---|
[1540] | 747 | strncat(bkpinfo->exclude_paths, " ", 4*MAX_STR_LEN);
|
---|
[116] | 748 | }
|
---|
[1540] | 749 | strncat(bkpinfo->exclude_paths, psz, 4*MAX_STR_LEN);
|
---|
[116] | 750 | log_msg(3, "-N means we're now excluding %s",
|
---|
| 751 | bkpinfo->exclude_paths);
|
---|
| 752 | }
|
---|
[1977] | 753 |
|
---|
[1540] | 754 | if (strlen(bkpinfo->exclude_paths) >= 4*MAX_STR_LEN) {
|
---|
[116] | 755 | fatal_error
|
---|
[1540] | 756 | ("Your '-E' parameter is too long. Increase MAX_STR_LEN");
|
---|
[116] | 757 | }
|
---|
[1977] | 758 |
|
---|
[116] | 759 | if (flag_set['b']) {
|
---|
| 760 | strcpy(psz, flag_val['b']);
|
---|
| 761 | log_msg(1, "psz = '%s'", psz);
|
---|
| 762 | if (psz[strlen(psz) - 1] == 'k') {
|
---|
| 763 | psz[strlen(psz) - 1] = '\0';
|
---|
| 764 | itbs = atol(psz) * 1024L;
|
---|
| 765 | } else {
|
---|
| 766 | itbs = atol(psz);
|
---|
| 767 | }
|
---|
| 768 | log_msg(1, "'%s' --> %ld", flag_val['b'], itbs);
|
---|
| 769 | log_msg(1, "Internal tape block size is now %ld bytes", itbs);
|
---|
| 770 | if (itbs % 512 != 0 || itbs < 256 || itbs > 1024L * 1024) {
|
---|
| 771 | fatal_error
|
---|
| 772 | ("Are you nuts? Silly, your internal tape block size is. Abort, I shall.");
|
---|
| 773 | }
|
---|
| 774 | bkpinfo->internal_tape_block_size = itbs;
|
---|
| 775 | }
|
---|
[1977] | 776 |
|
---|
| 777 | if ((flag_set['D']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 778 | bkpinfo->differential = 1;
|
---|
[1] | 779 | // bkpinfo->differential = atoi (flag_val['D']);
|
---|
[116] | 780 | if ((bkpinfo->differential < 1) || (bkpinfo->differential > 9)) {
|
---|
| 781 | fatal_error
|
---|
| 782 | ("The D option should be between 1 and 9 inclusive");
|
---|
| 783 | }
|
---|
[1] | 784 | }
|
---|
[1977] | 785 |
|
---|
[116] | 786 | if (flag_set['x']) {
|
---|
| 787 | strncpy(bkpinfo->image_devs, flag_val['x'], MAX_STR_LEN / 4);
|
---|
[1977] | 788 | if ((run_program_and_log_output("which ntfsclone", 2)) && (! bkpinfo->restore_data)) {
|
---|
[296] | 789 | fatal_error("Please install ntfsprogs package/tarball.");
|
---|
[116] | 790 | }
|
---|
[1] | 791 | }
|
---|
[1977] | 792 |
|
---|
[116] | 793 | if (flag_set['m']) {
|
---|
| 794 | bkpinfo->manual_cd_tray = TRUE;
|
---|
[1] | 795 | }
|
---|
[1977] | 796 |
|
---|
| 797 | if ((flag_set['k']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 798 | strncpy(bkpinfo->kernel_path, flag_val['k'], MAX_STR_LEN);
|
---|
| 799 | if (!strcmp(bkpinfo->kernel_path, "failsafe")) {
|
---|
| 800 | strcpy(bkpinfo->kernel_path, "FAILSAFE");
|
---|
| 801 | }
|
---|
| 802 | if (strcmp(bkpinfo->kernel_path, "FAILSAFE")
|
---|
| 803 | && !does_file_exist(bkpinfo->kernel_path)) {
|
---|
| 804 | retval++;
|
---|
| 805 | sprintf(tmp,
|
---|
[541] | 806 | "You specified kernel '%s', which does not exist\n",
|
---|
[116] | 807 | bkpinfo->kernel_path);
|
---|
| 808 | log_to_screen(tmp);
|
---|
| 809 | }
|
---|
| 810 | }
|
---|
[1977] | 811 |
|
---|
[116] | 812 | if (flag_set['p']) {
|
---|
| 813 | strncpy(bkpinfo->prefix, flag_val['p'], MAX_STR_LEN / 4);
|
---|
[1977] | 814 | log_msg(1,"Prefix forced to %s",bkpinfo->prefix);
|
---|
[116] | 815 | }
|
---|
[1] | 816 |
|
---|
[116] | 817 | if (flag_set['d']) { /* backup directory (if ISO/NFS) */
|
---|
| 818 | if (flag_set['i']) {
|
---|
| 819 | strncpy(bkpinfo->isodir, flag_val['d'], MAX_STR_LEN / 4);
|
---|
| 820 | sprintf(tmp, "ls -l %s", bkpinfo->isodir);
|
---|
[1737] | 821 | if (run_program_and_log_output(tmp, 2)) {
|
---|
[116] | 822 | fatal_error
|
---|
| 823 | ("output folder does not exist - please create it");
|
---|
| 824 | }
|
---|
| 825 | } else if (flag_set['n']) {
|
---|
| 826 | strncpy(bkpinfo->nfs_remote_dir, flag_val['d'], MAX_STR_LEN);
|
---|
| 827 | } else { /* backup device (if tape/CD-R/CD-RW) */
|
---|
| 828 | strncpy(bkpinfo->media_device, flag_val['d'], MAX_STR_LEN / 4);
|
---|
| 829 | }
|
---|
[1] | 830 | }
|
---|
[116] | 831 |
|
---|
[1977] | 832 | if ((flag_set['n']) && (! bkpinfo->restore_data)) {
|
---|
[1767] | 833 | asprintf(&tmp1,"%s/%s/.dummy.txt", bkpinfo->isodir,bkpinfo->nfs_remote_dir);
|
---|
| 834 | sprintf(tmp, "echo hi > %s", tmp1);
|
---|
[1737] | 835 | if (run_program_and_log_output(tmp, 2)) {
|
---|
[116] | 836 | retval++;
|
---|
| 837 | sprintf(tmp,
|
---|
[541] | 838 | "Are you sure directory '%s' exists in remote dir '%s'?\nIf so, do you have rights to write to it?\n",
|
---|
[116] | 839 | bkpinfo->nfs_remote_dir, bkpinfo->nfs_mount);
|
---|
| 840 | log_to_screen(tmp);
|
---|
| 841 | }
|
---|
[1767] | 842 | unlink(tmp1);
|
---|
| 843 | paranoid_free(tmp1);
|
---|
[1] | 844 | }
|
---|
| 845 |
|
---|
[116] | 846 | if (!flag_set['d']
|
---|
| 847 | && (flag_set['c'] || flag_set['w'] || flag_set['C'])) {
|
---|
| 848 | if (g_kernel_version >= 2.6) {
|
---|
| 849 | if (popup_and_get_string
|
---|
[541] | 850 | ("Device", "Please specify the device",
|
---|
[116] | 851 | bkpinfo->media_device, MAX_STR_LEN / 4)) {
|
---|
| 852 | retval++;
|
---|
[541] | 853 | log_to_screen("User opted to cancel.");
|
---|
[116] | 854 | }
|
---|
| 855 | } else if (find_cdrw_device(bkpinfo->media_device)) {
|
---|
| 856 | retval++;
|
---|
| 857 | log_to_screen
|
---|
[541] | 858 | ("Tried and failed to find CD-R[W] drive automatically.\n");
|
---|
[116] | 859 | } else {
|
---|
| 860 | flag_set['d'] = TRUE;
|
---|
| 861 | strncpy(flag_val['d'], bkpinfo->media_device, MAX_STR_LEN / 4);
|
---|
| 862 | }
|
---|
[1] | 863 | }
|
---|
| 864 |
|
---|
[1977] | 865 | if ((!flag_set['d'] && !flag_set['n'] && !flag_set['C']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 866 | retval++;
|
---|
[541] | 867 | log_to_screen("Please specify the backup device/directory.\n");
|
---|
[116] | 868 | fatal_error
|
---|
| 869 | ("You didn't use -d to specify the backup device/directory.");
|
---|
[1] | 870 | }
|
---|
[1977] | 871 |
|
---|
[116] | 872 | for (i = '0'; i <= '9'; i++) {
|
---|
| 873 | if (flag_set[i]) {
|
---|
| 874 | bkpinfo->compression_level = i - '0';
|
---|
| 875 | } /* not '\0' but '0' */
|
---|
[1] | 876 | }
|
---|
[1977] | 877 |
|
---|
[116] | 878 | if (flag_set['S']) {
|
---|
| 879 | sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%ld", flag_val['S'],
|
---|
| 880 | random() % 32768);
|
---|
[1] | 881 | }
|
---|
[1977] | 882 |
|
---|
[116] | 883 | if (flag_set['T']) {
|
---|
[1655] | 884 | setup_tmpdir(flag_val['T']);
|
---|
| 885 | sprintf(tmp, "touch %s/.foo.dat", bkpinfo->tmpdir);
|
---|
[116] | 886 | if (run_program_and_log_output(tmp, 1)) {
|
---|
| 887 | retval++;
|
---|
| 888 | log_to_screen
|
---|
[541] | 889 | ("Please specify a tempdir which I can write to. :)");
|
---|
[116] | 890 | fatal_error("I cannot write to the tempdir you specified.");
|
---|
| 891 | }
|
---|
[1655] | 892 | sprintf(tmp, "ln -sf %s/.foo.dat %s/.bar.dat", bkpinfo->tmpdir, bkpinfo->tmpdir);
|
---|
[116] | 893 | if (run_program_and_log_output(tmp, 1)) {
|
---|
| 894 | retval++;
|
---|
| 895 | log_to_screen
|
---|
[541] | 896 | ("Please don't specify a SAMBA or VFAT or NFS tmpdir.");
|
---|
[116] | 897 | fatal_error("I cannot write to the tempdir you specified.");
|
---|
| 898 | }
|
---|
[1] | 899 | }
|
---|
[1977] | 900 |
|
---|
| 901 | if ((flag_set['A']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 902 | strncpy(bkpinfo->call_after_iso, flag_val['A'], MAX_STR_LEN);
|
---|
| 903 | }
|
---|
[1977] | 904 |
|
---|
| 905 | if ((flag_set['B']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 906 | strncpy(bkpinfo->call_before_iso, flag_val['B'], MAX_STR_LEN);
|
---|
| 907 | }
|
---|
[1977] | 908 |
|
---|
| 909 | if ((flag_set['H']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 910 | g_cd_recovery = TRUE;
|
---|
| 911 | }
|
---|
[1977] | 912 |
|
---|
| 913 | if ((flag_set['l']) && (! bkpinfo->restore_data)) {
|
---|
[1] | 914 | #ifdef __FreeBSD__
|
---|
| 915 | # define BOOT_LOADER_CHARS "GLBMR"
|
---|
| 916 | #else
|
---|
| 917 | # ifdef __IA64__
|
---|
| 918 | # define BOOT_LOADER_CHARS "GER"
|
---|
| 919 | # else
|
---|
| 920 | # define BOOT_LOADER_CHARS "GLR"
|
---|
| 921 | # endif
|
---|
| 922 | #endif
|
---|
[116] | 923 | if (!strchr
|
---|
| 924 | (BOOT_LOADER_CHARS,
|
---|
| 925 | (bkpinfo->boot_loader = flag_val['l'][0]))) {
|
---|
| 926 | log_msg(1, "%c? WTF is %c? I need G, L, E or R.",
|
---|
| 927 | bkpinfo->boot_loader, bkpinfo->boot_loader);
|
---|
| 928 | fatal_error
|
---|
| 929 | ("Please specify GRUB, LILO, ELILO or RAW with the -l switch");
|
---|
| 930 | }
|
---|
[1] | 931 | #undef BOOT_LOADER_CHARS
|
---|
| 932 | }
|
---|
[1977] | 933 |
|
---|
[116] | 934 | if (flag_set['f']) {
|
---|
| 935 | strncpy(bkpinfo->boot_device,
|
---|
| 936 | resolve_softlinks_to_get_to_actual_device_file(flag_val
|
---|
| 937 | ['f']),
|
---|
| 938 | MAX_STR_LEN / 4);
|
---|
| 939 | }
|
---|
[1977] | 940 |
|
---|
| 941 | if ((flag_set['P']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 942 | strncpy(bkpinfo->postnuke_tarball, flag_val['P'], MAX_STR_LEN);
|
---|
| 943 | }
|
---|
[1977] | 944 |
|
---|
[116] | 945 | if (flag_set['Q']) {
|
---|
| 946 | i = which_boot_loader(tmp);
|
---|
| 947 | log_msg(3, "boot loader is %c, residing at %s", i, tmp);
|
---|
[541] | 948 | printf("boot loader is %c, residing at %s\n", i, tmp);
|
---|
[116] | 949 | finish(0);
|
---|
| 950 | }
|
---|
[1977] | 951 |
|
---|
| 952 | if ((flag_set['L']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 953 | bkpinfo->use_lzo = TRUE;
|
---|
[1737] | 954 | if (run_program_and_log_output("which lzop", 2)) {
|
---|
[116] | 955 | retval++;
|
---|
| 956 | log_to_screen
|
---|
[541] | 957 | ("Please install LZOP. You can't use '-L' until you do.\n");
|
---|
[116] | 958 | }
|
---|
| 959 | }
|
---|
[1] | 960 |
|
---|
[1977] | 961 | if ((flag_set['G']) && (! bkpinfo->restore_data)) {
|
---|
[998] | 962 | bkpinfo->use_gzip = TRUE;
|
---|
[1737] | 963 | if (run_program_and_log_output("which gzip", 2)) {
|
---|
[998] | 964 | retval++;
|
---|
| 965 | log_to_screen
|
---|
| 966 | ("Please install gzip. You can't use '-G' until you do.\n");
|
---|
| 967 | }
|
---|
| 968 | }
|
---|
| 969 |
|
---|
[1977] | 970 | bkpinfo->use_obdr = FALSE;
|
---|
| 971 | if (flag_set['o']) {
|
---|
| 972 | if ((!flag_set['t']) && (! bkpinfo->restore_data)) {
|
---|
| 973 | log_to_screen("OBDR support is only available for tapes. Use the -t option");
|
---|
| 974 | fatal_error("Aborting");
|
---|
| 975 | }
|
---|
| 976 | bkpinfo->use_obdr = TRUE;
|
---|
| 977 | }
|
---|
| 978 |
|
---|
| 979 | #ifndef __FreeBSD__
|
---|
| 980 | if ((!is_this_a_valid_disk_format("vfat")) && (! bkpinfo->restore_data)) {
|
---|
[116] | 981 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
| 982 | log_to_screen
|
---|
[1977] | 983 | ("Your kernel appears not to support vfat filesystems. I am therefore");
|
---|
| 984 | log_to_screen
|
---|
| 985 | ("using LILO instead of SYSLINUX as the media boot loader.");
|
---|
[116] | 986 | }
|
---|
[1977] | 987 | if ((run_program_and_log_output("which mkfs.vfat", 2)) && (! bkpinfo->restore_data)) {
|
---|
[116] | 988 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
[1] | 989 | #ifdef __IA32__
|
---|
[1977] | 990 | log_to_screen
|
---|
| 991 | ("Your filesystem is missing 'mkfs.vfat', so I cannot use SYSLINUX as");
|
---|
| 992 | log_to_screen
|
---|
| 993 | ("your boot loader. I shall therefore use LILO instead.");
|
---|
[1] | 994 | #endif
|
---|
| 995 | #ifdef __IA64__
|
---|
[1977] | 996 | log_to_screen
|
---|
| 997 | ("Your filesystem is missing 'mkfs.vfat', so I cannot prepare the EFI");
|
---|
| 998 | log_to_screen("environment correctly. Please install it.");
|
---|
| 999 | fatal_error("Aborting");
|
---|
[1] | 1000 | #endif
|
---|
[1977] | 1001 | }
|
---|
[1] | 1002 | #ifdef __IA64__
|
---|
[1977] | 1003 | /* We force ELILO usage on IA64 */
|
---|
| 1004 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
[1] | 1005 | #endif
|
---|
| 1006 | #endif
|
---|
| 1007 |
|
---|
[116] | 1008 | if (bkpinfo->make_cd_use_lilo && !does_file_exist("/boot/boot.b")) {
|
---|
| 1009 | paranoid_system("touch /boot/boot.b");
|
---|
| 1010 | }
|
---|
[1] | 1011 |
|
---|
[1977] | 1012 | if (! bkpinfo->restore_data) {
|
---|
[1917] | 1013 | i = flag_set['O'] + flag_set['V'];
|
---|
| 1014 | if (i == 0) {
|
---|
| 1015 | retval++;
|
---|
| 1016 | log_to_screen("Specify backup (-O), verify (-V) or both (-OV).\n");
|
---|
| 1017 | }
|
---|
[116] | 1018 | }
|
---|
[1] | 1019 |
|
---|
[1977] | 1020 | if ((! bkpinfo->restore_data) && (flag_set['Z'])) {
|
---|
| 1021 | fatal_error
|
---|
| 1022 | ("The -Z switch is only valid in restore mode");
|
---|
| 1023 | }
|
---|
| 1024 |
|
---|
| 1025 | if (flag_set['Z']) {
|
---|
| 1026 | if (! strcmp(flag_val['Z'], "nuke")) {
|
---|
| 1027 | bkpinfo->restore_mode = nuke;
|
---|
| 1028 | } else if (! strcmp(flag_val['Z'], "interactive")) {
|
---|
| 1029 | bkpinfo->restore_mode = interactive;
|
---|
| 1030 | } else if (! strcmp(flag_val['Z'], "compare")) {
|
---|
| 1031 | bkpinfo->restore_mode = compare;
|
---|
| 1032 | } else if (! strcmp(flag_val['Z'], "mbr")) {
|
---|
| 1033 | bkpinfo->restore_mode = mbr;
|
---|
| 1034 | } else if (! strcmp(flag_val['Z'], "iso")) {
|
---|
| 1035 | bkpinfo->restore_mode = isoonly;
|
---|
| 1036 | } else if (! strcmp(flag_val['Z'], "isonuke")) {
|
---|
| 1037 | bkpinfo->restore_mode = isonuke;
|
---|
| 1038 | } else {
|
---|
| 1039 | bkpinfo->restore_mode = interactive;
|
---|
| 1040 | }
|
---|
| 1041 | }
|
---|
| 1042 |
|
---|
[1] | 1043 | /* and finally... */
|
---|
| 1044 |
|
---|
[116] | 1045 | paranoid_free(tmp);
|
---|
| 1046 | paranoid_free(psz);
|
---|
| 1047 | return (retval);
|
---|
[1] | 1048 | }
|
---|
| 1049 |
|
---|
| 1050 |
|
---|
| 1051 |
|
---|
| 1052 | /**
|
---|
| 1053 | * Get the switches from @p argc and @p argv using getopt() and place them in
|
---|
| 1054 | * @p flag_set and @p flag_val.
|
---|
| 1055 | * @param argc The argument count (@p argc passed to main()).
|
---|
| 1056 | * @param argv The argument vector (@p argv passed to main()).
|
---|
| 1057 | * @param flag_val An array indexed by switch letter - if a switch is set and
|
---|
| 1058 | * has an argument then set flag_val[switch] to that argument.
|
---|
| 1059 | * @param flag_set An array indexed by switch letter - if a switch is set then
|
---|
| 1060 | * set flag_set[switch] to TRUE, else set it to FALSE.
|
---|
| 1061 | * @return The number of problems with the command line (0 for success).
|
---|
| 1062 | */
|
---|
| 1063 | int
|
---|
[116] | 1064 | retrieve_switches_from_command_line(int argc, char *argv[],
|
---|
| 1065 | char flag_val[128][MAX_STR_LEN],
|
---|
| 1066 | bool flag_set[128])
|
---|
[1] | 1067 | {
|
---|
[116] | 1068 | /*@ ints ** */
|
---|
| 1069 | int opt = 0;
|
---|
| 1070 | char tmp[MAX_STR_LEN];
|
---|
| 1071 | int i = 0;
|
---|
| 1072 | int len;
|
---|
[1] | 1073 |
|
---|
[116] | 1074 | /*@ bools *** */
|
---|
| 1075 | bool bad_switches = FALSE;
|
---|
[1] | 1076 |
|
---|
[116] | 1077 | assert(flag_val != NULL);
|
---|
| 1078 | assert(flag_set != NULL);
|
---|
[1] | 1079 |
|
---|
[116] | 1080 | for (i = 0; i < 128; i++) {
|
---|
| 1081 | flag_val[i][0] = '\0';
|
---|
| 1082 | flag_set[i] = FALSE;
|
---|
[1] | 1083 | }
|
---|
[116] | 1084 | while ((opt =
|
---|
[1917] | 1085 | getopt(argc, argv, MONDO_OPTIONS))
|
---|
[116] | 1086 | != -1) {
|
---|
| 1087 | if (opt == '?') {
|
---|
| 1088 | bad_switches = TRUE;
|
---|
| 1089 | /*log_it("Invalid option: %c\n",optopt); */
|
---|
| 1090 | } else {
|
---|
| 1091 | if (flag_set[optopt]) {
|
---|
| 1092 | bad_switches = TRUE;
|
---|
[541] | 1093 | sprintf(tmp, "Switch -%c previously defined as %s\n", opt,
|
---|
[116] | 1094 | flag_val[i]);
|
---|
| 1095 | log_to_screen(tmp);
|
---|
| 1096 | } else {
|
---|
| 1097 | flag_set[opt] = TRUE;
|
---|
| 1098 | if (optarg) {
|
---|
| 1099 | len = strlen(optarg);
|
---|
| 1100 | if (optarg[0] != '/' && optarg[len - 1] == '/') {
|
---|
| 1101 | optarg[--len] = '\0';
|
---|
| 1102 | log_to_screen
|
---|
[541] | 1103 | ("Warning - param '%s' should not have trailing slash!",
|
---|
[116] | 1104 | optarg);
|
---|
| 1105 | }
|
---|
| 1106 | if (opt == 'd') {
|
---|
| 1107 | if (strchr(flag_val[opt], '/')
|
---|
| 1108 | && flag_val[opt][0] != '/') {
|
---|
| 1109 | sprintf(tmp,
|
---|
[541] | 1110 | "-%c flag --- must be absolute path --- '%s' isn't absolute",
|
---|
[116] | 1111 | opt, flag_val[opt]);
|
---|
| 1112 | log_to_screen(tmp);
|
---|
| 1113 | bad_switches = TRUE;
|
---|
| 1114 | }
|
---|
| 1115 | }
|
---|
| 1116 | strcpy(flag_val[opt], optarg);
|
---|
| 1117 | }
|
---|
| 1118 | }
|
---|
[1] | 1119 | }
|
---|
| 1120 | }
|
---|
[116] | 1121 | for (i = optind; i < argc; i++) {
|
---|
| 1122 | bad_switches = TRUE;
|
---|
[541] | 1123 | sprintf(tmp, "Invalid arg -- %s\n", argv[i]);
|
---|
[116] | 1124 | log_to_screen(tmp);
|
---|
| 1125 | }
|
---|
| 1126 | return (bad_switches);
|
---|
[1] | 1127 | }
|
---|
| 1128 |
|
---|
| 1129 |
|
---|
| 1130 |
|
---|
| 1131 |
|
---|
| 1132 | /**
|
---|
| 1133 | * Print a not-so-helpful help message and exit.
|
---|
| 1134 | */
|
---|
[116] | 1135 | void help_screen()
|
---|
[1] | 1136 | {
|
---|
[1977] | 1137 | log_msg(1, "Type 'man mondoarchive' for more information\n");
|
---|
[116] | 1138 | exit(1);
|
---|
[1] | 1139 | }
|
---|
| 1140 |
|
---|
| 1141 |
|
---|
| 1142 | /**
|
---|
| 1143 | * Terminate Mondo in response to a signal.
|
---|
| 1144 | * @param sig The signal number received.
|
---|
| 1145 | */
|
---|
| 1146 | void terminate_daemon(int sig)
|
---|
| 1147 | {
|
---|
[116] | 1148 | char tmp[64];
|
---|
| 1149 | char tmp2[MAX_STR_LEN];
|
---|
| 1150 | // char command[512];
|
---|
| 1151 | // pid_t pid;
|
---|
[1] | 1152 |
|
---|
[116] | 1153 | switch (sig) {
|
---|
[1] | 1154 | case SIGINT:
|
---|
| 1155 | sprintf(tmp, "SIGINT");
|
---|
[541] | 1156 | strcpy(tmp2, "You interrupted me :-)");
|
---|
[1] | 1157 | break;
|
---|
| 1158 | case SIGKILL:
|
---|
| 1159 | sprintf(tmp, "SIGKILL");
|
---|
[116] | 1160 | strcpy(tmp2,
|
---|
[541] | 1161 | "I seriously have no clue how this signal even got to me. Something's wrong with your system.");
|
---|
[1] | 1162 | break;
|
---|
| 1163 | case SIGTERM:
|
---|
| 1164 | sprintf(tmp, "SIGTERM");
|
---|
[541] | 1165 | strcpy(tmp2, "Got terminate signal");
|
---|
[1] | 1166 | break;
|
---|
| 1167 | case SIGHUP:
|
---|
| 1168 | sprintf(tmp, "SIGHUP");
|
---|
[541] | 1169 | strcpy(tmp2, "Hangup on line");
|
---|
[1] | 1170 | break;
|
---|
| 1171 | case SIGSEGV:
|
---|
| 1172 | sprintf(tmp, "SIGSEGV");
|
---|
[116] | 1173 | strcpy(tmp2,
|
---|
[541] | 1174 | "Internal programming error. Please send a backtrace as well as your log.");
|
---|
[1] | 1175 | break;
|
---|
| 1176 | case SIGPIPE:
|
---|
| 1177 | sprintf(tmp, "SIGPIPE");
|
---|
[541] | 1178 | strcpy(tmp2, "Pipe was broken");
|
---|
[1] | 1179 | break;
|
---|
[116] | 1180 | case SIGABRT:
|
---|
| 1181 | sprintf(tmp, "SIGABRT");
|
---|
| 1182 | sprintf(tmp2,
|
---|
[541] | 1183 | "Abort - probably failed assertion. I'm sleeping for a few seconds so you can read the message.");
|
---|
[116] | 1184 | break;
|
---|
[1] | 1185 | default:
|
---|
[541] | 1186 | sprintf(tmp, "(Unknown)");
|
---|
[116] | 1187 | }
|
---|
[1] | 1188 |
|
---|
[541] | 1189 | strcat(tmp, " signal received from OS");
|
---|
[116] | 1190 | log_to_screen(tmp);
|
---|
| 1191 | log_to_screen(tmp2);
|
---|
| 1192 | if (sig == SIGABRT) {
|
---|
| 1193 | sleep(10);
|
---|
| 1194 | }
|
---|
| 1195 | kill_buffer();
|
---|
[1977] | 1196 |
|
---|
| 1197 | free_MR_global_filenames();
|
---|
| 1198 |
|
---|
[116] | 1199 | fatal_error
|
---|
[1977] | 1200 | ("MondoRescue is terminating in response to a signal from the OS");
|
---|
[116] | 1201 | finish(254); // just in case
|
---|
[1] | 1202 | }
|
---|
| 1203 |
|
---|
| 1204 |
|
---|
| 1205 |
|
---|
| 1206 |
|
---|
| 1207 | /**
|
---|
| 1208 | * Turn signal-trapping on or off.
|
---|
| 1209 | * @param on If TRUE, turn it on; if FALSE, turn it off (we still trap it, just don't do as much).
|
---|
| 1210 | */
|
---|
| 1211 | void set_signals(int on)
|
---|
| 1212 | {
|
---|
[116] | 1213 | int signals[] =
|
---|
| 1214 | { SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGKILL, SIGSTOP, 0 };
|
---|
| 1215 | int i;
|
---|
| 1216 |
|
---|
| 1217 | signal(SIGPIPE, sigpipe_occurred);
|
---|
| 1218 | for (i = 0; signals[i]; i++) {
|
---|
| 1219 | if (on) {
|
---|
| 1220 | signal(signals[i], terminate_daemon);
|
---|
| 1221 | } else {
|
---|
| 1222 | signal(signals[i], termination_in_progress);
|
---|
| 1223 | }
|
---|
| 1224 | }
|
---|
[1] | 1225 | }
|
---|
| 1226 |
|
---|
| 1227 |
|
---|
| 1228 |
|
---|
| 1229 |
|
---|
| 1230 | /**
|
---|
| 1231 | * Exit immediately without cleaning up.
|
---|
| 1232 | * @param sig The signal we are exiting due to.
|
---|
| 1233 | */
|
---|
| 1234 | void termination_in_progress(int sig)
|
---|
| 1235 | {
|
---|
[116] | 1236 | log_msg(1, "Termination in progress");
|
---|
| 1237 | usleep(1000);
|
---|
| 1238 | pthread_exit(0);
|
---|
[1] | 1239 | }
|
---|
| 1240 |
|
---|
| 1241 | /* @} - end of cliGroup */
|
---|