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