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