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