[1] | 1 | /***************************************************************************
|
---|
| 2 | mondo-rstr-tools.c - description
|
---|
| 3 | -----------------
|
---|
| 4 |
|
---|
| 5 | begin: Sun Sep 21 16:40:35 EDT 2003
|
---|
| 6 | copyright : (C) 2002 Mondo Hugo Rabson
|
---|
| 7 | email : Hugo Rabson <hugorabson@msn.com>
|
---|
| 8 | edited by : by Stan Benoit ?/2003
|
---|
| 9 | email : troff@nakedsoul.org
|
---|
| 10 | cvsid : $Id: mondo-rstr-tools.c
|
---|
| 11 | ***************************************************************************/
|
---|
| 12 |
|
---|
| 13 | /***************************************************************************
|
---|
[1242] | 14 | * *
|
---|
| 15 | * This program is free software; you can redistribute it and/or modify *
|
---|
| 16 | * it under the terms of the GNU General Public License as published by *
|
---|
| 17 | * the Free Software Foundation; either version 2 of the License, or *
|
---|
| 18 | * (at your option) any later version. *
|
---|
| 19 | * *
|
---|
| 20 | ***************************************************************************/
|
---|
[1] | 21 | /* mondo-rstr-tools.c Hugo Rabson
|
---|
| 22 |
|
---|
| 23 |
|
---|
| 24 | 07/27
|
---|
| 25 | - if the user is foolish enough to use /dev/md0 as boot device,
|
---|
[1242] | 26 | call lilo -M /dev/hda to make sure lilo does its job properly
|
---|
[1] | 27 | - better NFS+nuke support
|
---|
| 28 |
|
---|
| 29 | 07/20
|
---|
| 30 | - use backup's i-want-my-lvm file
|
---|
| 31 | - be sure to use archives' raidtab when restoring
|
---|
| 32 |
|
---|
| 33 | 07/18
|
---|
| 34 | - use /tmp/isodir for NFS if DR mode
|
---|
| 35 | - better support of users who boot from LVM CD and nuke-restore non-LVM backups
|
---|
| 36 |
|
---|
| 37 | 07/12
|
---|
| 38 | - bugfix to allow user to burn ISOs to CDs and restore from CDs (not original src)
|
---|
| 39 |
|
---|
| 40 | 06/29
|
---|
| 41 | - mount ext3 partitions as ext2, just in case :)
|
---|
| 42 |
|
---|
| 43 | 06/26
|
---|
| 44 | - delete make_relevant_partition_bootable()
|
---|
| 45 |
|
---|
| 46 | 06/19
|
---|
| 47 | - futzed with the call to mount floppy, to stop it from locking up on my AMD64 system
|
---|
| 48 |
|
---|
| 49 | 06/14
|
---|
| 50 | - shell out to /mnt/RESTORING chroot in order to let user install GRUB
|
---|
[1242] | 51 | manually if automatic GRUB installation fails
|
---|
[1] | 52 |
|
---|
| 53 | 06/15
|
---|
| 54 | - Added check for different 'isodir' chosen by user than stored in the archive
|
---|
[1242] | 55 | Conor Daly <conor.daly@met.ie>
|
---|
[1] | 56 |
|
---|
| 57 | 04/17
|
---|
| 58 | - replaced INTERNAL_TAPE_BLK_SIZE with bkpinfo->internal_tape_block_size
|
---|
| 59 |
|
---|
| 60 | 04/09
|
---|
| 61 | - don't try to mount CD if tape bkp
|
---|
| 62 |
|
---|
| 63 | 04/03
|
---|
| 64 | - trying to copy tmp/mondo-restore.cfg to itself - silly! - fixed
|
---|
| 65 |
|
---|
| 66 | 04/02
|
---|
| 67 | - when extracting cfg file and mountlist from all.tar.gz (tape copy),
|
---|
[1242] | 68 | use block size of INTERNAL_TAPE_BLK_SIZE, not TAPE_BLOCK_SIZE
|
---|
[1] | 69 |
|
---|
| 70 | 02/21
|
---|
| 71 | - don't use 'mv -v' cos Busybox won't support it
|
---|
| 72 |
|
---|
| 73 | 02/09
|
---|
| 74 | - make hole for cfg file before moving it (line 2094 or so)
|
---|
| 75 |
|
---|
| 76 | 02/03
|
---|
| 77 | - changed a couple of refs to filelist.full, to filelist.full.gz
|
---|
| 78 |
|
---|
| 79 | 01/16/2004
|
---|
| 80 | - instead of copying filelist, use 'ln -sf' to link to original;
|
---|
[1242] | 81 | saves space
|
---|
[1] | 82 |
|
---|
| 83 | 11/20/2003
|
---|
| 84 | - also retrieve /tmp/mountlist.txt if user wants
|
---|
| 85 |
|
---|
| 86 | 11/16
|
---|
| 87 | - fixed NFS path bug affecting the extractions of filelist/biggielist
|
---|
[1242] | 88 | during selective restore
|
---|
[1] | 89 |
|
---|
| 90 | 11/02
|
---|
| 91 | - fixed mount_cdrom() to run properly w/ nfs restores
|
---|
| 92 | - mount_device() returns 0 if swap mount fails cos swap isn't crucial
|
---|
| 93 |
|
---|
| 94 | 10/17
|
---|
| 95 | - run_grub() uses MNT_RESTORING instead of "/mnt/RESTORING"
|
---|
| 96 |
|
---|
| 97 | 10/26
|
---|
| 98 | - cleaned up run_grub()
|
---|
| 99 |
|
---|
| 100 | 10/25
|
---|
| 101 | - fixed mount_cdrom() to run properly w/ nfs restores
|
---|
| 102 |
|
---|
| 103 | 10/21
|
---|
| 104 | - mount_device() returns 0 if swap mount fails cos swap isn't crucial
|
---|
| 105 |
|
---|
| 106 | 10/15
|
---|
| 107 | - run_grub() now uses its initiative instead
|
---|
[1242] | 108 | of calling grub-install
|
---|
[1] | 109 |
|
---|
| 110 | 10/10
|
---|
| 111 | - don't leave copies of filelist.full lying around, clogging up
|
---|
[1242] | 112 | the ramdisk, there's a good fellow :-)
|
---|
[1] | 113 |
|
---|
| 114 | 10/02
|
---|
| 115 | - added 'dvd' to the range of media types I'll understand
|
---|
| 116 | - fixed iso->cdr problem (thanks, Stan Benoit & Fred Beondo)
|
---|
| 117 |
|
---|
| 118 | 09/24
|
---|
| 119 | - try lots of tape devs if /dev/st0 fails
|
---|
| 120 |
|
---|
| 121 | 09/23/2003
|
---|
| 122 | - first incarnation
|
---|
| 123 | */
|
---|
| 124 |
|
---|
| 125 |
|
---|
| 126 | #include <pthread.h>
|
---|
| 127 | #include "../common/my-stuff.h"
|
---|
| 128 | #include "../common/mondostructures.h"
|
---|
| 129 | #include "../common/libmondo.h"
|
---|
| 130 | #include "mr-externs.h"
|
---|
| 131 | //#include "mondo-restore.h"
|
---|
| 132 | //#include "mondo-rstr-compare-EXT.h"
|
---|
| 133 | #include "mondo-rstr-tools.h"
|
---|
| 134 |
|
---|
| 135 | extern bool g_sigpipe_caught;
|
---|
[128] | 136 | extern bool g_ISO_restore_mode; /* are we in Iso Mode? */
|
---|
[1] | 137 | extern bool g_I_have_just_nuked;
|
---|
| 138 | extern char *g_tmpfs_mountpt;
|
---|
| 139 | extern char *g_isodir_device;
|
---|
| 140 | extern char *g_isodir_format;
|
---|
| 141 | extern long g_current_progress, g_maximum_progress;
|
---|
[128] | 142 | extern char *g_biggielist_txt; // where 'biggielist.txt' is stored, on ramdisk / tempdir;
|
---|
[1242] | 143 | // biggielist.txt is the list of big files stored on the
|
---|
| 144 | // backup media set in question
|
---|
[128] | 145 | extern char *g_filelist_full; // filelist.full.gz is the list of all regular files
|
---|
[1242] | 146 | // (excluding big files) stored on the backup media set
|
---|
[128] | 147 | extern char *g_biggielist_pot; // list of big files which _could_ be restored, if the
|
---|
[1242] | 148 | // user chooses them
|
---|
[128] | 149 | extern char *g_filelist_imagedevs; // list of devices (e.g. /dev/hda1, /dev/sda5) which
|
---|
[1242] | 150 | // were archived as images, not just /dev entries
|
---|
| 151 | // ... e.g. NTFS, BeOS partitions
|
---|
[128] | 152 | extern char *g_imagedevs_restthese; // of the imagedevs listed in FILELIST_IMAGEDEVS,
|
---|
[1242] | 153 | // restore only these
|
---|
[128] | 154 | extern char *g_mondo_cfg_file; // where m*ndo-restore.cfg (the config file) is stored
|
---|
| 155 | extern char *g_mountlist_fname; // where mountlist.txt (the mountlist file) is stored
|
---|
| 156 | extern char *g_mondo_home; // homedir of Mondo; usually /usr/local/share/mondo
|
---|
[1] | 157 |
|
---|
| 158 | extern t_bkptype g_backup_media_type;
|
---|
| 159 |
|
---|
| 160 | extern int g_partition_table_locked_up;
|
---|
[1316] | 161 | extern char *MONDO_LOGFILE;
|
---|
[1] | 162 |
|
---|
[1645] | 163 | /* Reference to global bkpinfo */
|
---|
| 164 | extern struct s_bkpinfo *bkpinfo;
|
---|
| 165 |
|
---|
[949] | 166 | /* Should we use or not extended attributes and acl when restoring */
|
---|
| 167 | char *g_getfattr = NULL;
|
---|
| 168 | char *g_getfacl = NULL;
|
---|
| 169 |
|
---|
[1] | 170 | /**
|
---|
[1242] | 171 | * @addtogroup restoreUtilityGroup
|
---|
| 172 | * @{
|
---|
| 173 | */
|
---|
[1] | 174 | /**
|
---|
[1242] | 175 | * Free the malloc()s for the filename variables.
|
---|
| 176 | */
|
---|
[1] | 177 | void free_MR_global_filenames()
|
---|
| 178 | {
|
---|
[1242] | 179 | paranoid_free(g_biggielist_txt);
|
---|
| 180 | paranoid_free(g_filelist_full);
|
---|
| 181 | paranoid_free(g_filelist_imagedevs);
|
---|
[1] | 182 | // paranoid_free (g_imagedevs_pot );
|
---|
[1242] | 183 | paranoid_free(g_imagedevs_restthese);
|
---|
| 184 | paranoid_free(g_mondo_cfg_file);
|
---|
| 185 | paranoid_free(g_mountlist_fname);
|
---|
| 186 | paranoid_free(g_mondo_home);
|
---|
| 187 | paranoid_free(g_tmpfs_mountpt);
|
---|
| 188 | paranoid_free(g_isodir_device);
|
---|
| 189 | paranoid_free(g_isodir_format);
|
---|
[1] | 190 |
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 |
|
---|
| 194 |
|
---|
| 195 | /**
|
---|
[1242] | 196 | * Ask the user which imagedevs from the list contained in @p infname should
|
---|
| 197 | * actually be restored.
|
---|
| 198 | * @param infname The file containing a list of all imagedevs.
|
---|
| 199 | * @param outfname The location of the output file containing the imagedevs the user wanted to restore.
|
---|
| 200 | * @ingroup restoreUtilityGroup
|
---|
| 201 | */
|
---|
[128] | 202 | void ask_about_these_imagedevs(char *infname, char *outfname)
|
---|
[1] | 203 | {
|
---|
[1242] | 204 | FILE *fin;
|
---|
| 205 | FILE *fout;
|
---|
| 206 | /************************************************************************
|
---|
| 207 | * allocate memory regions. test and set -sab 16 feb 2003 *
|
---|
| 208 | ************************************************************************/
|
---|
| 209 | char *incoming_ptr;
|
---|
| 210 | char *question_ptr;
|
---|
[1] | 211 |
|
---|
[1242] | 212 | char incoming[MAX_STR_LEN] = "\0";
|
---|
| 213 | char question[MAX_STR_LEN];
|
---|
[1] | 214 |
|
---|
[1242] | 215 | assert_string_is_neither_NULL_nor_zerolength(infname);
|
---|
| 216 | assert_string_is_neither_NULL_nor_zerolength(outfname);
|
---|
[1] | 217 |
|
---|
[1242] | 218 | incoming_ptr = malloc(sizeof(incoming));
|
---|
| 219 | if (incoming_ptr == NULL) {
|
---|
| 220 | fprintf(stderr, "Out of Memory\n");
|
---|
| 221 | exit(EXIT_FAILURE);
|
---|
| 222 | }
|
---|
[1] | 223 |
|
---|
[1242] | 224 | question_ptr = malloc(sizeof(question));
|
---|
| 225 | if (question_ptr == NULL) {
|
---|
| 226 | fprintf(stderr, "Out of Memory\n");
|
---|
| 227 | exit(EXIT_FAILURE);
|
---|
| 228 | }
|
---|
[1] | 229 |
|
---|
[1242] | 230 | memset(incoming_ptr, '\0', sizeof(incoming));
|
---|
| 231 | memset(question_ptr, '\0', sizeof(question));
|
---|
[1] | 232 |
|
---|
| 233 |
|
---|
| 234 |
|
---|
[1242] | 235 | if (!(fin = fopen(infname, "r"))) {
|
---|
| 236 | fatal_error("Cannot openin infname");
|
---|
| 237 | }
|
---|
| 238 | if (!(fout = fopen(outfname, "w"))) {
|
---|
| 239 | fatal_error("Cannot openin outfname");
|
---|
| 240 | }
|
---|
| 241 | for (fgets(incoming_ptr, MAX_STR_LEN, fin);
|
---|
| 242 | !feof(fin); fgets(incoming_ptr, MAX_STR_LEN, fin)) {
|
---|
| 243 | strip_spaces(incoming_ptr);
|
---|
[1] | 244 |
|
---|
[1242] | 245 | if (incoming[0] == '\0') {
|
---|
| 246 | continue;
|
---|
| 247 | }
|
---|
[1] | 248 |
|
---|
[1242] | 249 | sprintf(question_ptr,
|
---|
| 250 | "Should I restore the image of %s ?", incoming_ptr);
|
---|
[128] | 251 |
|
---|
[1242] | 252 | if (ask_me_yes_or_no(question_ptr)) {
|
---|
| 253 | fprintf(fout, "%s\n", incoming_ptr);
|
---|
| 254 | }
|
---|
| 255 | }
|
---|
[128] | 256 |
|
---|
[1242] | 257 | /*** free memory ***********/
|
---|
| 258 | paranoid_free(incoming_ptr);
|
---|
| 259 | incoming_ptr = NULL;
|
---|
| 260 | paranoid_free(question_ptr);
|
---|
| 261 | question_ptr = NULL;
|
---|
[1] | 262 |
|
---|
[128] | 263 |
|
---|
[1242] | 264 | paranoid_fclose(fout);
|
---|
| 265 | paranoid_fclose(fin);
|
---|
[1] | 266 | }
|
---|
| 267 |
|
---|
| 268 | /**************************************************************************
|
---|
[1242] | 269 | *ASK_ABOUT_THESE_IMAGEDEVS *
|
---|
| 270 | **************************************************************************/
|
---|
[1] | 271 |
|
---|
| 272 |
|
---|
| 273 |
|
---|
| 274 |
|
---|
| 275 |
|
---|
| 276 |
|
---|
| 277 |
|
---|
| 278 |
|
---|
| 279 | /**
|
---|
[1242] | 280 | * Extract @c mondo-restore.cfg and @c mountlist.txt from @p ramdisk_fname.
|
---|
| 281 | * @param bkpinfo The backup information structure. @c tmpdir is the only field used.
|
---|
| 282 | * @param ramdisk_fname The filename of the @b compressed ramdisk to look in.
|
---|
| 283 | * @param output_cfg_file Where to put the configuration file extracted.
|
---|
| 284 | * @param output_mountlist_file Where to put the mountlist file extracted.
|
---|
| 285 | * @return 0 for success, nonzero for failure.
|
---|
| 286 | * @ingroup restoreUtilityGroup
|
---|
| 287 | */
|
---|
[128] | 288 | int
|
---|
[1645] | 289 | extract_config_file_from_ramdisk(char *ramdisk_fname,
|
---|
[1242] | 290 | char *output_cfg_file,
|
---|
| 291 | char *output_mountlist_file)
|
---|
[1] | 292 | {
|
---|
[1242] | 293 | char *mountpt;
|
---|
| 294 | char *command;
|
---|
| 295 | char *orig_fname;
|
---|
| 296 | int retval = 0;
|
---|
[1] | 297 |
|
---|
[1242] | 298 | assert(bkpinfo != NULL);
|
---|
| 299 | malloc_string(mountpt);
|
---|
| 300 | malloc_string(command);
|
---|
| 301 | malloc_string(orig_fname);
|
---|
| 302 | assert_string_is_neither_NULL_nor_zerolength(ramdisk_fname);
|
---|
| 303 | assert_string_is_neither_NULL_nor_zerolength(output_cfg_file);
|
---|
| 304 | assert_string_is_neither_NULL_nor_zerolength(output_mountlist_file);
|
---|
| 305 | sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
|
---|
| 306 | sprintf(command, "mkdir -p %s", mountpt);
|
---|
| 307 | run_program_and_log_output(command, FALSE);
|
---|
| 308 | sprintf(command, "gzip -dc %s > %s/mindi.rd 2> /dev/null",
|
---|
| 309 | ramdisk_fname, bkpinfo->tmpdir);
|
---|
[1] | 310 |
|
---|
[1242] | 311 | run_program_and_log_output(command, FALSE);
|
---|
| 312 | sprintf(command, "umount %s", mountpt);
|
---|
[1] | 313 |
|
---|
[1242] | 314 | run_program_and_log_output(command, FALSE);
|
---|
[1] | 315 |
|
---|
[1242] | 316 | sprintf(command, "mount -o loop %s/mindi.rd -t ext2 %s",
|
---|
| 317 | bkpinfo->tmpdir, mountpt);
|
---|
[1] | 318 |
|
---|
[1242] | 319 | run_program_and_log_output(command, FALSE);
|
---|
[1] | 320 |
|
---|
[1242] | 321 | sprintf(command, "mkdir -p %s/tmp", bkpinfo->tmpdir);
|
---|
[1] | 322 |
|
---|
[1242] | 323 | run_program_and_log_output(command, FALSE);
|
---|
[1] | 324 |
|
---|
[1242] | 325 | sprintf(command, "cp -f %s/%s %s", // %s/%s becomes {mountpt}/tmp/m*ndo-restore.cfg
|
---|
| 326 | mountpt, g_mondo_cfg_file, output_cfg_file);
|
---|
| 327 | run_program_and_log_output(command, FALSE);
|
---|
[1] | 328 |
|
---|
[1242] | 329 | sprintf(orig_fname, "%s/%s", mountpt, g_mountlist_fname);
|
---|
| 330 | if (does_file_exist(orig_fname)) {
|
---|
| 331 | sprintf(command, "cp -f %s %s", orig_fname, output_mountlist_file);
|
---|
| 332 | run_program_and_log_output(command, FALSE);
|
---|
| 333 | }
|
---|
| 334 | sprintf(command, "umount %s", mountpt);
|
---|
| 335 | run_program_and_log_output(command, FALSE);
|
---|
| 336 | if (!does_file_exist(output_cfg_file)
|
---|
| 337 | || (!does_file_exist(output_mountlist_file)
|
---|
| 338 | && does_file_exist(orig_fname))) {
|
---|
| 339 | log_msg(2, "Failed to extract %s and/or %s from ramdisk",
|
---|
| 340 | output_cfg_file, output_mountlist_file);
|
---|
| 341 | retval = 1;
|
---|
| 342 | } else {
|
---|
| 343 | retval = 0;
|
---|
| 344 | }
|
---|
| 345 | paranoid_free(mountpt);
|
---|
| 346 | paranoid_free(command);
|
---|
| 347 | paranoid_free(orig_fname);
|
---|
| 348 | return (retval);
|
---|
[128] | 349 |
|
---|
[1] | 350 | }
|
---|
| 351 |
|
---|
| 352 |
|
---|
| 353 |
|
---|
| 354 |
|
---|
| 355 | /**
|
---|
[1242] | 356 | * Keep trying to get mondo-restore.cfg from the archive, until the user gives up.
|
---|
| 357 | */
|
---|
[1645] | 358 | void get_cfg_file_from_archive_or_bust()
|
---|
[1] | 359 | {
|
---|
[1645] | 360 | while (get_cfg_file_from_archive()) {
|
---|
[1242] | 361 | if (!ask_me_yes_or_no
|
---|
| 362 | ("Failed to find config file/archives. Choose another source?"))
|
---|
| 363 | {
|
---|
| 364 | fatal_error("Could not find config file/archives. Aborting.");
|
---|
[1] | 365 | }
|
---|
[1645] | 366 | interactively_obtain_media_parameters_from_user(FALSE);
|
---|
[1242] | 367 | }
|
---|
| 368 | }
|
---|
[1] | 369 |
|
---|
| 370 |
|
---|
| 371 | /**
|
---|
[1242] | 372 | * Determine whether @p list_fname contains a line containing @p f.
|
---|
| 373 | * @param f The line to search for.
|
---|
| 374 | * @param list_fname The file to search in.
|
---|
| 375 | * @param preamble Ignore this beginning part of @p f ("" to disable).
|
---|
| 376 | * @return TRUE if it's in the list, FALSE if it's not.
|
---|
| 377 | */
|
---|
[128] | 378 | bool is_file_in_list(char *f, char *list_fname, char *preamble)
|
---|
[1] | 379 | {
|
---|
| 380 |
|
---|
[1242] | 381 | /** needs malloc **/
|
---|
| 382 | char *command;
|
---|
| 383 | char *file;
|
---|
| 384 | char *tmp;
|
---|
| 385 | int res;
|
---|
[1] | 386 |
|
---|
[1242] | 387 | malloc_string(command);
|
---|
| 388 | malloc_string(file);
|
---|
| 389 | malloc_string(tmp);
|
---|
| 390 | assert_string_is_neither_NULL_nor_zerolength(f);
|
---|
| 391 | assert_string_is_neither_NULL_nor_zerolength(list_fname);
|
---|
| 392 | assert(preamble != NULL);
|
---|
[1] | 393 |
|
---|
[1242] | 394 | if (strncmp(preamble, f, strlen(preamble)) == 0) {
|
---|
| 395 | strcpy(file, f + strlen(preamble));
|
---|
| 396 | } else {
|
---|
| 397 | strcpy(file, f);
|
---|
[1] | 398 | }
|
---|
[1242] | 399 | if (file[0] == '/' && file[1] == '/') {
|
---|
| 400 | strcpy(tmp, file);
|
---|
| 401 | strcpy(file, tmp + 1);
|
---|
| 402 | }
|
---|
| 403 | sprintf(tmp,
|
---|
| 404 | "Checking to see if f=%s, file=%s, is in the list of biggiefiles",
|
---|
| 405 | f, file);
|
---|
| 406 | log_msg(2, tmp);
|
---|
| 407 | sprintf(command, "grep -E '^%s$' %s", file, list_fname);
|
---|
| 408 | res = run_program_and_log_output(command, FALSE);
|
---|
| 409 | paranoid_free(command);
|
---|
| 410 | paranoid_free(file);
|
---|
| 411 | paranoid_free(tmp);
|
---|
| 412 | if (res) {
|
---|
| 413 | return (FALSE);
|
---|
| 414 | } else {
|
---|
| 415 | return (TRUE);
|
---|
| 416 | }
|
---|
| 417 | }
|
---|
[128] | 418 |
|
---|
[1] | 419 | /**************************************************************************
|
---|
[1242] | 420 | *END_IS_FILE_IN_LIST *
|
---|
| 421 | **************************************************************************/
|
---|
[1] | 422 |
|
---|
| 423 |
|
---|
| 424 |
|
---|
| 425 | /**
|
---|
[1242] | 426 | * Set up an ISO backup.
|
---|
| 427 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 428 | * - @c bkpinfo->backup_media_type
|
---|
| 429 | * - @c bkpinfo->disaster_recovery
|
---|
| 430 | * - @c bkpinfo->isodir
|
---|
| 431 | * @param nuke_me_please If TRUE, we're in nuke mode; if FALSE we're in interactive mode.
|
---|
| 432 | * @return 0 for success, nonzero for failure.
|
---|
| 433 | */
|
---|
[1645] | 434 | int iso_fiddly_bits(bool nuke_me_please)
|
---|
[1] | 435 | {
|
---|
[1242] | 436 | char *mount_isodir_command, *tmp, *command;
|
---|
| 437 | int retval = 0, i;
|
---|
| 438 | bool already_mounted = FALSE;
|
---|
[1] | 439 |
|
---|
[1242] | 440 | assert(bkpinfo != NULL);
|
---|
| 441 | malloc_string(mount_isodir_command);
|
---|
| 442 | malloc_string(tmp);
|
---|
| 443 | malloc_string(command);
|
---|
| 444 | g_ISO_restore_mode = TRUE;
|
---|
| 445 | read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
|
---|
| 446 | if (bkpinfo->disaster_recovery) {
|
---|
[1] | 447 | /* Patch Conor Daly 26-june-2004
|
---|
[1242] | 448 | * Don't let this clobber an existing bkpinfo->isodir */
|
---|
| 449 | if (!bkpinfo->isodir[0]) {
|
---|
| 450 | strcpy(bkpinfo->isodir, "/tmp/isodir");
|
---|
| 451 | }
|
---|
[1] | 452 | /* End patch */
|
---|
[1242] | 453 | sprintf(command, "mkdir -p %s", bkpinfo->isodir);
|
---|
| 454 | run_program_and_log_output(command, 5);
|
---|
| 455 | log_msg(2, "Setting isodir to %s", bkpinfo->isodir);
|
---|
| 456 | }
|
---|
[1] | 457 |
|
---|
[1242] | 458 | if (!get_isodir_info
|
---|
| 459 | (g_isodir_device, g_isodir_format, bkpinfo->isodir,
|
---|
| 460 | nuke_me_please)) {
|
---|
| 461 | return (1);
|
---|
| 462 | }
|
---|
| 463 | paranoid_system("umount " MNT_CDROM " 2> /dev/null"); /* just in case */
|
---|
[1] | 464 |
|
---|
[1242] | 465 | if (is_this_device_mounted(g_isodir_device)) {
|
---|
| 466 | log_to_screen("WARNING - isodir is already mounted");
|
---|
| 467 | already_mounted = TRUE;
|
---|
| 468 | } else {
|
---|
| 469 | sprintf(mount_isodir_command, "mount %s", g_isodir_device);
|
---|
| 470 | if (strlen(g_isodir_format) > 1) {
|
---|
| 471 | sprintf(mount_isodir_command + strlen(mount_isodir_command),
|
---|
| 472 | " -t %s", g_isodir_format);
|
---|
[1] | 473 | }
|
---|
[1242] | 474 | strcat(mount_isodir_command, " -o ro ");
|
---|
| 475 | strcat(mount_isodir_command, bkpinfo->isodir);
|
---|
| 476 | run_program_and_log_output("df -m", FALSE);
|
---|
| 477 | sprintf(tmp,
|
---|
| 478 | "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?",
|
---|
| 479 | mount_isodir_command);
|
---|
| 480 | log_msg(1, tmp);
|
---|
| 481 | if (run_program_and_log_output(mount_isodir_command, FALSE)) {
|
---|
| 482 | popup_and_OK
|
---|
| 483 | ("Cannot mount the device where the ISO files are stored.");
|
---|
| 484 | return (1);
|
---|
| 485 | }
|
---|
| 486 | log_to_screen
|
---|
| 487 | ("I have mounted the device where the ISO files are stored.");
|
---|
| 488 | }
|
---|
| 489 | if (!IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
[1736] | 490 | mount_media();
|
---|
[1242] | 491 | }
|
---|
[1736] | 492 | i = what_number_cd_is_this(); /* has the side-effect of calling mount_media() */
|
---|
[1242] | 493 | sprintf(tmp, "%s #%d has been mounted via loopback mount",
|
---|
| 494 | media_descriptor_string(bkpinfo->backup_media_type), i);
|
---|
| 495 | log_msg(1, tmp);
|
---|
| 496 | if (i < 0) {
|
---|
| 497 | popup_and_OK
|
---|
| 498 | ("Cannot find ISO images in the directory you specified.");
|
---|
| 499 | retval = 1;
|
---|
| 500 | }
|
---|
| 501 | log_msg(2, "%ld: bkpinfo->isodir is now %s", __LINE__,
|
---|
| 502 | bkpinfo->isodir);
|
---|
| 503 | paranoid_free(mount_isodir_command);
|
---|
| 504 | paranoid_free(tmp);
|
---|
| 505 | paranoid_free(command);
|
---|
| 506 | return (retval);
|
---|
| 507 | }
|
---|
[1] | 508 |
|
---|
| 509 |
|
---|
| 510 |
|
---|
| 511 |
|
---|
| 512 | /**
|
---|
[1242] | 513 | * Kill all Petris processes.
|
---|
| 514 | */
|
---|
[128] | 515 | void kill_petris(void)
|
---|
[1] | 516 | {
|
---|
[1242] | 517 | char *command;
|
---|
| 518 | malloc_string(command);
|
---|
| 519 | sprintf(command,
|
---|
| 520 | "kill `ps 2> /dev/null | grep petris 2> /dev/null | grep -v grep | cut -d' ' -f2` 2> /dev/null");
|
---|
| 521 | paranoid_system(command);
|
---|
| 522 | paranoid_free(command);
|
---|
[1] | 523 | }
|
---|
[128] | 524 |
|
---|
[1] | 525 | /**************************************************************************
|
---|
[1242] | 526 | *END_KILL_PETRIS *
|
---|
| 527 | **************************************************************************/
|
---|
[1] | 528 |
|
---|
| 529 |
|
---|
| 530 | /**
|
---|
[1242] | 531 | * Mount all devices in @p p_external_copy_of_mountlist on @p MNT_RESTORING.
|
---|
| 532 | * @param p_external_copy_of_mountlist The mountlist containing devices to be mounted.
|
---|
| 533 | * @param writeable If TRUE, then mount read-write; if FALSE mount read-only.
|
---|
| 534 | * @return The number of errors encountered (0 for success).
|
---|
| 535 | */
|
---|
[128] | 536 | int mount_all_devices(struct mountlist_itself
|
---|
[1242] | 537 | *p_external_copy_of_mountlist, bool writeable)
|
---|
[1] | 538 | {
|
---|
[1242] | 539 | int retval = 0, lino, res;
|
---|
| 540 | char *tmp, *these_failed, *format;
|
---|
| 541 | struct mountlist_itself *mountlist;
|
---|
[1] | 542 |
|
---|
[1242] | 543 | malloc_string(tmp);
|
---|
| 544 | malloc_string(format);
|
---|
| 545 | malloc_string(these_failed);
|
---|
| 546 | assert(p_external_copy_of_mountlist != NULL);
|
---|
| 547 | mountlist = malloc(sizeof(struct mountlist_itself));
|
---|
| 548 | memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist,
|
---|
| 549 | sizeof(struct mountlist_itself));
|
---|
| 550 | sort_mountlist_by_mountpoint(mountlist, 0);
|
---|
[1] | 551 |
|
---|
[1242] | 552 | /** menset **/
|
---|
| 553 | these_failed[0] = '\0';
|
---|
[1] | 554 |
|
---|
[1242] | 555 | mvaddstr_and_log_it(g_currentY, 0, "Mounting devices ");
|
---|
| 556 | open_progress_form("Mounting devices",
|
---|
| 557 | "I am now mounting all the drives.",
|
---|
| 558 | "This should not take long.",
|
---|
| 559 | "", mountlist->entries);
|
---|
[128] | 560 |
|
---|
[1242] | 561 | for (lino = 0; lino < mountlist->entries; lino++) {
|
---|
| 562 | if (!strcmp(mountlist->el[lino].device, "/proc")) {
|
---|
| 563 | log_msg(1,
|
---|
| 564 | "Again with the /proc - why is this in your mountlist?");
|
---|
| 565 | } else if (is_this_device_mounted(mountlist->el[lino].device)) {
|
---|
| 566 | sprintf(tmp, "%s is already mounted",
|
---|
| 567 | mountlist->el[lino].device);
|
---|
| 568 | log_to_screen(tmp);
|
---|
| 569 | } else if (strcmp(mountlist->el[lino].mountpoint, "none")
|
---|
| 570 | && strcmp(mountlist->el[lino].mountpoint, "lvm")
|
---|
| 571 | && strcmp(mountlist->el[lino].mountpoint, "raid")
|
---|
| 572 | && strcmp(mountlist->el[lino].mountpoint, "image")) {
|
---|
| 573 | sprintf(tmp, "Mounting %s", mountlist->el[lino].device);
|
---|
| 574 | update_progress_form(tmp);
|
---|
| 575 | strcpy(format, mountlist->el[lino].format);
|
---|
[1741] | 576 | /* BERLIOS: removed as it doen't make sens to not mount ext3 partitions as ext3
|
---|
[1242] | 577 | if (!strcmp(format, "ext3")) {
|
---|
| 578 | strcpy(format, "ext2");
|
---|
[1] | 579 | }
|
---|
[1741] | 580 | */
|
---|
[1242] | 581 | res = mount_device(mountlist->el[lino].device,
|
---|
| 582 | mountlist->el[lino].mountpoint,
|
---|
| 583 | format, writeable);
|
---|
| 584 | retval += res;
|
---|
| 585 | if (res) {
|
---|
| 586 | strcat(these_failed, mountlist->el[lino].device);
|
---|
| 587 | strcat(these_failed, " ");
|
---|
[1] | 588 | }
|
---|
| 589 | }
|
---|
[1242] | 590 | g_current_progress++;
|
---|
| 591 | }
|
---|
| 592 | close_progress_form();
|
---|
| 593 | run_program_and_log_output("df -m", TRUE);
|
---|
| 594 | if (retval) {
|
---|
| 595 | if (g_partition_table_locked_up > 0) {
|
---|
| 596 | log_to_screen
|
---|
| 597 | ("fdisk's ictol() call to refresh its copy of the partition table causes the kernel to");
|
---|
| 598 | log_to_screen
|
---|
| 599 | ("lock up the partition table. You might have to reboot and use Interactive Mode to");
|
---|
| 600 | log_to_screen
|
---|
| 601 | ("format and restore *without* partitioning first. Sorry for the inconvenience.");
|
---|
| 602 | }
|
---|
[1541] | 603 | sprintf(tmp, "Could not mount device(s) %s- shall I abort?",
|
---|
[1242] | 604 | these_failed);
|
---|
| 605 | if (!ask_me_yes_or_no(tmp)) {
|
---|
| 606 | retval = 0;
|
---|
| 607 | log_to_screen
|
---|
[1541] | 608 | ("Continuing, although some device(s) failed to be mounted");
|
---|
[1242] | 609 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
| 610 | } else {
|
---|
| 611 | mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
|
---|
| 612 | log_to_screen
|
---|
| 613 | ("Unable to mount some or all of your partitions.");
|
---|
| 614 | }
|
---|
| 615 | } else {
|
---|
| 616 | log_to_screen("All partitions were mounted OK.");
|
---|
| 617 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
| 618 | }
|
---|
| 619 | run_program_and_log_output("df -m", 3);
|
---|
| 620 | paranoid_free(mountlist);
|
---|
| 621 | paranoid_free(tmp);
|
---|
| 622 | paranoid_free(format);
|
---|
| 623 | paranoid_free(these_failed);
|
---|
| 624 | return (retval);
|
---|
| 625 | }
|
---|
[128] | 626 |
|
---|
[1242] | 627 | /**************************************************************************
|
---|
| 628 | *END_MOUNT_ALL_DEVICES *
|
---|
| 629 | **************************************************************************/
|
---|
[1] | 630 |
|
---|
| 631 |
|
---|
| 632 | /**
|
---|
[1736] | 633 | * Mount the CD-ROM or USB device at /mnt/cdrom.
|
---|
[1242] | 634 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 635 | * - @c bkpinfo->backup_media_type
|
---|
| 636 | * - @c bkpinfo->disaster_recovery
|
---|
| 637 | * - @c bkpinfo->isodir
|
---|
| 638 | * - @c bkpinfo->media_device
|
---|
| 639 | * @return 0 for success, nonzero for failure.
|
---|
| 640 | */
|
---|
[1736] | 641 | int mount_media()
|
---|
[1] | 642 | {
|
---|
[1242] | 643 | char *mount_cmd;
|
---|
| 644 | int i, res;
|
---|
[1] | 645 | #ifdef __FreeBSD__
|
---|
[1242] | 646 | char mdd[32];
|
---|
| 647 | char *mddev = mdd;
|
---|
[1] | 648 | #endif
|
---|
| 649 |
|
---|
[1242] | 650 | malloc_string(mount_cmd);
|
---|
| 651 | assert(bkpinfo != NULL);
|
---|
[1] | 652 |
|
---|
[1242] | 653 | if (bkpinfo->backup_media_type == tape
|
---|
[1736] | 654 | || bkpinfo->backup_media_type == udev) {
|
---|
| 655 | log_msg(8, "Tape/udev. Therefore, no need to mount a media.");
|
---|
| 656 | paranoid_free(mount_cmd);
|
---|
| 657 | return 0;
|
---|
[1242] | 658 | }
|
---|
[1] | 659 |
|
---|
[1242] | 660 | if (!run_program_and_log_output("mount | grep -F " MNT_CDROM, FALSE)) {
|
---|
[1736] | 661 | log_msg(2, "mount_media() - media already mounted. Fair enough.");
|
---|
| 662 | paranoid_free(mount_cmd);
|
---|
| 663 | return (0);
|
---|
[1242] | 664 | }
|
---|
[1] | 665 |
|
---|
[1242] | 666 | if (bkpinfo->backup_media_type == nfs) {
|
---|
[1736] | 667 | log_msg(2, "Mounting for NFS thingy");
|
---|
| 668 | log_msg(2, "isodir = %s", bkpinfo->isodir);
|
---|
| 669 | if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/"))
|
---|
| 670 | && am_I_in_disaster_recovery_mode()) {
|
---|
| 671 | strcpy(bkpinfo->isodir, "/tmp/isodir");
|
---|
| 672 | log_msg(1, "isodir is being set to %s", bkpinfo->isodir);
|
---|
| 673 | }
|
---|
[1] | 674 | #ifdef __FreeBSD__
|
---|
[1736] | 675 | sprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir,
|
---|
[1242] | 676 | bkpinfo->nfs_remote_dir, bkpinfo->prefix, g_current_media_number);
|
---|
[1736] | 677 | mddev = make_vn(mount_cmd);
|
---|
| 678 | sprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev);
|
---|
[1] | 679 | #else
|
---|
[1736] | 680 | sprintf(mount_cmd, "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s",
|
---|
[1242] | 681 | bkpinfo->isodir, bkpinfo->nfs_remote_dir,
|
---|
| 682 | bkpinfo->prefix, g_current_media_number, MNT_CDROM);
|
---|
[1] | 683 | #endif
|
---|
| 684 |
|
---|
[1736] | 685 | } else if (bkpinfo->backup_media_type == iso) {
|
---|
[1] | 686 | #ifdef __FreeBSD__
|
---|
[1736] | 687 | sprintf(mount_cmd, "%s/%s-%d.iso", bkpinfo->isodir,
|
---|
[1242] | 688 | bkpinfo->prefix, g_current_media_number);
|
---|
[1736] | 689 | mddev = make_vn(mount_cmd);
|
---|
| 690 | sprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM);
|
---|
[1] | 691 | #else
|
---|
[1736] | 692 | sprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s",
|
---|
[1242] | 693 | bkpinfo->isodir, bkpinfo->prefix, g_current_media_number, MNT_CDROM);
|
---|
[1] | 694 | #endif
|
---|
[1738] | 695 | } else if (bkpinfo->backup_media_type == usb) {
|
---|
[1741] | 696 | sprintf(mount_cmd, "mount -t vfat %s %s", bkpinfo->media_device, MNT_CDROM);
|
---|
[1738] | 697 | } else if (strstr(bkpinfo->media_device, "/dev/")) {
|
---|
[1] | 698 | #ifdef __FreeBSD__
|
---|
[1736] | 699 | sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
|
---|
[1242] | 700 | MNT_CDROM);
|
---|
[1] | 701 | #else
|
---|
[1736] | 702 | sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
|
---|
[1242] | 703 | bkpinfo->media_device, MNT_CDROM);
|
---|
[1] | 704 | #endif
|
---|
[1242] | 705 | } else {
|
---|
[1736] | 706 | if (bkpinfo->disaster_recovery
|
---|
| 707 | && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
|
---|
| 708 | strcpy(bkpinfo->media_device,
|
---|
| 709 | last_line_of_file("/tmp/CDROM-LIVES-HERE"));
|
---|
| 710 | } else {
|
---|
| 711 | find_cdrom_device(bkpinfo->media_device, TRUE);
|
---|
| 712 | }
|
---|
[1] | 713 |
|
---|
| 714 | #ifdef __FreeBSD__
|
---|
[1738] | 715 | sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
|
---|
| 716 | MNT_CDROM);
|
---|
[1] | 717 | #else
|
---|
[1738] | 718 | sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
|
---|
| 719 | bkpinfo->media_device, MNT_CDROM);
|
---|
[1] | 720 | #endif
|
---|
[1736] | 721 | }
|
---|
[1] | 722 |
|
---|
[1736] | 723 | log_msg(2, "(mount_media) --- command = %s", mount_cmd);
|
---|
[1242] | 724 | for (i = 0; i < 2; i++) {
|
---|
| 725 | res = run_program_and_log_output(mount_cmd, FALSE);
|
---|
| 726 | if (!res) {
|
---|
| 727 | break;
|
---|
| 728 | } else {
|
---|
[1736] | 729 | log_msg(2, "Failed to mount device.");
|
---|
[1242] | 730 | sleep(5);
|
---|
| 731 | run_program_and_log_output("sync", FALSE);
|
---|
| 732 | }
|
---|
| 733 | }
|
---|
| 734 | if (res) {
|
---|
[1736] | 735 | log_msg(2, "Failed, despite %d attempts", i);
|
---|
[1242] | 736 | } else {
|
---|
[1736] | 737 | log_msg(2, "Mounted CD-ROM drive OK");
|
---|
[1242] | 738 | }
|
---|
| 739 | paranoid_free(mount_cmd);
|
---|
| 740 | return (res);
|
---|
| 741 | }
|
---|
[1] | 742 |
|
---|
| 743 |
|
---|
| 744 |
|
---|
| 745 |
|
---|
| 746 |
|
---|
| 747 | /**************************************************************************
|
---|
[1242] | 748 | *END_MOUNT_CDROM *
|
---|
| 749 | **************************************************************************/
|
---|
[1] | 750 |
|
---|
| 751 |
|
---|
| 752 | /**
|
---|
[1242] | 753 | * Mount @p device at @p mpt as @p format.
|
---|
| 754 | * @param device The device (/dev entry) to mount.
|
---|
| 755 | * @param mpt The directory to mount it on.
|
---|
| 756 | * @param format The filesystem type of @p device.
|
---|
| 757 | * @param writeable If TRUE, mount read-write; if FALSE, mount read-only.
|
---|
| 758 | * @return 0 for success, nonzero for failure.
|
---|
| 759 | */
|
---|
[128] | 760 | int mount_device(char *device, char *mpt, char *format, bool writeable)
|
---|
[1] | 761 | {
|
---|
[1242] | 762 | int res = 0;
|
---|
[1] | 763 |
|
---|
[1242] | 764 | /** malloc **/
|
---|
| 765 | char *tmp, *command, *mountdir, *mountpoint, *additional_parameters;
|
---|
[1] | 766 |
|
---|
[1242] | 767 | assert_string_is_neither_NULL_nor_zerolength(device);
|
---|
| 768 | assert_string_is_neither_NULL_nor_zerolength(mpt);
|
---|
| 769 | assert(format != NULL);
|
---|
| 770 | malloc_string(tmp);
|
---|
| 771 | malloc_string(command);
|
---|
| 772 | malloc_string(mountdir);
|
---|
| 773 | malloc_string(mountpoint);
|
---|
| 774 | malloc_string(additional_parameters);
|
---|
[1] | 775 |
|
---|
[1242] | 776 | if (!strcmp(mpt, "/1")) {
|
---|
[1451] | 777 | strcpy(mountpoint, "/");
|
---|
| 778 | log_msg(3, "Mommm! SME is being a dildo!");
|
---|
[1242] | 779 | } else {
|
---|
[1451] | 780 | strcpy(mountpoint, mpt);
|
---|
[1242] | 781 | }
|
---|
[1] | 782 |
|
---|
[1242] | 783 | if (!strcmp(mountpoint, "lvm")) {
|
---|
[1451] | 784 | return (0);
|
---|
[1242] | 785 | }
|
---|
| 786 | if (!strcmp(mountpoint, "image")) {
|
---|
[1451] | 787 | return (0);
|
---|
[1242] | 788 | }
|
---|
| 789 | sprintf(tmp, "Mounting device %s ", device);
|
---|
| 790 | log_msg(1, tmp);
|
---|
| 791 | if (writeable) {
|
---|
[1451] | 792 | strcpy(additional_parameters, "-o rw");
|
---|
[1242] | 793 | } else {
|
---|
[1451] | 794 | strcpy(additional_parameters, "-o ro");
|
---|
[1242] | 795 | }
|
---|
| 796 | if (find_home_of_exe("setfattr")) {
|
---|
[1451] | 797 | strcat(additional_parameters, ",user_xattr");
|
---|
[1242] | 798 | }
|
---|
| 799 | if (find_home_of_exe("setfacl")) {
|
---|
[1451] | 800 | strcat(additional_parameters, ",acl");
|
---|
[1242] | 801 | }
|
---|
[1] | 802 |
|
---|
[1242] | 803 | if (!strcmp(mountpoint, "swap")) {
|
---|
[1451] | 804 | sprintf(command, "swapon %s", device);
|
---|
[1242] | 805 | } else {
|
---|
| 806 | if (!strcmp(mountpoint, "/")) {
|
---|
| 807 | strcpy(mountdir, MNT_RESTORING);
|
---|
| 808 | } else {
|
---|
| 809 | sprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint);
|
---|
| 810 | }
|
---|
| 811 | sprintf(command, "mkdir -p %s", mountdir);
|
---|
| 812 | run_program_and_log_output(command, FALSE);
|
---|
| 813 | sprintf(command, "mount -t %s %s %s %s 2>> %s", format, device,
|
---|
| 814 | additional_parameters, mountdir, MONDO_LOGFILE);
|
---|
| 815 | log_msg(2, "command='%s'", command);
|
---|
| 816 | }
|
---|
| 817 | res = run_program_and_log_output(command, TRUE);
|
---|
| 818 | if (res && (strstr(command, "xattr") || strstr(command, "acl"))) {
|
---|
[1451] | 819 | log_msg(1, "Re-trying without the fancy extra parameters");
|
---|
| 820 | sprintf(command, "mount -t %s %s %s 2>> %s", format, device,
|
---|
[1242] | 821 | mountdir, MONDO_LOGFILE);
|
---|
[1451] | 822 | res = run_program_and_log_output(command, TRUE);
|
---|
[1242] | 823 | }
|
---|
| 824 | if (res) {
|
---|
[1451] | 825 | log_msg(1, "Unable to mount device %s (type %s) at %s", device,
|
---|
[1242] | 826 | format, mountdir);
|
---|
[1451] | 827 | log_msg(1, "command was '%s'", command);
|
---|
| 828 | if (!strcmp(mountpoint, "swap")) {
|
---|
| 829 | log_to_screen(tmp);
|
---|
| 830 | } else {
|
---|
| 831 | log_msg(2, "Retrying w/o the '-t' switch");
|
---|
| 832 | sprintf(command, "mount %s %s 2>> %s", device, mountdir,
|
---|
[1242] | 833 | MONDO_LOGFILE);
|
---|
[1451] | 834 | log_msg(2, "2nd command = '%s'", command);
|
---|
| 835 | res = run_program_and_log_output(command, TRUE);
|
---|
| 836 | if (res == 0) {
|
---|
| 837 | log_msg(1,
|
---|
[1242] | 838 | "That's OK. I called mount w/o a filesystem type and it worked fine in the end.");
|
---|
[1451] | 839 | } else {
|
---|
| 840 | log_to_screen(tmp);
|
---|
| 841 | }
|
---|
[128] | 842 | }
|
---|
[1242] | 843 | }
|
---|
| 844 | if (res && !strcmp(mountpoint, "swap")) {
|
---|
[1451] | 845 | log_msg(2, "That's ok. It's just a swap partition.");
|
---|
| 846 | log_msg(2, "Non-fatal error. Returning 0.");
|
---|
| 847 | res = 0;
|
---|
[1242] | 848 | }
|
---|
[1] | 849 |
|
---|
[1242] | 850 | paranoid_free(tmp);
|
---|
| 851 | paranoid_free(command);
|
---|
| 852 | paranoid_free(mountdir);
|
---|
| 853 | paranoid_free(mountpoint);
|
---|
| 854 | paranoid_free(additional_parameters);
|
---|
[128] | 855 |
|
---|
[1242] | 856 | return (res);
|
---|
[1] | 857 | }
|
---|
[128] | 858 |
|
---|
[1] | 859 | /**************************************************************************
|
---|
[1242] | 860 | *END_MOUNT_DEVICE *
|
---|
| 861 | **************************************************************************/
|
---|
[1] | 862 |
|
---|
| 863 |
|
---|
| 864 |
|
---|
| 865 | /**
|
---|
[1242] | 866 | * Fix some miscellaneous things in the filesystem so the system will come
|
---|
| 867 | * up correctly on the first boot.
|
---|
| 868 | */
|
---|
[128] | 869 | void protect_against_braindead_sysadmins()
|
---|
[1] | 870 | {
|
---|
[1242] | 871 | run_program_and_log_output("touch " MNT_RESTORING "/var/log/pacct",
|
---|
| 872 | FALSE);
|
---|
| 873 | run_program_and_log_output("touch " MNT_RESTORING "/var/account/pacct",
|
---|
| 874 | FALSE);
|
---|
| 875 | if (run_program_and_log_output("ls " MNT_RESTORING " /tmp", FALSE)) {
|
---|
| 876 | run_program_and_log_output("chmod 1777 " MNT_RESTORING "/tmp",
|
---|
| 877 | FALSE);
|
---|
[1] | 878 | }
|
---|
[1242] | 879 | run_program_and_log_output("mkdir -p " MNT_RESTORING
|
---|
| 880 | "/var/run/console", FALSE);
|
---|
| 881 | run_program_and_log_output("chmod 777 " MNT_RESTORING "/dev/null",
|
---|
| 882 | FALSE);
|
---|
| 883 | run_program_and_log_output("cd " MNT_RESTORING
|
---|
| 884 | "; for i in `ls home/`; do echo \"Moving $i's spurious files to $i/.disabled\"; mkdir \"$i\"/.disabled ; mv -f \"$i\"/.DCOP* \"$i\"/.MCOP* \"$i\"/.*authority \"$i\"/.kde/tmp* \"$i\"/.kde/socket* \"$i\"/.disabled/ ; done",
|
---|
| 885 | TRUE);
|
---|
| 886 | run_program_and_log_output("rm -f " MNT_RESTORING "/var/run/*.pid",
|
---|
| 887 | TRUE);
|
---|
| 888 | run_program_and_log_output("rm -f " MNT_RESTORING "/var/lock/subsys/*",
|
---|
| 889 | TRUE);
|
---|
| 890 | }
|
---|
[128] | 891 |
|
---|
[1] | 892 | /**************************************************************************
|
---|
[1242] | 893 | *END_PROTECT_AGAINST_BRAINDEAD_SYSADMINS *
|
---|
| 894 | **************************************************************************/
|
---|
[1] | 895 |
|
---|
| 896 |
|
---|
| 897 |
|
---|
| 898 |
|
---|
| 899 | /**
|
---|
[1242] | 900 | * Fill out @p bkpinfo based on @p cfg_file.
|
---|
| 901 | * @param cfg_file The mondo-restore.cfg file to read into @p bkpinfo.
|
---|
| 902 | * @param bkpinfo The backup information structure to fill out with information
|
---|
| 903 | * from @p cfg_file.
|
---|
| 904 | * @return 0 for success, nonzero for failure.
|
---|
| 905 | */
|
---|
[1645] | 906 | int read_cfg_file_into_bkpinfo(char *cfgf)
|
---|
[1] | 907 | {
|
---|
[1242] | 908 | /** add mallocs **/
|
---|
| 909 | char *value = NULL;
|
---|
| 910 | char *tmp = NULL;
|
---|
| 911 | char *envtmp1 = NULL;
|
---|
| 912 | char *envtmp2 = NULL;
|
---|
| 913 | char *command = NULL;
|
---|
| 914 | char *iso_mnt = NULL;
|
---|
| 915 | char *iso_path = NULL;
|
---|
| 916 | char *old_isodir = NULL;
|
---|
| 917 | char cfg_file[100];
|
---|
| 918 | t_bkptype media_specified_by_user;
|
---|
[1] | 919 |
|
---|
[1242] | 920 | malloc_string(command);
|
---|
| 921 | malloc_string(iso_mnt);
|
---|
| 922 | malloc_string(iso_path);
|
---|
| 923 | malloc_string(old_isodir);
|
---|
| 924 | malloc_string(value);
|
---|
| 925 | malloc_string(tmp);
|
---|
[1] | 926 | // assert_string_is_neither_NULL_nor_zerolength(cfg_file);
|
---|
[1242] | 927 | assert(bkpinfo != NULL);
|
---|
[1] | 928 |
|
---|
[1242] | 929 | if (!cfgf) {
|
---|
| 930 | strcpy(cfg_file, g_mondo_cfg_file);
|
---|
| 931 | } else {
|
---|
| 932 | strcpy(cfg_file, cfgf);
|
---|
| 933 | }
|
---|
[1] | 934 |
|
---|
[1242] | 935 | media_specified_by_user = bkpinfo->backup_media_type; // or 'none', if not specified
|
---|
[1] | 936 |
|
---|
[1242] | 937 | if (0 == read_cfg_var(cfg_file, "backup-media-type", value)) {
|
---|
| 938 | if (!strcmp(value, "cdstream")) {
|
---|
| 939 | bkpinfo->backup_media_type = cdstream;
|
---|
| 940 | } else if (!strcmp(value, "cdr")) {
|
---|
| 941 | bkpinfo->backup_media_type = cdr;
|
---|
| 942 | } else if (!strcmp(value, "cdrw")) {
|
---|
| 943 | bkpinfo->backup_media_type = cdrw;
|
---|
| 944 | } else if (!strcmp(value, "dvd")) {
|
---|
| 945 | bkpinfo->backup_media_type = dvd;
|
---|
[1736] | 946 | } else if (!strcmp(value, "usb")) {
|
---|
| 947 | bkpinfo->backup_media_type = usb;
|
---|
[1746] | 948 | bkpinfo->please_dont_eject = TRUE;
|
---|
[1242] | 949 | } else if (!strcmp(value, "iso")) {
|
---|
[1] | 950 | /*
|
---|
[1242] | 951 | if (am_I_in_disaster_recovery_mode()
|
---|
| 952 | && !run_program_and_log_output("mount /dev/cdrom "MNT_CDROM, 1)
|
---|
| 953 | && does_file_exist(MNT_CDROM"/archives/filelist.0"))
|
---|
[1] | 954 | */
|
---|
| 955 |
|
---|
| 956 | // Patch by Conor Daly - 2004/07/12
|
---|
[1242] | 957 | bkpinfo->backup_media_type = iso;
|
---|
| 958 | if (am_I_in_disaster_recovery_mode()) {
|
---|
| 959 | /* Check to see if CD is already mounted before mounting it... */
|
---|
| 960 | if (!is_this_device_mounted("/dev/cdrom")) {
|
---|
| 961 | log_msg(2,
|
---|
| 962 | "NB: CDROM device not mounted, mounting...");
|
---|
| 963 | run_program_and_log_output("mount /dev/cdrom "
|
---|
| 964 | MNT_CDROM, 1);
|
---|
[128] | 965 | }
|
---|
[1242] | 966 | if (does_file_exist(MNT_CDROM "/archives/filelist.0")) {
|
---|
| 967 | bkpinfo->backup_media_type = cdr;
|
---|
| 968 | run_program_and_log_output("umount " MNT_CDROM, 1);
|
---|
| 969 | log_it
|
---|
| 970 | ("Re-jigging configuration AGAIN. CD-R, not ISO.");
|
---|
| 971 | }
|
---|
| 972 | }
|
---|
| 973 | if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
|
---|
| 974 | strcpy(bkpinfo->prefix,value);
|
---|
[128] | 975 | } else {
|
---|
[1242] | 976 | strcpy(bkpinfo->prefix,STD_PREFIX);
|
---|
[1] | 977 | }
|
---|
[1242] | 978 | } else if (!strcmp(value, "nfs")) {
|
---|
| 979 | bkpinfo->backup_media_type = nfs;
|
---|
| 980 | if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
|
---|
| 981 | strcpy(bkpinfo->prefix,value);
|
---|
[128] | 982 | } else {
|
---|
[1242] | 983 | strcpy(bkpinfo->prefix,STD_PREFIX);
|
---|
[1] | 984 | }
|
---|
[1242] | 985 | if (strstr(call_program_and_get_last_line_of_output
|
---|
| 986 | ("cat /proc/cmdline"), "pxe")) {
|
---|
| 987 | /* We need to override prefix value in PXE mode as it's
|
---|
| 988 | * already done in start-nfs */
|
---|
| 989 | envtmp1 = getenv("imgname");
|
---|
| 990 | if (envtmp1 == NULL) {
|
---|
| 991 | fatal_error("no imgname variable in environment");
|
---|
[949] | 992 | }
|
---|
[1242] | 993 | strcpy(bkpinfo->prefix,envtmp1);
|
---|
[949] | 994 | }
|
---|
| 995 |
|
---|
[1242] | 996 | } else if (!strcmp(value, "tape")) {
|
---|
| 997 | bkpinfo->backup_media_type = tape;
|
---|
| 998 | } else if (!strcmp(value, "udev")) {
|
---|
| 999 | bkpinfo->backup_media_type = udev;
|
---|
| 1000 | } else {
|
---|
| 1001 | fatal_error("UNKNOWN bkp-media-type");
|
---|
| 1002 | }
|
---|
| 1003 | } else {
|
---|
| 1004 | fatal_error("backup-media-type not specified!");
|
---|
| 1005 | }
|
---|
| 1006 | if (bkpinfo->disaster_recovery) {
|
---|
[1736] | 1007 | if (bkpinfo->backup_media_type == cdstream) {
|
---|
| 1008 | sprintf(bkpinfo->media_device, "/dev/cdrom");
|
---|
[1242] | 1009 | // bkpinfo->media_size[0] = -1;
|
---|
[1736] | 1010 | bkpinfo->media_size[0] = 1999 * 1024;
|
---|
| 1011 | bkpinfo->media_size[1] = 650; /* good guess */
|
---|
| 1012 | } else if (bkpinfo->backup_media_type == usb) {
|
---|
| 1013 | if (read_cfg_var(cfg_file, "usb-dev", value)) {
|
---|
| 1014 | fatal_error("Cannot get USB device name from cfg file");
|
---|
| 1015 | }
|
---|
[1741] | 1016 | sprintf(bkpinfo->media_device, "%s1", value);
|
---|
[1736] | 1017 | sprintf(tmp, "Backup medium is USB --- dev=%s", bkpinfo->media_device);
|
---|
| 1018 | log_msg(2, tmp);
|
---|
| 1019 | } else if (bkpinfo->backup_media_type == tape
|
---|
| 1020 | || bkpinfo->backup_media_type == udev) {
|
---|
| 1021 | if (read_cfg_var(cfg_file, "media-dev", value)) {
|
---|
| 1022 | fatal_error("Cannot get tape device name from cfg file");
|
---|
| 1023 | }
|
---|
| 1024 | strcpy(bkpinfo->media_device, value);
|
---|
| 1025 | read_cfg_var(cfg_file, "media-size", value);
|
---|
| 1026 | bkpinfo->media_size[1] = atol(value);
|
---|
| 1027 | sprintf(tmp, "Backup medium is TAPE --- dev=%s",
|
---|
| 1028 | bkpinfo->media_device);
|
---|
| 1029 | log_msg(2, tmp);
|
---|
| 1030 | } else {
|
---|
| 1031 | strcpy(bkpinfo->media_device, "/dev/cdrom"); /* we don't really need this var */
|
---|
| 1032 | bkpinfo->media_size[0] = 1999 * 1024; /* 650, probably, but we don't need this var anyway */
|
---|
| 1033 | bkpinfo->media_size[1] = 1999 * 1024; /* 650, probably, but we don't need this var anyway */
|
---|
| 1034 | log_msg(2, "Backup medium is CD-R[W]");
|
---|
[1] | 1035 | }
|
---|
[1242] | 1036 | } else {
|
---|
[1736] | 1037 | log_msg(2,
|
---|
[1242] | 1038 | "Not in Disaster Recovery Mode. No need to derive device name from config file.");
|
---|
| 1039 | }
|
---|
[128] | 1040 |
|
---|
[1242] | 1041 | read_cfg_var(cfg_file, "use-star", value);
|
---|
| 1042 | if (strstr(value, "yes")) {
|
---|
| 1043 | bkpinfo->use_star = TRUE;
|
---|
| 1044 | log_msg(1, "Goody! ... bkpinfo->use_star is now true.");
|
---|
| 1045 | }
|
---|
| 1046 |
|
---|
| 1047 | read_cfg_var(cfg_file, "acl", value);
|
---|
| 1048 | if (strstr(value, "TRUE")) {
|
---|
| 1049 | asprintf(&g_getfacl,"setfacl");
|
---|
| 1050 | log_msg(1, "We will restore ACLs");
|
---|
| 1051 | if (! find_home_of_exe("setfacl")) {
|
---|
| 1052 | log_msg(1, "Unable to restore ACLs as no setfacl found");
|
---|
| 1053 | }
|
---|
| 1054 | }
|
---|
| 1055 | read_cfg_var(cfg_file, "xattr", value);
|
---|
| 1056 | if (strstr(value, "TRUE")) {
|
---|
| 1057 | asprintf(&g_getfattr,"setfattr");
|
---|
| 1058 | log_msg(1, "We will restore XATTRs");
|
---|
| 1059 | if (! find_home_of_exe("setfattr")) {
|
---|
| 1060 | log_msg(1, "Unable to restore XATTRs as no setfattr found");
|
---|
| 1061 | }
|
---|
| 1062 | }
|
---|
| 1063 |
|
---|
| 1064 | if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value)) {
|
---|
| 1065 | bkpinfo->internal_tape_block_size = atol(value);
|
---|
| 1066 | log_msg(1, "Internal tape block size has been custom-set to %ld",
|
---|
| 1067 | bkpinfo->internal_tape_block_size);
|
---|
| 1068 | } else {
|
---|
| 1069 | bkpinfo->internal_tape_block_size =
|
---|
| 1070 | DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
|
---|
| 1071 | log_msg(1, "Internal tape block size = default (%ld)",
|
---|
| 1072 | DEFAULT_INTERNAL_TAPE_BLOCK_SIZE);
|
---|
| 1073 | }
|
---|
| 1074 |
|
---|
| 1075 | read_cfg_var(cfg_file, "use-lzo", value);
|
---|
| 1076 | if (strstr(value, "yes")) {
|
---|
| 1077 | bkpinfo->use_lzo = TRUE;
|
---|
| 1078 | bkpinfo->use_gzip = FALSE;
|
---|
| 1079 | strcpy(bkpinfo->zip_exe, "lzop");
|
---|
| 1080 | strcpy(bkpinfo->zip_suffix, "lzo");
|
---|
| 1081 | } else {
|
---|
| 1082 | read_cfg_var(cfg_file, "use-gzip", value);
|
---|
| 1083 | if (strstr(value, "yes")) {
|
---|
| 1084 | bkpinfo->use_lzo = FALSE;
|
---|
| 1085 | bkpinfo->use_gzip = TRUE;
|
---|
| 1086 | strcpy(bkpinfo->zip_exe, "gzip");
|
---|
| 1087 | strcpy(bkpinfo->zip_suffix, "gz");
|
---|
| 1088 | } else {
|
---|
| 1089 | read_cfg_var(cfg_file, "use-comp", value);
|
---|
[128] | 1090 | if (strstr(value, "yes")) {
|
---|
[1242] | 1091 | bkpinfo->use_lzo = FALSE;
|
---|
[998] | 1092 | bkpinfo->use_gzip = FALSE;
|
---|
[1242] | 1093 | strcpy(bkpinfo->zip_exe, "bzip2");
|
---|
| 1094 | strcpy(bkpinfo->zip_suffix, "bz2");
|
---|
[128] | 1095 | } else {
|
---|
[1242] | 1096 | bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
|
---|
[1] | 1097 | }
|
---|
[1242] | 1098 | }
|
---|
| 1099 | }
|
---|
[1] | 1100 |
|
---|
[1242] | 1101 | value[0] = '\0';
|
---|
| 1102 | read_cfg_var(cfg_file, "differential", value);
|
---|
| 1103 | if (!strcmp(value, "yes") || !strcmp(value, "1")) {
|
---|
| 1104 | bkpinfo->differential = TRUE;
|
---|
| 1105 | }
|
---|
| 1106 | log_msg(2, "differential var = '%s'", value);
|
---|
| 1107 | if (bkpinfo->differential) {
|
---|
| 1108 | log_msg(2, "THIS IS A DIFFERENTIAL BACKUP");
|
---|
| 1109 | } else {
|
---|
| 1110 | log_msg(2, "This is a regular (full) backup");
|
---|
| 1111 | }
|
---|
| 1112 |
|
---|
| 1113 | read_cfg_var(g_mondo_cfg_file, "please-dont-eject", tmp);
|
---|
| 1114 | if (tmp[0]
|
---|
| 1115 | ||
|
---|
| 1116 | strstr(call_program_and_get_last_line_of_output
|
---|
| 1117 | ("cat /proc/cmdline"), "donteject")) {
|
---|
| 1118 | bkpinfo->please_dont_eject = TRUE;
|
---|
| 1119 | log_msg(2, "Ok, I shan't eject when restoring! Groovy.");
|
---|
| 1120 | }
|
---|
| 1121 |
|
---|
| 1122 | if (bkpinfo->backup_media_type == nfs) {
|
---|
[1736] | 1123 | if (!cfgf) {
|
---|
| 1124 | log_msg(2, "nfs_mount remains %s", bkpinfo->nfs_mount);
|
---|
| 1125 | log_msg(2, "nfs_remote_dir remains %s",
|
---|
| 1126 | bkpinfo->nfs_remote_dir);
|
---|
| 1127 | log_msg(2,
|
---|
| 1128 | "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place");
|
---|
| 1129 | } else {
|
---|
| 1130 | read_cfg_var(g_mondo_cfg_file, "nfs-server-mount",
|
---|
| 1131 | bkpinfo->nfs_mount);
|
---|
| 1132 | read_cfg_var(g_mondo_cfg_file, "nfs-server-path",
|
---|
| 1133 | bkpinfo->nfs_remote_dir);
|
---|
| 1134 | log_msg(2, "nfs_mount is %s", bkpinfo->nfs_mount);
|
---|
| 1135 | log_msg(2, "nfs_remote_dir is %s", bkpinfo->nfs_remote_dir);
|
---|
[1] | 1136 | }
|
---|
[1736] | 1137 | if (strstr(call_program_and_get_last_line_of_output
|
---|
| 1138 | ("cat /proc/cmdline"), "pxe")) {
|
---|
| 1139 | /* We need to override values in PXE mode as it's
|
---|
| 1140 | * already done in start-nfs */
|
---|
| 1141 | envtmp1 = getenv("nfsmount");
|
---|
| 1142 | if (envtmp1 == NULL) {
|
---|
| 1143 | fatal_error("no nfsmount variable in environment");
|
---|
| 1144 | }
|
---|
| 1145 | envtmp2 = getenv("dirimg");
|
---|
| 1146 | if (envtmp2 == NULL) {
|
---|
| 1147 | fatal_error("no dirimg variable in environment");
|
---|
| 1148 | }
|
---|
| 1149 | strcpy(bkpinfo->nfs_mount,envtmp1);
|
---|
| 1150 | strcpy(bkpinfo->nfs_remote_dir,envtmp2);
|
---|
[1] | 1151 | }
|
---|
[1242] | 1152 | } else if (bkpinfo->backup_media_type == iso) {
|
---|
[1736] | 1153 | /* Patch by Conor Daly 23-june-2004
|
---|
| 1154 | * to correctly mount iso-dev and set a sensible
|
---|
| 1155 | * isodir in disaster recovery mode
|
---|
| 1156 | */
|
---|
| 1157 | strcpy(old_isodir, bkpinfo->isodir);
|
---|
| 1158 | read_cfg_var(g_mondo_cfg_file, "iso-mnt", iso_mnt);
|
---|
| 1159 | read_cfg_var(g_mondo_cfg_file, "isodir", iso_path);
|
---|
| 1160 | sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
|
---|
| 1161 | if (!bkpinfo->isodir[0]) {
|
---|
[1242] | 1162 | strcpy(bkpinfo->isodir, old_isodir);
|
---|
[128] | 1163 | }
|
---|
[1736] | 1164 | if (!bkpinfo->disaster_recovery) {
|
---|
| 1165 | if (strcmp(old_isodir, bkpinfo->isodir)) {
|
---|
| 1166 | log_it
|
---|
| 1167 | ("user nominated isodir differs from archive, keeping user's choice: %s %s\n",
|
---|
| 1168 | old_isodir, bkpinfo->isodir);
|
---|
| 1169 | strcpy(bkpinfo->isodir, old_isodir);
|
---|
| 1170 | }
|
---|
| 1171 | }
|
---|
| 1172 | read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
|
---|
| 1173 | log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir,
|
---|
| 1174 | g_isodir_device);
|
---|
| 1175 | if (bkpinfo->disaster_recovery) {
|
---|
| 1176 | if (is_this_device_mounted(g_isodir_device)) {
|
---|
| 1177 | log_msg(2, "NB: isodir is already mounted");
|
---|
| 1178 | /* Find out where it's mounted */
|
---|
| 1179 | sprintf(command,
|
---|
| 1180 | "mount | grep -E '^%s' | tail -n1 | cut -d' ' -f3",
|
---|
| 1181 | g_isodir_device);
|
---|
| 1182 | log_it("command = %s", command);
|
---|
| 1183 | log_it("res of it = %s",
|
---|
| 1184 | call_program_and_get_last_line_of_output(command));
|
---|
| 1185 | sprintf(iso_mnt, "%s",
|
---|
| 1186 | call_program_and_get_last_line_of_output(command));
|
---|
| 1187 | } else {
|
---|
| 1188 | sprintf(iso_mnt, "/tmp/isodir");
|
---|
| 1189 | sprintf(tmp, "mkdir -p %s", iso_mnt);
|
---|
| 1190 | run_program_and_log_output(tmp, 5);
|
---|
| 1191 | sprintf(tmp, "mount %s %s", g_isodir_device, iso_mnt);
|
---|
| 1192 | if (run_program_and_log_output(tmp, 3)) {
|
---|
[1242] | 1193 | log_msg(1,
|
---|
[1736] | 1194 | "Unable to mount isodir. Perhaps this is really a CD backup?");
|
---|
| 1195 | bkpinfo->backup_media_type = cdr;
|
---|
| 1196 | strcpy(bkpinfo->media_device, "/dev/cdrom"); /* superfluous */
|
---|
| 1197 | bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0';
|
---|
| 1198 | if (mount_media()) {
|
---|
| 1199 | fatal_error
|
---|
| 1200 | ("Unable to mount isodir. Failed to mount CD-ROM as well.");
|
---|
| 1201 | } else {
|
---|
| 1202 | log_msg(1,
|
---|
| 1203 | "You backed up to disk, then burned some CDs.");
|
---|
| 1204 | }
|
---|
[128] | 1205 | }
|
---|
| 1206 | }
|
---|
[1736] | 1207 | /* bkpinfo->isodir should now be the true path to prefix-1.iso etc... */
|
---|
| 1208 | if (bkpinfo->backup_media_type == iso) {
|
---|
| 1209 | sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
|
---|
| 1210 | }
|
---|
[1] | 1211 | }
|
---|
[1242] | 1212 | }
|
---|
[1] | 1213 |
|
---|
[1242] | 1214 | if (media_specified_by_user != none) {
|
---|
[1736] | 1215 | if (g_restoring_live_from_cd) {
|
---|
| 1216 | if (bkpinfo->backup_media_type != media_specified_by_user) {
|
---|
| 1217 | log_msg(2,
|
---|
| 1218 | "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)");
|
---|
| 1219 | interactively_obtain_media_parameters_from_user(FALSE);
|
---|
| 1220 | media_specified_by_user = bkpinfo->backup_media_type;
|
---|
| 1221 | get_cfg_file_from_archive();
|
---|
| 1222 | /*
|
---|
| 1223 | if (media_specified_by_user != cdr && media_specified_by_user == cdrw)
|
---|
| 1224 | { g_restoring_live_from_cd = FALSE; }
|
---|
| 1225 | */
|
---|
| 1226 | }
|
---|
[128] | 1227 | }
|
---|
[1736] | 1228 | bkpinfo->backup_media_type = media_specified_by_user;
|
---|
[1242] | 1229 | }
|
---|
| 1230 | g_backup_media_type = bkpinfo->backup_media_type;
|
---|
| 1231 | paranoid_free(value);
|
---|
| 1232 | paranoid_free(tmp);
|
---|
| 1233 | paranoid_free(command);
|
---|
| 1234 | paranoid_free(iso_mnt);
|
---|
| 1235 | paranoid_free(iso_path);
|
---|
| 1236 | paranoid_free(old_isodir);
|
---|
| 1237 | return (0);
|
---|
[1] | 1238 |
|
---|
| 1239 | }
|
---|
[128] | 1240 |
|
---|
[1] | 1241 | /**************************************************************************
|
---|
[1242] | 1242 | *END_READ_CFG_FILE_INTO_BKPINFO *
|
---|
| 1243 | **************************************************************************/
|
---|
[1] | 1244 |
|
---|
| 1245 |
|
---|
| 1246 |
|
---|
[128] | 1247 |
|
---|
[1] | 1248 | /**
|
---|
[1242] | 1249 | * Allow the user to edit the filelist and biggielist.
|
---|
| 1250 | * The filelist is unlinked after it is read.
|
---|
| 1251 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 1252 | * - @c bkpinfo->backup_media_type
|
---|
| 1253 | * - @c bkpinfo->isodir
|
---|
| 1254 | * - @c bkpinfo->media_device
|
---|
| 1255 | * - @c bkpinfo->tmpdir
|
---|
| 1256 | * @return The filelist structure containing the information read from disk.
|
---|
| 1257 | */
|
---|
[1] | 1258 | struct
|
---|
[1645] | 1259 | s_node *process_filelist_and_biggielist()
|
---|
[1] | 1260 | {
|
---|
[1242] | 1261 | struct s_node *filelist;
|
---|
[1] | 1262 |
|
---|
[1242] | 1263 | /** add mallocs**/
|
---|
| 1264 | char *command;
|
---|
| 1265 | char *tmp;
|
---|
| 1266 | int res = 0;
|
---|
| 1267 | pid_t pid;
|
---|
[1] | 1268 |
|
---|
[1242] | 1269 | assert(bkpinfo != NULL);
|
---|
| 1270 | malloc_string(command);
|
---|
| 1271 | malloc_string(tmp);
|
---|
[1] | 1272 |
|
---|
[1242] | 1273 | if (does_file_exist(g_filelist_full)
|
---|
| 1274 | && does_file_exist(g_biggielist_txt)) {
|
---|
| 1275 | log_msg(1, "%s exists", g_filelist_full);
|
---|
| 1276 | log_msg(1, "%s exists", g_biggielist_txt);
|
---|
| 1277 | log_msg(2,
|
---|
| 1278 | "Filelist and biggielist already recovered from media. Yay!");
|
---|
| 1279 | } else {
|
---|
| 1280 | getcwd(tmp, MAX_STR_LEN);
|
---|
| 1281 | chdir(bkpinfo->tmpdir);
|
---|
| 1282 | log_msg(1, "chdir(%s)", bkpinfo->tmpdir);
|
---|
| 1283 | log_to_screen("Extracting filelist and biggielist from media...");
|
---|
| 1284 | unlink("/tmp/filelist.full");
|
---|
| 1285 | unlink("/" FILELIST_FULL_STUB);
|
---|
| 1286 | unlink("/tmp/i-want-my-lvm");
|
---|
| 1287 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 1288 | sprintf(command,
|
---|
| 1289 | "tar -b %ld -zxf %s %s %s %s %s %s",
|
---|
| 1290 | bkpinfo->internal_tape_block_size,
|
---|
| 1291 | bkpinfo->media_device,
|
---|
| 1292 | MOUNTLIST_FNAME_STUB,
|
---|
| 1293 | BIGGIELIST_TXT_STUB,
|
---|
| 1294 | FILELIST_FULL_STUB,
|
---|
| 1295 | "tmp/i-want-my-lvm", MONDO_CFG_FILE_STUB);
|
---|
| 1296 | log_msg(1, "tarcommand = %s", command);
|
---|
| 1297 | run_program_and_log_output(command, 1);
|
---|
| 1298 | } else {
|
---|
| 1299 | log_msg(2,
|
---|
| 1300 | "Calling insist_on_this_cd_number; bkpinfo->isodir=%s",
|
---|
| 1301 | bkpinfo->isodir);
|
---|
[1645] | 1302 | insist_on_this_cd_number(1);
|
---|
[1242] | 1303 | log_msg(2, "Back from iotcn");
|
---|
| 1304 | run_program_and_log_output("mount", 1);
|
---|
| 1305 | sprintf(command,
|
---|
| 1306 | "tar -zxf %s/images/all.tar.gz %s %s %s %s %s",
|
---|
| 1307 | MNT_CDROM,
|
---|
| 1308 | MOUNTLIST_FNAME_STUB,
|
---|
| 1309 | BIGGIELIST_TXT_STUB,
|
---|
| 1310 | FILELIST_FULL_STUB,
|
---|
| 1311 | "tmp/i-want-my-lvm", MONDO_CFG_FILE_STUB);
|
---|
[1] | 1312 |
|
---|
[1242] | 1313 | log_msg(1, "tarcommand = %s", command);
|
---|
| 1314 | run_program_and_log_output(command, 1);
|
---|
[128] | 1315 | // popup_and_OK("Press ENTER to continue");
|
---|
[1242] | 1316 | if (!does_file_exist(BIGGIELIST_TXT_STUB)) {
|
---|
| 1317 | fatal_error
|
---|
| 1318 | ("all.tar.gz did not include tmp/biggielist.txt");
|
---|
[128] | 1319 | }
|
---|
[1242] | 1320 | if (!does_file_exist(FILELIST_FULL_STUB)) {
|
---|
| 1321 | fatal_error
|
---|
| 1322 | ("all.tar.gz did not include tmp/filelist.full.gz");
|
---|
| 1323 | }
|
---|
| 1324 | }
|
---|
| 1325 | sprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB,
|
---|
| 1326 | g_mondo_cfg_file);
|
---|
| 1327 | run_program_and_log_output(command, FALSE);
|
---|
[1] | 1328 |
|
---|
[1242] | 1329 | sprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir,
|
---|
| 1330 | BIGGIELIST_TXT_STUB, g_biggielist_txt);
|
---|
| 1331 | log_msg(1, "command = %s", command);
|
---|
| 1332 | paranoid_system(command);
|
---|
| 1333 | sprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir,
|
---|
| 1334 | FILELIST_FULL_STUB, g_filelist_full);
|
---|
| 1335 | log_msg(1, "command = %s", command);
|
---|
| 1336 | paranoid_system(command);
|
---|
| 1337 | }
|
---|
| 1338 |
|
---|
| 1339 | if (am_I_in_disaster_recovery_mode()
|
---|
| 1340 | &&
|
---|
| 1341 | ask_me_yes_or_no("Do you want to retrieve the mountlist as well?"))
|
---|
| 1342 | {
|
---|
[1] | 1343 | // sprintf(command, "cp -f tmp/mountlist.txt /tmp");
|
---|
[1242] | 1344 | sprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB,
|
---|
| 1345 | bkpinfo->tmpdir);
|
---|
| 1346 | paranoid_system(command);
|
---|
| 1347 | }
|
---|
[1] | 1348 |
|
---|
[1242] | 1349 | chdir(tmp);
|
---|
[1] | 1350 |
|
---|
[1242] | 1351 | if (!does_file_exist(g_biggielist_txt)) {
|
---|
| 1352 | log_msg(1, "Warning - %s not found", g_biggielist_txt);
|
---|
| 1353 | }
|
---|
| 1354 | if (!does_file_exist(g_filelist_full)) {
|
---|
| 1355 | log_msg(1, "Warning - %s does not exist", g_filelist_full);
|
---|
| 1356 | }
|
---|
[1] | 1357 | // popup_and_OK("Wonderful.");
|
---|
| 1358 |
|
---|
[1242] | 1359 | log_msg(2, "Forking");
|
---|
| 1360 | pid = fork();
|
---|
| 1361 | switch (pid) {
|
---|
| 1362 | case -1:
|
---|
| 1363 | fatal_error("Forking error");
|
---|
| 1364 | break;
|
---|
[1] | 1365 |
|
---|
[1242] | 1366 | case 0:
|
---|
| 1367 | log_to_screen("Pre-processing filelist");
|
---|
| 1368 | if (!does_file_exist(g_biggielist_txt)) {
|
---|
| 1369 | sprintf(command, "echo -n > %s", g_biggielist_txt);
|
---|
[128] | 1370 | paranoid_system(command);
|
---|
| 1371 | }
|
---|
[910] | 1372 | sprintf(command, "grep -E '^/dev/.*' %s > %s",
|
---|
[128] | 1373 | g_biggielist_txt, g_filelist_imagedevs);
|
---|
| 1374 | paranoid_system(command);
|
---|
| 1375 | exit(0);
|
---|
| 1376 | break;
|
---|
| 1377 |
|
---|
| 1378 | default:
|
---|
[541] | 1379 | open_evalcall_form("Pre-processing filelist");
|
---|
[128] | 1380 | while (!waitpid(pid, (int *) 0, WNOHANG)) {
|
---|
| 1381 | usleep(100000);
|
---|
| 1382 | update_evalcall_form(0);
|
---|
| 1383 | }
|
---|
[1] | 1384 | }
|
---|
[128] | 1385 | close_evalcall_form();
|
---|
[1] | 1386 |
|
---|
[128] | 1387 | log_msg(3, "loading filelist");
|
---|
| 1388 | filelist = load_filelist(g_filelist_full);
|
---|
| 1389 | log_msg(3, "deleting original filelist");
|
---|
| 1390 | unlink(g_filelist_full);
|
---|
| 1391 | if (g_text_mode) {
|
---|
[541] | 1392 | printf("Restore which directory? --> ");
|
---|
[128] | 1393 | fgets(tmp, sizeof(tmp), stdin);
|
---|
| 1394 | toggle_path_selection(filelist, tmp, TRUE);
|
---|
| 1395 | if (strlen(tmp) == 0) {
|
---|
| 1396 | res = 1;
|
---|
| 1397 | } else {
|
---|
| 1398 | res = 0;
|
---|
| 1399 | }
|
---|
| 1400 | } else {
|
---|
| 1401 | res = edit_filelist(filelist);
|
---|
[1] | 1402 | }
|
---|
[128] | 1403 | if (res) {
|
---|
| 1404 | log_msg(2, "User hit 'cancel'. Freeing filelist and aborting.");
|
---|
| 1405 | free_filelist(filelist);
|
---|
| 1406 | return (NULL);
|
---|
| 1407 | }
|
---|
| 1408 | ask_about_these_imagedevs(g_filelist_imagedevs, g_imagedevs_restthese);
|
---|
| 1409 | close_evalcall_form();
|
---|
[1] | 1410 |
|
---|
[128] | 1411 | // NB: It's not necessary to add g_biggielist_txt to the filelist.full
|
---|
| 1412 | // file. The filelist.full file already contains the filename of EVERY
|
---|
| 1413 | // file backed up - regular and biggie files.
|
---|
[1] | 1414 |
|
---|
[128] | 1415 | // However, we do want to make sure the imagedevs selected by the user
|
---|
| 1416 | // are flagged for restoring.
|
---|
| 1417 | if (length_of_file(g_imagedevs_restthese) > 2) {
|
---|
| 1418 | add_list_of_files_to_filelist(filelist, g_imagedevs_restthese,
|
---|
| 1419 | TRUE);
|
---|
| 1420 | }
|
---|
[1] | 1421 |
|
---|
[128] | 1422 | paranoid_free(command);
|
---|
| 1423 | paranoid_free(tmp);
|
---|
| 1424 | return (filelist);
|
---|
| 1425 | }
|
---|
[1] | 1426 |
|
---|
| 1427 | /**************************************************************************
|
---|
| 1428 | *END_ PROCESS_FILELIST_AND_BIGGIELIST *
|
---|
| 1429 | **************************************************************************/
|
---|
| 1430 |
|
---|
| 1431 |
|
---|
| 1432 |
|
---|
| 1433 |
|
---|
| 1434 | /**
|
---|
| 1435 | * Make a backup copy of <tt>path_root</tt>/<tt>filename</tt>.
|
---|
| 1436 | * The backup filename is the filename of the original with ".pristine" added.
|
---|
| 1437 | * @param path_root The place where the filesystem is mounted (e.g. MNT_RESTORING).
|
---|
| 1438 | * @param filename The filename (absolute path) within @p path_root.
|
---|
| 1439 | * @return 0 for success, nonzero for failure.
|
---|
| 1440 | */
|
---|
[128] | 1441 | int backup_crucial_file(char *path_root, char *filename)
|
---|
[1] | 1442 | {
|
---|
[128] | 1443 | char *tmp;
|
---|
| 1444 | char *command;
|
---|
| 1445 | int res;
|
---|
[1] | 1446 |
|
---|
[128] | 1447 | malloc_string(tmp);
|
---|
| 1448 | malloc_string(command);
|
---|
| 1449 | assert(path_root != NULL);
|
---|
| 1450 | assert_string_is_neither_NULL_nor_zerolength(filename);
|
---|
| 1451 |
|
---|
| 1452 | sprintf(tmp, "%s/%s", path_root, filename);
|
---|
| 1453 | sprintf(command, "cp -f %s %s.pristine", tmp, tmp);
|
---|
| 1454 |
|
---|
| 1455 | res = run_program_and_log_output(command, 5);
|
---|
| 1456 | paranoid_free(tmp);
|
---|
| 1457 | paranoid_free(command);
|
---|
| 1458 | return (res);
|
---|
[1] | 1459 | }
|
---|
| 1460 |
|
---|
| 1461 |
|
---|
| 1462 | /**
|
---|
| 1463 | * Install the user's boot loader in the MBR.
|
---|
| 1464 | * Currently LILO, ELILO, GRUB, RAW (dd of MBR), and the FreeBSD bootloader are supported.
|
---|
| 1465 | * @param offer_to_hack_scripts If TRUE, then offer to hack the user's fstab for them.
|
---|
| 1466 | * @return 0 for success, nonzero for failure.
|
---|
| 1467 | */
|
---|
[128] | 1468 | int run_boot_loader(bool offer_to_hack_scripts)
|
---|
[1] | 1469 | {
|
---|
[128] | 1470 | int res;
|
---|
| 1471 | int retval = 0;
|
---|
[1] | 1472 |
|
---|
| 1473 | /** malloc *******/
|
---|
[128] | 1474 | char *device;
|
---|
| 1475 | char *tmp;
|
---|
| 1476 | char *name;
|
---|
[1] | 1477 |
|
---|
[128] | 1478 | malloc_string(device);
|
---|
| 1479 | malloc_string(tmp);
|
---|
| 1480 | malloc_string(name);
|
---|
| 1481 | backup_crucial_file(MNT_RESTORING, "/etc/fstab");
|
---|
| 1482 | backup_crucial_file(MNT_RESTORING, "/etc/grub.conf");
|
---|
| 1483 | backup_crucial_file(MNT_RESTORING, "/etc/lilo.conf");
|
---|
| 1484 | backup_crucial_file(MNT_RESTORING, "/etc/elilo.conf");
|
---|
| 1485 | read_cfg_var(g_mondo_cfg_file, "bootloader.device", device);
|
---|
| 1486 | read_cfg_var(g_mondo_cfg_file, "bootloader.name", name);
|
---|
| 1487 | sprintf(tmp, "run_boot_loader: device='%s', name='%s'", device, name);
|
---|
| 1488 | log_msg(2, tmp);
|
---|
| 1489 | system("sync");
|
---|
| 1490 | if (!strcmp(name, "LILO")) {
|
---|
| 1491 | res = run_lilo(offer_to_hack_scripts);
|
---|
| 1492 | } else if (!strcmp(name, "ELILO")) {
|
---|
| 1493 | res = run_elilo(offer_to_hack_scripts);
|
---|
| 1494 | } else if (!strcmp(name, "GRUB")) {
|
---|
[1] | 1495 | // if ( does_file_exist(DO_MBR_PLEASE) || (offer_to_hack_scripts && ask_me_yes_or_no("Because of bugs in GRUB, you're much better off running mondorestore --mbr after this program terminates. Are you sure you want to install GRUB right now?")))
|
---|
| 1496 | // {
|
---|
[128] | 1497 | res = run_grub(offer_to_hack_scripts, device);
|
---|
| 1498 | // unlink(DO_MBR_PLEASE);
|
---|
| 1499 | // }
|
---|
[1] | 1500 | // else
|
---|
| 1501 | // {
|
---|
[128] | 1502 | // log_msg(1, "Not running run_grub(). Was a bad idea anyway.");
|
---|
| 1503 | // res = 1;
|
---|
| 1504 | // }
|
---|
| 1505 | } else if (!strcmp(name, "RAW")) {
|
---|
| 1506 | res = run_raw_mbr(offer_to_hack_scripts, device);
|
---|
| 1507 | }
|
---|
[1] | 1508 | #ifdef __FreeBSD__
|
---|
[128] | 1509 | else if (!strcmp(name, "BOOT0")) {
|
---|
| 1510 | sprintf(tmp, "boot0cfg -B %s", device);
|
---|
| 1511 | res = run_program_and_log_output(tmp, FALSE);
|
---|
| 1512 | } else {
|
---|
[910] | 1513 | sprintf(tmp, "ls /dev | grep -Eq '^%ss[1-4].*'", device);
|
---|
[128] | 1514 | if (!system(tmp)) {
|
---|
| 1515 | sprintf(tmp, MNT_RESTORING "/sbin/fdisk -B %s", device);
|
---|
| 1516 | res = run_program_and_log_output(tmp, 3);
|
---|
| 1517 | } else {
|
---|
| 1518 | log_msg(1,
|
---|
| 1519 | "I'm not running any boot loader. You have a DD boot drive. It's already loaded up.");
|
---|
| 1520 | }
|
---|
| 1521 | }
|
---|
[1] | 1522 | #else
|
---|
[128] | 1523 | else {
|
---|
| 1524 | log_to_screen
|
---|
[541] | 1525 | ("Unable to determine type of boot loader. Defaulting to LILO.");
|
---|
[128] | 1526 | res = run_lilo(offer_to_hack_scripts);
|
---|
| 1527 | }
|
---|
[1] | 1528 | #endif
|
---|
[128] | 1529 | retval += res;
|
---|
| 1530 | if (res) {
|
---|
[541] | 1531 | log_to_screen("Your boot loader returned an error");
|
---|
[128] | 1532 | } else {
|
---|
[541] | 1533 | log_to_screen("Your boot loader ran OK");
|
---|
[128] | 1534 | }
|
---|
| 1535 | paranoid_free(device);
|
---|
| 1536 | paranoid_free(tmp);
|
---|
| 1537 | paranoid_free(name);
|
---|
| 1538 | return (retval);
|
---|
[1] | 1539 | }
|
---|
[128] | 1540 |
|
---|
[1] | 1541 | /**************************************************************************
|
---|
| 1542 | *END_ RUN_BOOT_LOADER *
|
---|
| 1543 | **************************************************************************/
|
---|
| 1544 |
|
---|
| 1545 |
|
---|
| 1546 |
|
---|
| 1547 | /**
|
---|
| 1548 | * Attempt to find the user's editor.
|
---|
| 1549 | * @return The editor found ("vi" if none could be found).
|
---|
| 1550 | * @note The returned string points to static storage that will be overwritten with each call.
|
---|
| 1551 | */
|
---|
| 1552 | char *find_my_editor(void)
|
---|
| 1553 | {
|
---|
[128] | 1554 | static char output[MAX_STR_LEN];
|
---|
| 1555 | if (find_home_of_exe("pico")) {
|
---|
| 1556 | strcpy(output, "pico");
|
---|
| 1557 | } else if (find_home_of_exe("nano")) {
|
---|
| 1558 | strcpy(output, "nano");
|
---|
| 1559 | } else if (find_home_of_exe("e3em")) {
|
---|
| 1560 | strcpy(output, "e3em");
|
---|
| 1561 | } else if (find_home_of_exe("e3vi")) {
|
---|
| 1562 | strcpy(output, "e3vi");
|
---|
| 1563 | } else {
|
---|
| 1564 | strcpy(output, "vi");
|
---|
| 1565 | }
|
---|
| 1566 | if (!find_home_of_exe(output)) {
|
---|
| 1567 | log_msg(2, " (find_my_editor) --- warning - %s not found", output);
|
---|
| 1568 | }
|
---|
| 1569 | return (output);
|
---|
[1] | 1570 | }
|
---|
| 1571 |
|
---|
| 1572 |
|
---|
| 1573 | /**
|
---|
| 1574 | * Install GRUB on @p bd.
|
---|
| 1575 | * @param offer_to_run_stabgrub If TRUE, then offer to hack the user's fstab for them.
|
---|
| 1576 | * @param bd The boot device where GRUB is installed.
|
---|
| 1577 | * @return 0 for success, nonzero for failure.
|
---|
| 1578 | */
|
---|
[128] | 1579 | int run_grub(bool offer_to_run_stabgrub, char *bd)
|
---|
[1] | 1580 | {
|
---|
| 1581 | /** malloc **/
|
---|
[128] | 1582 | char *command;
|
---|
| 1583 | char *boot_device;
|
---|
| 1584 | char *rootdev;
|
---|
| 1585 | char *rootdrive;
|
---|
| 1586 | char *conffile;
|
---|
| 1587 | char *tmp;
|
---|
| 1588 | char *editor;
|
---|
[1] | 1589 |
|
---|
[128] | 1590 | int res;
|
---|
| 1591 | int done;
|
---|
[1] | 1592 |
|
---|
[128] | 1593 | malloc_string(command);
|
---|
| 1594 | malloc_string(boot_device);
|
---|
| 1595 | malloc_string(tmp);
|
---|
| 1596 | malloc_string(editor);
|
---|
| 1597 | malloc_string(rootdev);
|
---|
| 1598 | malloc_string(rootdrive);
|
---|
| 1599 | malloc_string(conffile);
|
---|
| 1600 | assert_string_is_neither_NULL_nor_zerolength(bd);
|
---|
[1640] | 1601 | strcpy(editor, find_my_editor());
|
---|
[128] | 1602 | strcpy(boot_device, bd);
|
---|
| 1603 |
|
---|
| 1604 | if (!run_program_and_log_output("which grub-MR", FALSE)) {
|
---|
| 1605 | log_msg(1, "Yay! grub-MR found...");
|
---|
| 1606 | sprintf(command, "grub-MR %s /tmp/mountlist.txt", boot_device);
|
---|
| 1607 | log_msg(1, "command = %s", command);
|
---|
| 1608 | } else {
|
---|
| 1609 | sprintf(command, "chroot " MNT_RESTORING " grub-install %s",
|
---|
| 1610 | boot_device);
|
---|
| 1611 | log_msg(1, "WARNING - grub-MR not found; using grub-install");
|
---|
[1] | 1612 | }
|
---|
[128] | 1613 | if (offer_to_run_stabgrub
|
---|
[541] | 1614 | && ask_me_yes_or_no("Did you change the mountlist?"))
|
---|
[128] | 1615 | /* interactive mode */
|
---|
[1] | 1616 | {
|
---|
[128] | 1617 | mvaddstr_and_log_it(g_currentY,
|
---|
| 1618 | 0,
|
---|
[1547] | 1619 | "Modifying fstab, mtab, device.map and grub.conf, and running GRUB... ");
|
---|
[128] | 1620 | for (done = FALSE; !done;) {
|
---|
[541] | 1621 | popup_and_get_string("Boot device",
|
---|
| 1622 | "Please confirm/enter the boot device. If in doubt, try /dev/hda",
|
---|
[128] | 1623 | boot_device, MAX_STR_LEN / 4);
|
---|
| 1624 | sprintf(command, "stabgrub-me %s", boot_device);
|
---|
| 1625 | res = run_program_and_log_output(command, 1);
|
---|
| 1626 | if (res) {
|
---|
| 1627 | popup_and_OK
|
---|
[541] | 1628 | ("GRUB installation failed. Please install manually using 'grub-install' or similar command. You are now chroot()'ed to your restored system. Please type 'exit' when you are done.");
|
---|
[128] | 1629 | newtSuspend();
|
---|
| 1630 | system("chroot " MNT_RESTORING);
|
---|
| 1631 | newtResume();
|
---|
[541] | 1632 | popup_and_OK("Thank you.");
|
---|
[128] | 1633 | } else {
|
---|
| 1634 | done = TRUE;
|
---|
| 1635 | }
|
---|
[1547] | 1636 | popup_and_OK("You will now edit fstab, mtab, device.map and grub.conf");
|
---|
[128] | 1637 | if (!g_text_mode) {
|
---|
| 1638 | newtSuspend();
|
---|
| 1639 | }
|
---|
[1498] | 1640 | sprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
|
---|
[128] | 1641 | paranoid_system(tmp);
|
---|
[1547] | 1642 | sprintf(tmp, "chroot %s %s /etc/mtab", MNT_RESTORING, editor);
|
---|
| 1643 | paranoid_system(tmp);
|
---|
[1498] | 1644 | sprintf(tmp, "chroot %s %s /etc/grub.conf", MNT_RESTORING, editor);
|
---|
[128] | 1645 | paranoid_system(tmp);
|
---|
[1547] | 1646 | sprintf(tmp, "chroot %s %s /boot/grub/device.map", MNT_RESTORING, editor);
|
---|
| 1647 | paranoid_system(tmp);
|
---|
[128] | 1648 | if (!g_text_mode) {
|
---|
| 1649 | newtResume();
|
---|
| 1650 | }
|
---|
| 1651 | }
|
---|
| 1652 | } else
|
---|
| 1653 | /* nuke mode */
|
---|
| 1654 | {
|
---|
| 1655 | mvaddstr_and_log_it(g_currentY,
|
---|
| 1656 | 0,
|
---|
[541] | 1657 | "Running GRUB... ");
|
---|
[128] | 1658 | iamhere(command);
|
---|
| 1659 | res = run_program_and_log_output(command, 1);
|
---|
| 1660 | if (res) {
|
---|
| 1661 | popup_and_OK
|
---|
[541] | 1662 | ("Because of bugs in GRUB's own installer, GRUB was not installed properly. Please install the boot loader manually now, using this chroot()'ed shell prompt. Type 'exit' when you have finished.");
|
---|
[128] | 1663 | newtSuspend();
|
---|
| 1664 | system("chroot " MNT_RESTORING);
|
---|
| 1665 | newtResume();
|
---|
[541] | 1666 | popup_and_OK("Thank you.");
|
---|
[128] | 1667 | }
|
---|
[1] | 1668 | }
|
---|
[128] | 1669 | if (res) {
|
---|
[541] | 1670 | mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
|
---|
[128] | 1671 | log_to_screen
|
---|
[1315] | 1672 | ("GRUB ran w/error(s). See %s for more info.", MONDO_LOGFILE);
|
---|
[128] | 1673 | log_msg(1, "Type:-");
|
---|
| 1674 | log_msg(1, " mount-me");
|
---|
| 1675 | log_msg(1, " chroot " MNT_RESTORING);
|
---|
| 1676 | log_msg(1, " mount /boot");
|
---|
| 1677 | log_msg(1, " grub-install '(hd0)'");
|
---|
| 1678 | log_msg(1, " exit");
|
---|
| 1679 | log_msg(1, " unmount-me");
|
---|
| 1680 | log_msg(1,
|
---|
| 1681 | "If you're really stuck, please e-mail the mailing list.");
|
---|
| 1682 | } else {
|
---|
[541] | 1683 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
[128] | 1684 | }
|
---|
| 1685 | paranoid_free(rootdev);
|
---|
| 1686 | paranoid_free(rootdrive);
|
---|
| 1687 | paranoid_free(conffile);
|
---|
| 1688 | paranoid_free(command);
|
---|
| 1689 | paranoid_free(boot_device);
|
---|
| 1690 | paranoid_free(tmp);
|
---|
| 1691 | paranoid_free(editor);
|
---|
[1] | 1692 |
|
---|
[128] | 1693 | return (res);
|
---|
[1] | 1694 | }
|
---|
[128] | 1695 |
|
---|
[1] | 1696 | /**************************************************************************
|
---|
| 1697 | *END_RUN_GRUB *
|
---|
| 1698 | **************************************************************************/
|
---|
| 1699 |
|
---|
| 1700 |
|
---|
| 1701 | /**
|
---|
| 1702 | * Install ELILO on the user's boot drive (determined by elilo.conf).
|
---|
| 1703 | * @param offer_to_run_stabelilo If TRUE, then offer to hack the user's fstab for them.
|
---|
| 1704 | * @return 0 for success, nonzero for failure.
|
---|
| 1705 | */
|
---|
[128] | 1706 | int run_elilo(bool offer_to_run_stabelilo)
|
---|
[1] | 1707 | {
|
---|
| 1708 | /** malloc **/
|
---|
[128] | 1709 | char *command;
|
---|
| 1710 | char *tmp;
|
---|
| 1711 | char *editor;
|
---|
[1] | 1712 |
|
---|
[128] | 1713 | int res;
|
---|
| 1714 | int done;
|
---|
[1] | 1715 |
|
---|
[128] | 1716 | malloc_string(command);
|
---|
| 1717 | malloc_string(tmp);
|
---|
| 1718 | malloc_string(editor);
|
---|
| 1719 | strcpy(editor, find_my_editor());
|
---|
| 1720 | if (offer_to_run_stabelilo
|
---|
[541] | 1721 | && ask_me_yes_or_no("Did you change the mountlist?"))
|
---|
[1] | 1722 |
|
---|
[128] | 1723 | /* interactive mode */
|
---|
| 1724 | {
|
---|
| 1725 | mvaddstr_and_log_it(g_currentY,
|
---|
| 1726 | 0,
|
---|
[541] | 1727 | "Modifying fstab and elilo.conf... ");
|
---|
[128] | 1728 | sprintf(command, "stabelilo-me");
|
---|
| 1729 | res = run_program_and_log_output(command, 3);
|
---|
| 1730 | if (res) {
|
---|
| 1731 | popup_and_OK
|
---|
[541] | 1732 | ("You will now edit fstab and elilo.conf, to make sure they match your new mountlist.");
|
---|
[128] | 1733 | for (done = FALSE; !done;) {
|
---|
| 1734 | if (!g_text_mode) {
|
---|
| 1735 | newtSuspend();
|
---|
| 1736 | }
|
---|
| 1737 | sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
|
---|
| 1738 | paranoid_system(tmp);
|
---|
| 1739 | sprintf(tmp, "%s " MNT_RESTORING "/etc/elilo.conf",
|
---|
| 1740 | editor);
|
---|
| 1741 | paranoid_system(tmp);
|
---|
| 1742 | if (!g_text_mode) {
|
---|
| 1743 | newtResume();
|
---|
| 1744 | }
|
---|
[1] | 1745 | // newtCls();
|
---|
[541] | 1746 | if (ask_me_yes_or_no("Edit them again?")) {
|
---|
[128] | 1747 | continue;
|
---|
| 1748 | }
|
---|
| 1749 | done = TRUE;
|
---|
| 1750 | }
|
---|
| 1751 | } else {
|
---|
[541] | 1752 | log_to_screen("elilo.conf and fstab were modified OK");
|
---|
[1] | 1753 | }
|
---|
[128] | 1754 | } else
|
---|
| 1755 | /* nuke mode */
|
---|
[1] | 1756 | {
|
---|
[128] | 1757 | res = TRUE;
|
---|
[1] | 1758 | }
|
---|
[128] | 1759 | paranoid_free(command);
|
---|
| 1760 | paranoid_free(tmp);
|
---|
| 1761 | paranoid_free(editor);
|
---|
| 1762 | return (res);
|
---|
| 1763 | }
|
---|
[1] | 1764 |
|
---|
| 1765 | /**************************************************************************
|
---|
| 1766 | *END_RUN_ELILO *
|
---|
| 1767 | **************************************************************************/
|
---|
| 1768 |
|
---|
| 1769 |
|
---|
| 1770 | /**
|
---|
| 1771 | * Install LILO on the user's boot drive (determined by /etc/lilo.conf).
|
---|
| 1772 | * @param offer_to_run_stablilo If TRUE, then offer to hack the user's fstab for them.
|
---|
| 1773 | * @return 0 for success, nonzero for failure.
|
---|
| 1774 | */
|
---|
[128] | 1775 | int run_lilo(bool offer_to_run_stablilo)
|
---|
[1] | 1776 | {
|
---|
| 1777 | /** malloc **/
|
---|
[128] | 1778 | char *command;
|
---|
| 1779 | char *tmp;
|
---|
| 1780 | char *editor;
|
---|
[1] | 1781 |
|
---|
[128] | 1782 | int res;
|
---|
| 1783 | int done;
|
---|
| 1784 | bool run_lilo_M = FALSE;
|
---|
| 1785 | malloc_string(command);
|
---|
| 1786 | malloc_string(tmp);
|
---|
| 1787 | malloc_string(editor);
|
---|
[1] | 1788 |
|
---|
[128] | 1789 | if (!run_program_and_log_output
|
---|
| 1790 | ("grep \"boot.*=.*/dev/md\" " MNT_RESTORING "/etc/lilo.conf", 1)) {
|
---|
| 1791 | run_lilo_M = TRUE;
|
---|
| 1792 | }
|
---|
[1] | 1793 |
|
---|
[128] | 1794 | strcpy(editor, find_my_editor());
|
---|
| 1795 | if (offer_to_run_stablilo
|
---|
[541] | 1796 | && ask_me_yes_or_no("Did you change the mountlist?"))
|
---|
[1] | 1797 |
|
---|
[128] | 1798 | /* interactive mode */
|
---|
| 1799 | {
|
---|
| 1800 | mvaddstr_and_log_it(g_currentY,
|
---|
| 1801 | 0,
|
---|
[541] | 1802 | "Modifying fstab and lilo.conf, and running LILO... ");
|
---|
[128] | 1803 | sprintf(command, "stablilo-me");
|
---|
| 1804 | res = run_program_and_log_output(command, 3);
|
---|
| 1805 | if (res) {
|
---|
| 1806 | popup_and_OK
|
---|
[541] | 1807 | ("You will now edit fstab and lilo.conf, to make sure they match your new mountlist.");
|
---|
[128] | 1808 | for (done = FALSE; !done;) {
|
---|
| 1809 | if (!g_text_mode) {
|
---|
| 1810 | newtSuspend();
|
---|
| 1811 | }
|
---|
| 1812 | sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
|
---|
| 1813 | paranoid_system(tmp);
|
---|
| 1814 | sprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor);
|
---|
| 1815 | paranoid_system(tmp);
|
---|
| 1816 | if (!g_text_mode) {
|
---|
| 1817 | newtResume();
|
---|
| 1818 | }
|
---|
[1] | 1819 | // newtCls();
|
---|
[541] | 1820 | if (ask_me_yes_or_no("Edit them again?")) {
|
---|
[128] | 1821 | continue;
|
---|
| 1822 | }
|
---|
| 1823 | res =
|
---|
| 1824 | run_program_and_log_output("chroot " MNT_RESTORING
|
---|
| 1825 | " lilo -L", 3);
|
---|
| 1826 | if (res) {
|
---|
| 1827 | res =
|
---|
| 1828 | run_program_and_log_output("chroot " MNT_RESTORING
|
---|
| 1829 | " lilo", 3);
|
---|
| 1830 | }
|
---|
| 1831 | if (res) {
|
---|
| 1832 | done =
|
---|
| 1833 | ask_me_yes_or_no
|
---|
[541] | 1834 | ("LILO failed. Re-edit system files?");
|
---|
[128] | 1835 | } else {
|
---|
| 1836 | done = TRUE;
|
---|
| 1837 | }
|
---|
| 1838 | }
|
---|
| 1839 | } else {
|
---|
[541] | 1840 | log_to_screen("lilo.conf and fstab were modified OK");
|
---|
[1] | 1841 | }
|
---|
[128] | 1842 | } else
|
---|
| 1843 | /* nuke mode */
|
---|
| 1844 | {
|
---|
| 1845 | mvaddstr_and_log_it(g_currentY,
|
---|
| 1846 | 0,
|
---|
[541] | 1847 | "Running LILO... ");
|
---|
[128] | 1848 | res =
|
---|
| 1849 | run_program_and_log_output("chroot " MNT_RESTORING " lilo -L",
|
---|
| 1850 | 3);
|
---|
| 1851 | if (res) {
|
---|
| 1852 | res =
|
---|
| 1853 | run_program_and_log_output("chroot " MNT_RESTORING " lilo",
|
---|
| 1854 | 3);
|
---|
[1] | 1855 | }
|
---|
[128] | 1856 | if (res) {
|
---|
[541] | 1857 | mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
|
---|
[128] | 1858 | log_to_screen
|
---|
[541] | 1859 | ("Failed to re-jig fstab and/or lilo. Edit/run manually, please.");
|
---|
[128] | 1860 | } else {
|
---|
[541] | 1861 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
[128] | 1862 | }
|
---|
[1] | 1863 | }
|
---|
[128] | 1864 | if (run_lilo_M) {
|
---|
| 1865 | run_program_and_log_output("chroot " MNT_RESTORING
|
---|
| 1866 | " lilo -M /dev/hda", 3);
|
---|
| 1867 | run_program_and_log_output("chroot " MNT_RESTORING
|
---|
| 1868 | " lilo -M /dev/sda", 3);
|
---|
[1] | 1869 | }
|
---|
[128] | 1870 | paranoid_free(command);
|
---|
| 1871 | paranoid_free(tmp);
|
---|
| 1872 | paranoid_free(editor);
|
---|
| 1873 | return (res);
|
---|
| 1874 | }
|
---|
[1] | 1875 |
|
---|
| 1876 | /**************************************************************************
|
---|
| 1877 | *END_RUN_LILO *
|
---|
| 1878 | **************************************************************************/
|
---|
| 1879 |
|
---|
| 1880 |
|
---|
| 1881 | /**
|
---|
| 1882 | * Install a raw MBR onto @p bd.
|
---|
| 1883 | * @param offer_to_hack_scripts If TRUE, then offer to hack the user's fstab for them.
|
---|
| 1884 | * @param bd The device to copy the stored MBR to.
|
---|
| 1885 | * @return 0 for success, nonzero for failure.
|
---|
| 1886 | */
|
---|
[128] | 1887 | int run_raw_mbr(bool offer_to_hack_scripts, char *bd)
|
---|
[1] | 1888 | {
|
---|
| 1889 | /** malloc **/
|
---|
[128] | 1890 | char *command;
|
---|
| 1891 | char *boot_device;
|
---|
| 1892 | char *tmp;
|
---|
| 1893 | char *editor;
|
---|
| 1894 | int res;
|
---|
| 1895 | int done;
|
---|
[1] | 1896 |
|
---|
[128] | 1897 | malloc_string(command);
|
---|
| 1898 | malloc_string(boot_device);
|
---|
| 1899 | malloc_string(tmp);
|
---|
| 1900 | malloc_string(editor);
|
---|
| 1901 | assert_string_is_neither_NULL_nor_zerolength(bd);
|
---|
[1] | 1902 |
|
---|
[128] | 1903 | strcpy(editor, find_my_editor());
|
---|
| 1904 | strcpy(boot_device, bd);
|
---|
| 1905 | sprintf(command, "raw-MR %s /tmp/mountlist.txt", boot_device);
|
---|
| 1906 | log_msg(2, "run_raw_mbr() --- command='%s'", command);
|
---|
[1] | 1907 |
|
---|
[128] | 1908 | if (offer_to_hack_scripts
|
---|
[541] | 1909 | && ask_me_yes_or_no("Did you change the mountlist?"))
|
---|
[128] | 1910 | /* interactive mode */
|
---|
[1] | 1911 | {
|
---|
[128] | 1912 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
[541] | 1913 | "Modifying fstab and restoring MBR... ");
|
---|
[128] | 1914 | for (done = FALSE; !done;) {
|
---|
| 1915 | if (!run_program_and_log_output("which vi", FALSE)) {
|
---|
[541] | 1916 | popup_and_OK("You will now edit fstab");
|
---|
[128] | 1917 | if (!g_text_mode) {
|
---|
| 1918 | newtSuspend();
|
---|
| 1919 | }
|
---|
| 1920 | sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
|
---|
| 1921 | paranoid_system(tmp);
|
---|
| 1922 | if (!g_text_mode) {
|
---|
| 1923 | newtResume();
|
---|
| 1924 | }
|
---|
[1] | 1925 | // newtCls();
|
---|
[128] | 1926 | }
|
---|
[541] | 1927 | popup_and_get_string("Boot device",
|
---|
| 1928 | "Please confirm/enter the boot device. If in doubt, try /dev/hda",
|
---|
[128] | 1929 | boot_device, MAX_STR_LEN / 4);
|
---|
| 1930 | sprintf(command, "stabraw-me %s", boot_device);
|
---|
| 1931 | res = run_program_and_log_output(command, 3);
|
---|
| 1932 | if (res) {
|
---|
[541] | 1933 | done = ask_me_yes_or_no("Modifications failed. Re-try?");
|
---|
[128] | 1934 | } else {
|
---|
| 1935 | done = TRUE;
|
---|
| 1936 | }
|
---|
| 1937 | }
|
---|
| 1938 | } else
|
---|
| 1939 | /* nuke mode */
|
---|
| 1940 | {
|
---|
| 1941 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
[541] | 1942 | "Restoring MBR... ");
|
---|
[128] | 1943 | res = run_program_and_log_output(command, 3);
|
---|
[1] | 1944 | }
|
---|
[128] | 1945 | if (res) {
|
---|
[541] | 1946 | mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
|
---|
[128] | 1947 | log_to_screen
|
---|
[1315] | 1948 | ("MBR+fstab processed w/error(s). See %s for more info.", MONDO_LOGFILE);
|
---|
[128] | 1949 | } else {
|
---|
[541] | 1950 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
[128] | 1951 | }
|
---|
| 1952 | paranoid_free(command);
|
---|
| 1953 | paranoid_free(boot_device);
|
---|
| 1954 | paranoid_free(tmp);
|
---|
| 1955 | paranoid_free(editor);
|
---|
| 1956 | return (res);
|
---|
[1] | 1957 | }
|
---|
[128] | 1958 |
|
---|
[1] | 1959 | /**************************************************************************
|
---|
| 1960 | *END_RUN_RAW_MBR *
|
---|
| 1961 | **************************************************************************/
|
---|
| 1962 |
|
---|
| 1963 |
|
---|
| 1964 |
|
---|
[128] | 1965 |
|
---|
| 1966 |
|
---|
[1] | 1967 | /**
|
---|
| 1968 | * Turn signal trapping on or off.
|
---|
| 1969 | * @param on If TRUE, then do full cleanup when we receive a signal; if FALSE, then
|
---|
| 1970 | * print a message and exit immediately.
|
---|
| 1971 | */
|
---|
[128] | 1972 | void set_signals(int on)
|
---|
[1] | 1973 | {
|
---|
[128] | 1974 | int signals[] =
|
---|
| 1975 | { SIGKILL, SIGPIPE, SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT,
|
---|
| 1976 | SIGSTOP, 0 };
|
---|
| 1977 | int i;
|
---|
| 1978 | for (i = 0; signals[i]; i++) {
|
---|
| 1979 | if (on) {
|
---|
| 1980 | signal(signals[i], terminate_daemon);
|
---|
| 1981 | } else {
|
---|
| 1982 | signal(signals[i], termination_in_progress);
|
---|
| 1983 | }
|
---|
[1] | 1984 | }
|
---|
| 1985 | }
|
---|
| 1986 |
|
---|
| 1987 | /**************************************************************************
|
---|
| 1988 | *END_SET_SIGNALS *
|
---|
| 1989 | **************************************************************************/
|
---|
| 1990 |
|
---|
| 1991 |
|
---|
| 1992 | /**
|
---|
| 1993 | * malloc() and set sensible defaults for the mondorestore filename variables.
|
---|
| 1994 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 1995 | * - @c bkpinfo->tmpdir
|
---|
| 1996 | * - @c bkpinfo->disaster_recovery
|
---|
| 1997 | */
|
---|
[1645] | 1998 | void setup_MR_global_filenames()
|
---|
[1] | 1999 | {
|
---|
[128] | 2000 | char *temppath;
|
---|
[1] | 2001 |
|
---|
[128] | 2002 | assert(bkpinfo != NULL);
|
---|
[1] | 2003 |
|
---|
[128] | 2004 | malloc_string(g_biggielist_txt);
|
---|
| 2005 | malloc_string(g_filelist_full);
|
---|
| 2006 | malloc_string(g_filelist_imagedevs);
|
---|
| 2007 | malloc_string(g_imagedevs_restthese);
|
---|
| 2008 | malloc_string(g_mondo_cfg_file);
|
---|
| 2009 | malloc_string(g_mountlist_fname);
|
---|
| 2010 | malloc_string(g_mondo_home);
|
---|
| 2011 | malloc_string(g_tmpfs_mountpt);
|
---|
| 2012 | malloc_string(g_isodir_device);
|
---|
| 2013 | malloc_string(g_isodir_format);
|
---|
[1] | 2014 |
|
---|
[128] | 2015 | temppath = bkpinfo->tmpdir;
|
---|
[1] | 2016 |
|
---|
[128] | 2017 | sprintf(g_biggielist_txt, "%s/%s", temppath, BIGGIELIST_TXT_STUB);
|
---|
| 2018 | sprintf(g_filelist_full, "%s/%s", temppath, FILELIST_FULL_STUB);
|
---|
| 2019 | sprintf(g_filelist_imagedevs, "%s/tmp/filelist.imagedevs", temppath);
|
---|
[1] | 2020 | // sprintf(g_imagedevs_pot, "%s/tmp/imagedevs.pot", temppath);
|
---|
[128] | 2021 | sprintf(g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these",
|
---|
| 2022 | temppath);
|
---|
| 2023 | if (bkpinfo->disaster_recovery) {
|
---|
| 2024 | sprintf(g_mondo_cfg_file, "/%s", MONDO_CFG_FILE_STUB);
|
---|
| 2025 | sprintf(g_mountlist_fname, "/%s", MOUNTLIST_FNAME_STUB);
|
---|
| 2026 | } else {
|
---|
| 2027 | sprintf(g_mondo_cfg_file, "%s/%s", temppath, MONDO_CFG_FILE_STUB);
|
---|
| 2028 | sprintf(g_mountlist_fname, "%s/%s", temppath,
|
---|
| 2029 | MOUNTLIST_FNAME_STUB);
|
---|
| 2030 | }
|
---|
[1] | 2031 | }
|
---|
[128] | 2032 |
|
---|
[1] | 2033 | /**************************************************************************
|
---|
| 2034 | *END_SET_GLOBAL_FILENAME *
|
---|
| 2035 | **************************************************************************/
|
---|
| 2036 |
|
---|
| 2037 |
|
---|
| 2038 | /**
|
---|
| 2039 | * Copy @p input_file (containing the result of a compare) to @p output_file,
|
---|
| 2040 | * deleting spurious "changes" along the way.
|
---|
| 2041 | * @param output_file The output file to write with spurious changes removed.
|
---|
| 2042 | * @param input_file The input file, a list of changed files created by a compare.
|
---|
| 2043 | */
|
---|
[128] | 2044 | void streamline_changes_file(char *output_file, char *input_file)
|
---|
[1] | 2045 | {
|
---|
[128] | 2046 | FILE *fin;
|
---|
| 2047 | FILE *fout;
|
---|
[1] | 2048 | /** malloc **/
|
---|
[128] | 2049 | char *incoming;
|
---|
[1] | 2050 |
|
---|
[128] | 2051 | assert_string_is_neither_NULL_nor_zerolength(output_file);
|
---|
| 2052 | assert_string_is_neither_NULL_nor_zerolength(input_file);
|
---|
| 2053 | malloc_string(incoming);
|
---|
| 2054 |
|
---|
| 2055 | if (!(fin = fopen(input_file, "r"))) {
|
---|
| 2056 | log_OS_error(input_file);
|
---|
| 2057 | return;
|
---|
| 2058 | }
|
---|
| 2059 | if (!(fout = fopen(output_file, "w"))) {
|
---|
| 2060 | fatal_error("cannot open output_file");
|
---|
| 2061 | }
|
---|
| 2062 | for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
|
---|
| 2063 | fgets(incoming, MAX_STR_LEN - 1, fin)) {
|
---|
| 2064 | if (strncmp(incoming, "etc/adjtime", 11)
|
---|
| 2065 | && strncmp(incoming, "etc/mtab", 8)
|
---|
| 2066 | && strncmp(incoming, "tmp/", 4)
|
---|
| 2067 | && strncmp(incoming, "boot/map", 8)
|
---|
| 2068 | && !strstr(incoming, "incheckentry")
|
---|
| 2069 | && strncmp(incoming, "etc/mail/statistics", 19)
|
---|
| 2070 | && strncmp(incoming, "var/", 4))
|
---|
| 2071 | fprintf(fout, "%s", incoming); /* don't need \n here, for some reason.. */
|
---|
| 2072 | }
|
---|
| 2073 | paranoid_fclose(fout);
|
---|
| 2074 | paranoid_fclose(fin);
|
---|
| 2075 | paranoid_free(incoming);
|
---|
[1] | 2076 | }
|
---|
[128] | 2077 |
|
---|
[1] | 2078 | /**************************************************************************
|
---|
| 2079 | *END_STREAMLINE_CHANGES_FILE *
|
---|
| 2080 | **************************************************************************/
|
---|
| 2081 |
|
---|
| 2082 |
|
---|
| 2083 | /**
|
---|
| 2084 | * Exit due to a signal (normal cleanup).
|
---|
| 2085 | * @param sig The signal we're exiting due to.
|
---|
| 2086 | */
|
---|
[128] | 2087 | void terminate_daemon(int sig)
|
---|
[1] | 2088 | {
|
---|
[128] | 2089 | log_to_screen
|
---|
[541] | 2090 | ("Mondorestore is terminating in response to a signal from the OS");
|
---|
[128] | 2091 | paranoid_MR_finish(254);
|
---|
[1] | 2092 | }
|
---|
[128] | 2093 |
|
---|
[1] | 2094 | /**************************************************************************
|
---|
| 2095 | *END_TERMINATE_DAEMON *
|
---|
| 2096 | **************************************************************************/
|
---|
| 2097 |
|
---|
| 2098 |
|
---|
| 2099 | /**
|
---|
| 2100 | * Give the user twenty seconds to press Ctrl-Alt-Del before we nuke their drives.
|
---|
| 2101 | */
|
---|
[128] | 2102 | void twenty_seconds_til_yikes()
|
---|
[1] | 2103 | {
|
---|
[128] | 2104 | int i;
|
---|
| 2105 | /* MALLOC * */
|
---|
| 2106 | char *tmp;
|
---|
[1] | 2107 |
|
---|
[128] | 2108 | malloc_string(tmp);
|
---|
| 2109 | if (does_file_exist("/tmp/NOPAUSE")) {
|
---|
| 2110 | return;
|
---|
| 2111 | }
|
---|
[541] | 2112 | open_progress_form("CAUTION",
|
---|
| 2113 | "Be advised: I am about to ERASE your hard disk(s)!",
|
---|
| 2114 | "You may press Ctrl+Alt+Del to abort safely.",
|
---|
[128] | 2115 | "", 20);
|
---|
| 2116 | for (i = 0; i < 20; i++) {
|
---|
| 2117 | g_current_progress = i;
|
---|
[541] | 2118 | sprintf(tmp, "You have %d seconds left to abort.", 20 - i);
|
---|
[128] | 2119 | update_progress_form(tmp);
|
---|
| 2120 | sleep(1);
|
---|
| 2121 | }
|
---|
| 2122 | close_progress_form();
|
---|
| 2123 | paranoid_free(tmp);
|
---|
[1] | 2124 | }
|
---|
[128] | 2125 |
|
---|
[1] | 2126 | /**************************************************************************
|
---|
| 2127 | *END_TWENTY_SECONDS_TIL_YIKES *
|
---|
| 2128 | **************************************************************************/
|
---|
| 2129 |
|
---|
| 2130 |
|
---|
| 2131 |
|
---|
| 2132 |
|
---|
| 2133 |
|
---|
| 2134 | /**
|
---|
| 2135 | * Exit due to a signal (no cleanup).
|
---|
| 2136 | * @param sig The signal we're exiting due to.
|
---|
| 2137 | */
|
---|
[128] | 2138 | void termination_in_progress(int sig)
|
---|
[1] | 2139 | {
|
---|
[128] | 2140 | log_msg(1, "Termination in progress");
|
---|
| 2141 | usleep(1000);
|
---|
| 2142 | pthread_exit(0);
|
---|
[1] | 2143 | }
|
---|
[128] | 2144 |
|
---|
[1] | 2145 | /**************************************************************************
|
---|
| 2146 | *END_TERMINATION_IN_PROGRESS *
|
---|
| 2147 | **************************************************************************/
|
---|
| 2148 |
|
---|
| 2149 |
|
---|
| 2150 |
|
---|
| 2151 | /**
|
---|
| 2152 | * Unmount all devices in @p p_external_copy_of_mountlist.
|
---|
| 2153 | * @param p_external_copy_of_mountlist The mountlist to guide the devices to unmount.
|
---|
| 2154 | * @return 0 for success, nonzero for failure.
|
---|
| 2155 | */
|
---|
[128] | 2156 | int unmount_all_devices(struct mountlist_itself
|
---|
| 2157 | *p_external_copy_of_mountlist)
|
---|
[1] | 2158 | {
|
---|
[128] | 2159 | struct mountlist_itself *mountlist;
|
---|
| 2160 | int retval = 0, lino, res = 0, i;
|
---|
| 2161 | char *command;
|
---|
| 2162 | char *tmp;
|
---|
[1] | 2163 |
|
---|
[128] | 2164 | malloc_string(command);
|
---|
| 2165 | malloc_string(tmp);
|
---|
| 2166 | assert(p_external_copy_of_mountlist != NULL);
|
---|
[1] | 2167 |
|
---|
[128] | 2168 | mountlist = malloc(sizeof(struct mountlist_itself));
|
---|
| 2169 | memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist,
|
---|
| 2170 | sizeof(struct mountlist_itself));
|
---|
| 2171 | sort_mountlist_by_mountpoint(mountlist, 0);
|
---|
[1] | 2172 |
|
---|
[691] | 2173 | run_program_and_log_output("df -m", 3);
|
---|
[541] | 2174 | mvaddstr_and_log_it(g_currentY, 0, "Unmounting devices ");
|
---|
| 2175 | open_progress_form("Unmounting devices",
|
---|
| 2176 | "Unmounting all devices that were mounted,",
|
---|
| 2177 | "in preparation for the post-restoration reboot.",
|
---|
[128] | 2178 | "", mountlist->entries);
|
---|
| 2179 | chdir("/");
|
---|
| 2180 | for (i = 0;
|
---|
| 2181 | i < 10
|
---|
| 2182 | &&
|
---|
| 2183 | run_program_and_log_output
|
---|
[792] | 2184 | ("ps | grep buffer | grep -v \"grep buffer\"", TRUE) == 0;
|
---|
[128] | 2185 | i++) {
|
---|
| 2186 | sleep(1);
|
---|
| 2187 | log_msg(2, "Waiting for buffer() to finish");
|
---|
| 2188 | }
|
---|
[1] | 2189 |
|
---|
[128] | 2190 | paranoid_system("sync");
|
---|
[1] | 2191 |
|
---|
[1322] | 2192 | sprintf(tmp, "cp -f %s " MNT_RESTORING "/var/log", MONDO_LOGFILE);
|
---|
| 2193 | if (run_program_and_log_output(tmp, FALSE)) {
|
---|
[128] | 2194 | log_msg(1,
|
---|
[1315] | 2195 | "Error. Failed to copy log to PC's /var/log dir. (Mounted read-only?)");
|
---|
[1] | 2196 | }
|
---|
[128] | 2197 | if (does_file_exist("/tmp/DUMBASS-GENTOO")) {
|
---|
| 2198 | run_program_and_log_output("mkdir -p " MNT_RESTORING
|
---|
| 2199 | "/mnt/.boot.d", 5);
|
---|
[1] | 2200 | }
|
---|
[128] | 2201 | for (lino = mountlist->entries - 1; lino >= 0; lino--) {
|
---|
| 2202 | if (!strcmp(mountlist->el[lino].mountpoint, "lvm")) {
|
---|
| 2203 | continue;
|
---|
| 2204 | }
|
---|
[541] | 2205 | sprintf(tmp, "Unmounting device %s ", mountlist->el[lino].device);
|
---|
[128] | 2206 |
|
---|
| 2207 | update_progress_form(tmp);
|
---|
| 2208 | if (is_this_device_mounted(mountlist->el[lino].device)) {
|
---|
| 2209 | if (!strcmp(mountlist->el[lino].mountpoint, "swap")) {
|
---|
| 2210 | sprintf(command, "swapoff %s", mountlist->el[lino].device);
|
---|
| 2211 | } else {
|
---|
| 2212 | if (!strcmp(mountlist->el[lino].mountpoint, "/1")) {
|
---|
| 2213 | sprintf(command, "umount %s/", MNT_RESTORING);
|
---|
| 2214 | log_msg(3,
|
---|
| 2215 | "Well, I know a certain kitty-kitty who'll be sleeping with Mommy tonight...");
|
---|
| 2216 | } else {
|
---|
| 2217 | sprintf(command, "umount " MNT_RESTORING "%s",
|
---|
| 2218 | mountlist->el[lino].mountpoint);
|
---|
| 2219 | }
|
---|
| 2220 | }
|
---|
| 2221 | log_msg(10, "The 'umount' command is '%s'", command);
|
---|
| 2222 | res = run_program_and_log_output(command, 3);
|
---|
| 2223 | } else {
|
---|
[541] | 2224 | strcat(tmp, "...not mounted anyway :-) OK");
|
---|
[128] | 2225 | res = 0;
|
---|
| 2226 | }
|
---|
| 2227 | g_current_progress++;
|
---|
| 2228 | if (res) {
|
---|
[541] | 2229 | strcat(tmp, "...Failed");
|
---|
[128] | 2230 | retval++;
|
---|
| 2231 | log_to_screen(tmp);
|
---|
| 2232 | } else {
|
---|
| 2233 | log_msg(2, tmp);
|
---|
| 2234 | }
|
---|
| 2235 | }
|
---|
| 2236 | close_progress_form();
|
---|
| 2237 | if (retval) {
|
---|
[541] | 2238 | mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
|
---|
[128] | 2239 | } else {
|
---|
[541] | 2240 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
[128] | 2241 | }
|
---|
| 2242 | if (retval) {
|
---|
[541] | 2243 | log_to_screen("Unable to unmount some of your partitions.");
|
---|
[128] | 2244 | } else {
|
---|
[541] | 2245 | log_to_screen("All partitions were unmounted OK.");
|
---|
[128] | 2246 | }
|
---|
| 2247 | free(mountlist);
|
---|
| 2248 | paranoid_free(command);
|
---|
| 2249 | paranoid_free(tmp);
|
---|
| 2250 | return (retval);
|
---|
[1] | 2251 | }
|
---|
[128] | 2252 |
|
---|
[1] | 2253 | /**************************************************************************
|
---|
| 2254 | *END_UNMOUNT_ALL_DEVICES *
|
---|
| 2255 | **************************************************************************/
|
---|
| 2256 |
|
---|
| 2257 |
|
---|
| 2258 |
|
---|
| 2259 | /**
|
---|
| 2260 | * Extract mondo-restore.cfg and the mountlist from the tape inserted
|
---|
| 2261 | * to the ./tmp/ directory.
|
---|
| 2262 | * @param dev The tape device to read from.
|
---|
| 2263 | * @return 0 for success, nonzero for failure.
|
---|
| 2264 | */
|
---|
[128] | 2265 | int extract_cfg_file_and_mountlist_from_tape_dev(char *dev)
|
---|
[1] | 2266 | {
|
---|
[128] | 2267 | char *command;
|
---|
| 2268 | int res = 0;
|
---|
| 2269 | // BCO: below 32KB seems to block at least on RHAS 2.1 and MDK 10.0
|
---|
| 2270 | long tape_block_size = 32768;
|
---|
[1] | 2271 |
|
---|
[128] | 2272 | malloc_string(command);
|
---|
[1] | 2273 |
|
---|
[128] | 2274 | // tar -zxvf-
|
---|
| 2275 | sprintf(command,
|
---|
| 2276 | "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx %s %s %s %s %s",
|
---|
| 2277 | dev,
|
---|
| 2278 | tape_block_size,
|
---|
| 2279 | 1024L * 1024 * 32 / tape_block_size,
|
---|
| 2280 | MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB,
|
---|
| 2281 | BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, "tmp/i-want-my-lvm");
|
---|
| 2282 | log_msg(2, "command = '%s'", command);
|
---|
| 2283 | res = run_program_and_log_output(command, -1);
|
---|
| 2284 | if (res != 0 && does_file_exist(MONDO_CFG_FILE_STUB)) {
|
---|
| 2285 | res = 0;
|
---|
| 2286 | }
|
---|
| 2287 | paranoid_free(command);
|
---|
| 2288 | return (res);
|
---|
[1] | 2289 | }
|
---|
| 2290 |
|
---|
[128] | 2291 |
|
---|
| 2292 |
|
---|
[1] | 2293 | /**
|
---|
| 2294 | * Get the configuration file from the floppy, tape, or CD.
|
---|
| 2295 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 2296 | * - @c bkpinfo->backup_media_type
|
---|
| 2297 | * - @c bkpinfo->media_device
|
---|
| 2298 | * - @c bkpinfo->tmpdir
|
---|
| 2299 | * @return 0 for success, nonzero for failure.
|
---|
| 2300 | */
|
---|
[1645] | 2301 | int get_cfg_file_from_archive()
|
---|
[1] | 2302 | {
|
---|
[128] | 2303 | int retval = 0;
|
---|
| 2304 |
|
---|
[1] | 2305 | /** malloc *****/
|
---|
[128] | 2306 | char *device;
|
---|
| 2307 | char *command;
|
---|
| 2308 | char *cfg_file;
|
---|
| 2309 | char *mounted_cfgf_path;
|
---|
| 2310 | char *tmp;
|
---|
| 2311 | char *mountpt;
|
---|
| 2312 | char *ramdisk_fname;
|
---|
| 2313 | char *mountlist_file;
|
---|
| 2314 | int res;
|
---|
[1] | 2315 |
|
---|
[128] | 2316 | bool try_plan_B;
|
---|
| 2317 |
|
---|
| 2318 | assert(bkpinfo != NULL);
|
---|
| 2319 | malloc_string(cfg_file);
|
---|
| 2320 | malloc_string(mounted_cfgf_path);
|
---|
| 2321 | malloc_string(mountpt);
|
---|
| 2322 | malloc_string(ramdisk_fname);
|
---|
| 2323 | malloc_string(mountlist_file);
|
---|
| 2324 | malloc_string(device);
|
---|
| 2325 | malloc_string(command);
|
---|
| 2326 | malloc_string(tmp);
|
---|
| 2327 | log_msg(2, "gcffa --- starting");
|
---|
[541] | 2328 | log_to_screen("I'm thinking...");
|
---|
[128] | 2329 | sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
|
---|
| 2330 | device[0] = '\0';
|
---|
| 2331 | chdir(bkpinfo->tmpdir);
|
---|
| 2332 | strcpy(cfg_file, MONDO_CFG_FILE_STUB);
|
---|
| 2333 | unlink(cfg_file); // cfg_file[] is missing the '/' at the start, FYI, by intent
|
---|
| 2334 | unlink(FILELIST_FULL_STUB);
|
---|
| 2335 | unlink(BIGGIELIST_TXT_STUB);
|
---|
| 2336 | unlink("tmp/i-want-my-lvm");
|
---|
| 2337 | sprintf(command, "mkdir -p %s", mountpt);
|
---|
| 2338 | run_program_and_log_output(command, FALSE);
|
---|
| 2339 |
|
---|
[1] | 2340 | // unlink( "tmp/mondo-restore.cfg" ); // superfluous, surely?
|
---|
| 2341 |
|
---|
[128] | 2342 | sprintf(cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB);
|
---|
| 2343 | sprintf(mountlist_file, "%s/%s", bkpinfo->tmpdir,
|
---|
| 2344 | MOUNTLIST_FNAME_STUB);
|
---|
| 2345 | // make_hole_for_file( cfg_file );
|
---|
| 2346 | // make_hole_for_file( mountlist_file);
|
---|
| 2347 | log_msg(2, "mountpt = %s; cfg_file=%s", mountpt, cfg_file);
|
---|
| 2348 |
|
---|
| 2349 | /* Floppy? */
|
---|
| 2350 | sprintf(tmp, "mkdir -p %s", mountpt);
|
---|
| 2351 | run_program_and_log_output(tmp, FALSE);
|
---|
| 2352 | sprintf(tmp, "mkdir -p %s/tmp", bkpinfo->tmpdir);
|
---|
| 2353 | run_program_and_log_output(tmp, FALSE);
|
---|
| 2354 |
|
---|
[1496] | 2355 | /* Is there a floppy drive detected */
|
---|
| 2356 | sprintf(tmp, "%s", call_program_and_get_last_line_of_output("dmesg | grep -i floppy"));
|
---|
| 2357 | if (strcmp(tmp, "")) {
|
---|
| 2358 | sprintf(command, "mount /dev/fd0u1722 %s", mountpt);
|
---|
| 2359 | sprintf(tmp,
|
---|
[746] | 2360 | "(sleep 15; kill `ps | grep \"%s\" | cut -d' ' -f1` 2> /dev/null) &",
|
---|
[128] | 2361 | command);
|
---|
[1496] | 2362 | log_msg(1, "tmp = '%s'", tmp);
|
---|
| 2363 | system(tmp);
|
---|
[128] | 2364 | res = run_program_and_log_output(command, FALSE);
|
---|
[1496] | 2365 | if (res) {
|
---|
| 2366 | sprintf(command, "mount /dev/fd0H1440 %s", mountpt);
|
---|
| 2367 | res = run_program_and_log_output(command, FALSE);
|
---|
| 2368 | }
|
---|
| 2369 | } else {
|
---|
| 2370 | res = 1;
|
---|
[128] | 2371 | }
|
---|
| 2372 | if (res) {
|
---|
| 2373 | try_plan_B = TRUE;
|
---|
| 2374 | } else {
|
---|
| 2375 | try_plan_B = TRUE;
|
---|
| 2376 | log_msg(2,
|
---|
| 2377 | "Mounted floppy OK but I don't trust it because the archives might contain more up-to-date config file than the floppy does.");
|
---|
[1496] | 2378 | // NB: If busybox does not support 'mount -o loop' then Plan A WILL NOT WORK.
|
---|
[128] | 2379 | log_msg(2, "Processing floppy (plan A?)");
|
---|
| 2380 | sprintf(ramdisk_fname, "%s/mindi.rdz", mountpt);
|
---|
| 2381 | if (!does_file_exist(ramdisk_fname)) {
|
---|
| 2382 | sprintf(ramdisk_fname, "%s/initrd.img", mountpt);
|
---|
| 2383 | }
|
---|
| 2384 | if (!does_file_exist(ramdisk_fname)) {
|
---|
| 2385 | log_msg(2,
|
---|
| 2386 | "Cannot find ramdisk file on mountpoint. Are you sure that's a boot disk in the drive?");
|
---|
| 2387 | }
|
---|
[1645] | 2388 | if (extract_config_file_from_ramdisk(ramdisk_fname, cfg_file, mountlist_file)) {
|
---|
[128] | 2389 | log_msg(2,
|
---|
| 2390 | "Warning - failed to extract config file from ramdisk. I think this boot disk is mangled.");
|
---|
| 2391 | }
|
---|
| 2392 | sprintf(command, "umount %s", mountpt);
|
---|
| 2393 | run_program_and_log_output(command, 5);
|
---|
| 2394 | unlink(ramdisk_fname);
|
---|
| 2395 | }
|
---|
| 2396 | if (!does_file_exist(cfg_file)) {
|
---|
| 2397 | log_msg(2, "gcffa --- we don't have cfg file yet.");
|
---|
| 2398 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 2399 | try_plan_B = TRUE;
|
---|
| 2400 | } else {
|
---|
[1736] | 2401 | log_msg(2, "gcffa --- calling mount_media now :)");
|
---|
| 2402 | if (!mount_media()) {
|
---|
[128] | 2403 | log_msg(2,
|
---|
| 2404 | "gcffa --- managed to mount CD; so, no need for Plan B");
|
---|
| 2405 | try_plan_B = FALSE;
|
---|
| 2406 | } else {
|
---|
| 2407 | try_plan_B = TRUE;
|
---|
| 2408 | }
|
---|
[1645] | 2409 | if (what_number_cd_is_this() > 1) {
|
---|
| 2410 | insist_on_this_cd_number((g_current_media_number = 1));
|
---|
[128] | 2411 | }
|
---|
| 2412 | }
|
---|
| 2413 | if (try_plan_B) {
|
---|
| 2414 | log_msg(2, "gcffa --- OK, switching to Plan B");
|
---|
| 2415 | chdir(bkpinfo->tmpdir);
|
---|
| 2416 | run_program_and_log_output("mkdir -p tmp", FALSE);
|
---|
[1] | 2417 |
|
---|
[128] | 2418 | if (strlen(bkpinfo->media_device) == 0) {
|
---|
| 2419 | strcpy(bkpinfo->media_device, "/dev/st0");
|
---|
| 2420 | log_msg(2, "media_device is blank; assuming %s");
|
---|
| 2421 | }
|
---|
| 2422 | strcpy(tmp, bkpinfo->media_device);
|
---|
| 2423 | if (extract_cfg_file_and_mountlist_from_tape_dev
|
---|
| 2424 | (bkpinfo->media_device)) {
|
---|
| 2425 | strcpy(bkpinfo->media_device, "/dev/st0");
|
---|
| 2426 | if (extract_cfg_file_and_mountlist_from_tape_dev
|
---|
| 2427 | (bkpinfo->media_device)) {
|
---|
| 2428 | strcpy(bkpinfo->media_device, "/dev/osst0");
|
---|
| 2429 | if (extract_cfg_file_and_mountlist_from_tape_dev
|
---|
| 2430 | (bkpinfo->media_device)) {
|
---|
| 2431 | strcpy(bkpinfo->media_device, "/dev/ht0");
|
---|
| 2432 | if (extract_cfg_file_and_mountlist_from_tape_dev
|
---|
| 2433 | (bkpinfo->media_device)) {
|
---|
| 2434 | log_msg(3,
|
---|
| 2435 | "I tried lots of devices but none worked.");
|
---|
| 2436 | strcpy(bkpinfo->media_device, tmp);
|
---|
| 2437 | }
|
---|
| 2438 | }
|
---|
| 2439 | }
|
---|
| 2440 | }
|
---|
[1] | 2441 |
|
---|
[128] | 2442 | if (!does_file_exist("tmp/mondo-restore.cfg")) {
|
---|
[541] | 2443 | log_to_screen("Cannot find config info on tape/CD/floppy");
|
---|
[128] | 2444 | return (1);
|
---|
| 2445 | }
|
---|
| 2446 | } else {
|
---|
[1406] | 2447 | /* That boot imae doesn't always exist where the following method always works
|
---|
[128] | 2448 | log_msg(2,
|
---|
| 2449 | "gcffa --- looking at mounted CD for mindi-boot.2880.img");
|
---|
| 2450 | sprintf(command,
|
---|
| 2451 | "mount " MNT_CDROM
|
---|
| 2452 | "/images/mindi-boot.2880.img -o loop %s", mountpt);
|
---|
| 2453 | sprintf(mounted_cfgf_path, "%s/%s", mountpt, cfg_file);
|
---|
| 2454 | if (!does_file_exist(mounted_cfgf_path)) {
|
---|
[1406] | 2455 | */
|
---|
[128] | 2456 | log_msg(2,
|
---|
[1406] | 2457 | "gcffa --- Plan B, a.k.a. untarring some file from all.tar.gz");
|
---|
[128] | 2458 | sprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz %s %s %s %s %s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, "tmp/i-want-my-lvm"); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary
|
---|
| 2459 | run_program_and_log_output(command, TRUE);
|
---|
| 2460 | if (!does_file_exist(MONDO_CFG_FILE_STUB)) {
|
---|
| 2461 | fatal_error
|
---|
| 2462 | ("Please reinsert the disk/CD and try again.");
|
---|
| 2463 | }
|
---|
[1406] | 2464 | /*
|
---|
[128] | 2465 | }
|
---|
[1406] | 2466 | */
|
---|
[1] | 2467 | }
|
---|
[128] | 2468 | }
|
---|
| 2469 | if (does_file_exist(MONDO_CFG_FILE_STUB)) {
|
---|
| 2470 | log_msg(1, "gcffa --- great! We've got the config file");
|
---|
| 2471 | sprintf(tmp, "%s/%s",
|
---|
| 2472 | call_program_and_get_last_line_of_output("pwd"),
|
---|
| 2473 | MONDO_CFG_FILE_STUB);
|
---|
| 2474 | sprintf(command, "cp -f %s %s", tmp, cfg_file);
|
---|
| 2475 | iamhere(command);
|
---|
| 2476 | if (strcmp(tmp, cfg_file)
|
---|
| 2477 | && run_program_and_log_output(command, 1)) {
|
---|
| 2478 | log_msg(1,
|
---|
| 2479 | "... but an error occurred when I tried to move it to %s",
|
---|
| 2480 | cfg_file);
|
---|
| 2481 | } else {
|
---|
| 2482 | log_msg(1, "... and I moved it successfully to %s", cfg_file);
|
---|
| 2483 | }
|
---|
| 2484 | sprintf(command, "cp -f %s/%s %s",
|
---|
| 2485 | call_program_and_get_last_line_of_output("pwd"),
|
---|
| 2486 | MOUNTLIST_FNAME_STUB, mountlist_file);
|
---|
| 2487 | iamhere(command);
|
---|
| 2488 | if (strcmp(tmp, cfg_file)
|
---|
| 2489 | && run_program_and_log_output(command, 1)) {
|
---|
| 2490 | log_msg(1, "Failed to get mountlist");
|
---|
| 2491 | } else {
|
---|
| 2492 | log_msg(1, "Got mountlist too");
|
---|
| 2493 | sprintf(command, "cp -f %s %s", mountlist_file,
|
---|
| 2494 | g_mountlist_fname);
|
---|
| 2495 | if (run_program_and_log_output(command, 1)) {
|
---|
| 2496 | log_msg(1, "Failed to copy mountlist to /tmp");
|
---|
| 2497 | } else {
|
---|
| 2498 | log_msg(1, "Copied mountlist to /tmp as well OK");
|
---|
| 2499 | sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/");
|
---|
| 2500 | run_program_and_log_output(command, 1);
|
---|
[1] | 2501 | /* sprintf(command, "grep \" lvm \" %s", g_mountlist_fname);
|
---|
| 2502 | if (!run_program_and_log_output(command, 5) && !does_file_exist("/tmp/i-want-my-lvm"))
|
---|
| 2503 | {
|
---|
| 2504 | log_msg(1, "Warning. You want LVM but I don't have i-want-my-lvm. FIXME.");
|
---|
| 2505 | }
|
---|
| 2506 | else if (run_program_and_log_output(command,5) && does_file_exist("/tmp/i-want-my-lvm"))
|
---|
| 2507 | {
|
---|
| 2508 | log_msg(1, "Warning. You don't want LVM but i-want-my-lvm exists. I'll delete it. Cool.");
|
---|
| 2509 | do_my_funky_lvm_stuff(TRUE, FALSE); // ...after I stop any LVMs :)
|
---|
| 2510 | stop_raid_device("/dev/md0");
|
---|
| 2511 | stop_raid_device("/dev/md1");
|
---|
| 2512 | stop_raid_device("/dev/md2");
|
---|
| 2513 | unlink("/tmp/i-want-my-lvm");
|
---|
| 2514 | }
|
---|
| 2515 | else if (!run_program_and_log_output(command,5) && does_file_exist("/tmp/i-want-my-lvm"))
|
---|
| 2516 | {
|
---|
| 2517 | log_msg(1, "You had better pray that i-want-my-lvm patches your mountlist. FIXME.");
|
---|
| 2518 | }
|
---|
| 2519 | */
|
---|
[128] | 2520 | }
|
---|
| 2521 | }
|
---|
| 2522 | }
|
---|
| 2523 | run_program_and_log_output("umount " MNT_CDROM, FALSE);
|
---|
| 2524 | if (!does_file_exist(cfg_file)) {
|
---|
| 2525 | iamhere(cfg_file);
|
---|
| 2526 | log_msg(1, "%s not found", cfg_file);
|
---|
| 2527 | log_to_screen
|
---|
[541] | 2528 | ("Oh dear. Unable to recover configuration file from boot disk");
|
---|
[128] | 2529 | return (1);
|
---|
| 2530 | }
|
---|
[1] | 2531 |
|
---|
[541] | 2532 | log_to_screen("Recovered mondo-restore.cfg");
|
---|
[128] | 2533 | if (!does_file_exist(MOUNTLIST_FNAME_STUB)) {
|
---|
[541] | 2534 | log_to_screen("...but not mountlist.txt - a pity, really...");
|
---|
[128] | 2535 | }
|
---|
[1] | 2536 | /* start SAH */
|
---|
[128] | 2537 | else {
|
---|
| 2538 | sprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB,
|
---|
| 2539 | bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
|
---|
| 2540 | run_program_and_log_output(command, FALSE);
|
---|
| 2541 | }
|
---|
[1] | 2542 | /*--commented out by SAH
|
---|
| 2543 | sprintf( command, "cp -f %s %s/%s", cfg_file, bkpinfo->tmpdir, MONDO_CFG_FILE_STUB );
|
---|
| 2544 | run_program_and_log_output( command, FALSE );
|
---|
| 2545 | sprintf( command, "cp -f %s %s/%s", mountlist_file, bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB );
|
---|
| 2546 | run_program_and_log_output( command, FALSE );
|
---|
| 2547 | */
|
---|
| 2548 | /* end SAH */
|
---|
| 2549 |
|
---|
[128] | 2550 | sprintf(command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB);
|
---|
| 2551 | run_program_and_log_output(command, FALSE);
|
---|
| 2552 | sprintf(command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB);
|
---|
| 2553 | run_program_and_log_output(command, FALSE);
|
---|
| 2554 | sprintf(command, "cp -f etc/raidtab /etc/");
|
---|
| 2555 | run_program_and_log_output(command, FALSE);
|
---|
| 2556 | sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/");
|
---|
| 2557 | run_program_and_log_output(command, FALSE);
|
---|
| 2558 | g_backup_media_type = bkpinfo->backup_media_type;
|
---|
| 2559 | paranoid_free(device);
|
---|
| 2560 | paranoid_free(command);
|
---|
| 2561 | paranoid_free(tmp);
|
---|
| 2562 | paranoid_free(cfg_file);
|
---|
| 2563 | paranoid_free(mounted_cfgf_path);
|
---|
| 2564 | paranoid_free(mountpt);
|
---|
| 2565 | paranoid_free(ramdisk_fname);
|
---|
| 2566 | paranoid_free(mountlist_file);
|
---|
| 2567 | return (retval);
|
---|
[1] | 2568 | }
|
---|
| 2569 |
|
---|
| 2570 | /**************************************************************************
|
---|
| 2571 | *END_GET_CFG_FILE_FROM_ARCHIVE *
|
---|
| 2572 | **************************************************************************/
|
---|
| 2573 |
|
---|
| 2574 | /* @} - end restoreUtilityGroup */
|
---|
| 2575 |
|
---|
| 2576 |
|
---|
| 2577 | /***************************************************************************
|
---|
| 2578 | * F@ *
|
---|
| 2579 | * () -- Hugo Rabson *
|
---|
| 2580 | * *
|
---|
| 2581 | * Purpose: *
|
---|
| 2582 | * *
|
---|
| 2583 | * Called by: *
|
---|
| 2584 | * Params: - - *
|
---|
| 2585 | * Returns: 0=success; nonzero=failure *
|
---|
| 2586 | ***************************************************************************/
|
---|
| 2587 |
|
---|
[128] | 2588 |
|
---|
| 2589 |
|
---|
| 2590 | void wait_until_software_raids_are_prepped(char *mdstat_file,
|
---|
| 2591 | int wait_for_percentage)
|
---|
[1] | 2592 | {
|
---|
[558] | 2593 | struct raidlist_itself *raidlist;
|
---|
[128] | 2594 | int unfinished_mdstat_devices = 9999, i;
|
---|
| 2595 | char *screen_message;
|
---|
[1] | 2596 |
|
---|
[128] | 2597 | malloc_string(screen_message);
|
---|
[558] | 2598 | raidlist = malloc(sizeof(struct raidlist_itself));
|
---|
[128] | 2599 |
|
---|
| 2600 | assert(wait_for_percentage <= 100);
|
---|
[799] | 2601 | iamhere("wait_until_software_raids_are_prepped");
|
---|
[128] | 2602 | while (unfinished_mdstat_devices > 0) {
|
---|
[558] | 2603 | // FIXME: Prefix '/dev/' should really be dynamic!
|
---|
| 2604 | if (parse_mdstat(raidlist, "/dev/")) {
|
---|
| 2605 | log_to_screen("Sorry, cannot read %s", MDSTAT_FILE);
|
---|
| 2606 | log_msg(1,"Sorry, cannot read %s", MDSTAT_FILE);
|
---|
[128] | 2607 | return;
|
---|
[1] | 2608 | }
|
---|
[558] | 2609 | for (unfinished_mdstat_devices = i = 0; i <= raidlist->entries; i++) {
|
---|
| 2610 | if (raidlist->el[i].progress < wait_for_percentage) {
|
---|
[128] | 2611 | unfinished_mdstat_devices++;
|
---|
[704] | 2612 | if (raidlist->el[i].progress == -1) // delayed while another partition inits
|
---|
| 2613 | {
|
---|
| 2614 | continue;
|
---|
| 2615 | }
|
---|
[558] | 2616 | log_msg(1,"Sync'ing %s (i=%d)", raidlist->el[i].raid_device, i);
|
---|
| 2617 | sprintf(screen_message, "Sync'ing %s",
|
---|
| 2618 | raidlist->el[i].raid_device);
|
---|
[128] | 2619 | open_evalcall_form(screen_message);
|
---|
[558] | 2620 | while (raidlist->el[i].progress < wait_for_percentage) {
|
---|
| 2621 | log_msg(1,"Percentage sync'ed: %d", raidlist->el[i].progress);
|
---|
| 2622 | update_evalcall_form(raidlist->el[i].progress);
|
---|
[128] | 2623 | sleep(2);
|
---|
[558] | 2624 | // FIXME: Prefix '/dev/' should really be dynamic!
|
---|
| 2625 | if (parse_mdstat(raidlist, "/dev/")) {
|
---|
[128] | 2626 | break;
|
---|
| 2627 | }
|
---|
| 2628 | }
|
---|
| 2629 | close_evalcall_form();
|
---|
| 2630 | }
|
---|
[1] | 2631 | }
|
---|
[128] | 2632 | }
|
---|
| 2633 | paranoid_free(screen_message);
|
---|
[558] | 2634 | paranoid_free(raidlist);
|
---|
[1] | 2635 | }
|
---|