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