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