[1] | 1 | /***************************************************************************
|
---|
[2029] | 2 | $Id: mondo-rstr-tools.c 3874 2024-03-07 18:23:09Z 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"
|
---|
[3873] | 17 | #include "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, "dvd")) {
|
---|
| 674 | bkpinfo->backup_media_type = dvd;
|
---|
| 675 | } else if (!strcmp(value, "usb")) {
|
---|
| 676 | bkpinfo->backup_media_type = usb;
|
---|
| 677 | bkpinfo->please_dont_eject = TRUE;
|
---|
| 678 | } else if (!strcmp(value, "iso")) {
|
---|
| 679 | bkpinfo->backup_media_type = iso;
|
---|
| 680 | if (am_I_in_disaster_recovery_mode()) {
|
---|
| 681 | /* Check to see if CD is already mounted before mounting it... */
|
---|
| 682 | if (!is_this_device_mounted("/dev/cdrom")) {
|
---|
| 683 | log_msg(2, "NB: CDROM device not mounted, mounting...");
|
---|
| 684 | run_program_and_log_output("mount /dev/cdrom "MNT_CDROM, 1);
|
---|
| 685 | }
|
---|
| 686 | if (does_file_exist(MNT_CDROM"/archives/filelist.0")) {
|
---|
| 687 | bkpinfo->backup_media_type = cdr;
|
---|
| 688 | run_program_and_log_output("umount -d "MNT_CDROM, 1);
|
---|
| 689 | log_it("Re-jigging configuration AGAIN. CD-R, not ISO.");
|
---|
| 690 | }
|
---|
[128] | 691 | }
|
---|
[3193] | 692 | if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
|
---|
[3835] | 693 | mr_asprintf(bkpinfo->prefix, "%s", value);
|
---|
[3193] | 694 | } else {
|
---|
[3835] | 695 | mr_asprintf(bkpinfo->prefix, "%s", STD_PREFIX);
|
---|
[949] | 696 | }
|
---|
[3193] | 697 | log_it("Setting Prefix to %s", bkpinfo->prefix);
|
---|
| 698 | } else if ((!strcmp(value, "netfs")) || (!strcmp(value, "nfs"))) {
|
---|
| 699 | /* Stay compatible with previous versions by allowing nfs as an entry here */
|
---|
| 700 | bkpinfo->backup_media_type = netfs;
|
---|
| 701 | bkpinfo->please_dont_eject = TRUE;
|
---|
| 702 | if (read_cfg_var(cfg_file, "netfs-proto", value) == 0) {
|
---|
| 703 | mr_asprintf(bkpinfo->netfs_proto,"%s", value);
|
---|
| 704 | } else {
|
---|
| 705 | /* For compatibility, force protocol in old nfs case to be transparent */
|
---|
| 706 | mr_asprintf(bkpinfo->netfs_proto, "nfs");
|
---|
| 707 | }
|
---|
| 708 | if (read_cfg_var(cfg_file, "netfs-server-user", value) == 0) {
|
---|
| 709 | mr_asprintf(bkpinfo->netfs_user,"%s", value);
|
---|
| 710 | }
|
---|
| 711 | if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
|
---|
[3835] | 712 | mr_asprintf(bkpinfo->prefix, "%s", value);
|
---|
[3193] | 713 | } else {
|
---|
[3835] | 714 | mr_asprintf(bkpinfo->prefix, "%s", STD_PREFIX);
|
---|
[3193] | 715 | }
|
---|
[3610] | 716 | tmp1 = call_program_and_get_last_line_of_output("cat "CMDLINE);
|
---|
| 717 | if (strstr(tmp1, "pxe")) {
|
---|
[3193] | 718 | /* We need to override prefix value in PXE mode as it's
|
---|
| 719 | * already done in start-netfs */
|
---|
| 720 | envtmp1 = getenv("imgname");
|
---|
| 721 | if (envtmp1 == NULL) {
|
---|
| 722 | fatal_error("no imgname variable in environment");
|
---|
| 723 | }
|
---|
[3835] | 724 | mr_asprintf(bkpinfo->prefix, "%s", envtmp1);
|
---|
[3193] | 725 | }
|
---|
[3610] | 726 | mr_free(tmp1);
|
---|
[3193] | 727 | } else if (!strcmp(value, "tape")) {
|
---|
| 728 | bkpinfo->backup_media_type = tape;
|
---|
| 729 | } else if (!strcmp(value, "udev")) {
|
---|
| 730 | bkpinfo->backup_media_type = udev;
|
---|
| 731 | } else {
|
---|
| 732 | fatal_error("UNKNOWN bkp-media-type");
|
---|
[949] | 733 | }
|
---|
[1242] | 734 | } else {
|
---|
[3193] | 735 | fatal_error("backup-media-type not specified!");
|
---|
[1242] | 736 | }
|
---|
[3193] | 737 |
|
---|
[1242] | 738 | if (bkpinfo->disaster_recovery) {
|
---|
[1736] | 739 | if (bkpinfo->backup_media_type == cdstream) {
|
---|
[3822] | 740 | mr_asprintf(bkpinfo->media_device, "%s", "/dev/cdrom");
|
---|
[3150] | 741 | bkpinfo->media_size = 650; /* good guess */
|
---|
[1736] | 742 | } else if (bkpinfo->backup_media_type == usb) {
|
---|
[2127] | 743 | envtmp1 = getenv("MRUSBDEV");
|
---|
| 744 | if (envtmp1 == NULL) {
|
---|
| 745 | if (read_cfg_var(cfg_file, "usb-dev", value)) {
|
---|
| 746 | fatal_error("Cannot get USB device name from cfg file");
|
---|
| 747 | }
|
---|
| 748 | } else {
|
---|
| 749 | strcpy(value,envtmp1);
|
---|
[1736] | 750 | }
|
---|
[3822] | 751 | mr_asprintf(bkpinfo->media_device, "%s1", value);
|
---|
[3193] | 752 | log_msg(2, "Backup medium is USB --- dev=%s", bkpinfo->media_device);
|
---|
| 753 | } else if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) {
|
---|
[1736] | 754 | if (read_cfg_var(cfg_file, "media-dev", value)) {
|
---|
| 755 | fatal_error("Cannot get tape device name from cfg file");
|
---|
| 756 | }
|
---|
[3822] | 757 | mr_asprintf(bkpinfo->media_device, "%s", value);
|
---|
[1736] | 758 | read_cfg_var(cfg_file, "media-size", value);
|
---|
[3150] | 759 | bkpinfo->media_size = atol(value);
|
---|
[3193] | 760 | log_msg(2, "Backup medium is TAPE --- dev=%s", bkpinfo->media_device);
|
---|
[1736] | 761 | } else {
|
---|
[3822] | 762 | mr_asprintf(bkpinfo->media_device, "%s", "/dev/cdrom"); /* we don't really need this var */
|
---|
[3150] | 763 | bkpinfo->media_size = 1999 * 1024; /* 650, probably, but we don't need this var anyway */
|
---|
[3158] | 764 | log_msg(2, "Backup medium is similar to CD-R[W]");
|
---|
[1] | 765 | }
|
---|
[1242] | 766 | } else {
|
---|
[3193] | 767 | log_msg(2, "Not in Disaster Recovery Mode. No need to derive device name from config file.");
|
---|
[1242] | 768 | }
|
---|
[128] | 769 |
|
---|
[1242] | 770 | read_cfg_var(cfg_file, "use-star", value);
|
---|
| 771 | if (strstr(value, "yes")) {
|
---|
[1948] | 772 | bkpinfo->use_star = TRUE;
|
---|
| 773 | log_msg(1, "Goody! ... bkpinfo->use_star is now true.");
|
---|
[1242] | 774 | }
|
---|
| 775 |
|
---|
[1948] | 776 | read_cfg_var(cfg_file, "obdr", value);
|
---|
| 777 | if (strstr(value, "TRUE")) {
|
---|
| 778 | bkpinfo->use_obdr = TRUE;
|
---|
| 779 | log_msg(1, "OBDR mode activated");
|
---|
| 780 | }
|
---|
| 781 |
|
---|
[1242] | 782 | read_cfg_var(cfg_file, "acl", value);
|
---|
| 783 | if (strstr(value, "TRUE")) {
|
---|
[3866] | 784 | if ((tmp = find_home_of_exe("setfacl")) == NULL) {
|
---|
[1948] | 785 | log_msg(1, "Unable to restore ACLs as no setfacl found");
|
---|
[3866] | 786 | } else {
|
---|
| 787 | mr_asprintf(g_getfacl,"%s", tmp);
|
---|
| 788 | log_msg(1, "We will restore ACLs");
|
---|
[1948] | 789 | }
|
---|
[3866] | 790 | mr_free(tmp);
|
---|
[1242] | 791 | }
|
---|
| 792 | read_cfg_var(cfg_file, "xattr", value);
|
---|
| 793 | if (strstr(value, "TRUE")) {
|
---|
[3866] | 794 | if ((tmp = find_home_of_exe("setfattr")) == NULL) {
|
---|
[1948] | 795 | log_msg(1, "Unable to restore XATTRs as no setfattr found");
|
---|
[3866] | 796 | } else {
|
---|
| 797 | mr_asprintf(g_getfattr,"%s", tmp);
|
---|
| 798 | log_msg(1, "We will restore XATTRs");
|
---|
[1948] | 799 | }
|
---|
[3866] | 800 | mr_free(tmp);
|
---|
[1242] | 801 | }
|
---|
| 802 |
|
---|
| 803 | if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value)) {
|
---|
[3193] | 804 | bkpinfo->internal_tape_block_size = atol(value);
|
---|
[1242] | 805 | } else {
|
---|
[3193] | 806 | bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
|
---|
[1242] | 807 | }
|
---|
[3193] | 808 | log_msg(1, "Internal tape block size set to %ld", bkpinfo->internal_tape_block_size);
|
---|
[1242] | 809 |
|
---|
[3193] | 810 | read_cfg_var(cfg_file, "use-lzma", value);
|
---|
| 811 | if (strstr(value, "yes")) {
|
---|
| 812 | bkpinfo->use_lzma = TRUE;
|
---|
| 813 | bkpinfo->use_lzo = FALSE;
|
---|
| 814 | bkpinfo->use_gzip = FALSE;
|
---|
[3830] | 815 | mr_asprintf(bkpinfo->zip_exe, "%s", "lzma");
|
---|
| 816 | mr_asprintf(bkpinfo->zip_suffix, "%s", "lzma");
|
---|
[3193] | 817 | }
|
---|
| 818 |
|
---|
[1242] | 819 | read_cfg_var(cfg_file, "use-lzo", value);
|
---|
| 820 | if (strstr(value, "yes")) {
|
---|
[3193] | 821 | bkpinfo->use_lzma = FALSE;
|
---|
| 822 | bkpinfo->use_lzo = TRUE;
|
---|
| 823 | bkpinfo->use_gzip = FALSE;
|
---|
[3830] | 824 | mr_asprintf(bkpinfo->zip_exe, "%s", "lzop");
|
---|
| 825 | mr_asprintf(bkpinfo->zip_suffix, "%s", "lzo");
|
---|
[3193] | 826 | }
|
---|
| 827 |
|
---|
[1242] | 828 | read_cfg_var(cfg_file, "use-gzip", value);
|
---|
| 829 | if (strstr(value, "yes")) {
|
---|
[3193] | 830 | bkpinfo->use_lzma = FALSE;
|
---|
[1242] | 831 | bkpinfo->use_lzo = FALSE;
|
---|
| 832 | bkpinfo->use_gzip = TRUE;
|
---|
[3830] | 833 | mr_asprintf(bkpinfo->zip_exe, "%s", "gzip");
|
---|
| 834 | mr_asprintf(bkpinfo->zip_suffix, "%s", "gz");
|
---|
[1242] | 835 | }
|
---|
[3193] | 836 |
|
---|
| 837 | read_cfg_var(cfg_file, "use-comp", value);
|
---|
| 838 | if (strstr(value, "yes")) {
|
---|
| 839 | bkpinfo->use_lzma = FALSE;
|
---|
| 840 | bkpinfo->use_lzo = FALSE;
|
---|
| 841 | bkpinfo->use_gzip = FALSE;
|
---|
[3830] | 842 | mr_asprintf(bkpinfo->zip_exe, "%s", "xz");
|
---|
| 843 | mr_asprintf(bkpinfo->zip_suffix, "%s", "xz");
|
---|
[1242] | 844 | }
|
---|
[1] | 845 |
|
---|
[1242] | 846 | value[0] = '\0';
|
---|
| 847 | read_cfg_var(cfg_file, "differential", value);
|
---|
| 848 | if (!strcmp(value, "yes") || !strcmp(value, "1")) {
|
---|
[3193] | 849 | bkpinfo->differential = TRUE;
|
---|
[1242] | 850 | }
|
---|
| 851 | log_msg(2, "differential var = '%s'", value);
|
---|
| 852 | if (bkpinfo->differential) {
|
---|
[3193] | 853 | log_msg(2, "THIS IS A DIFFERENTIAL BACKUP");
|
---|
[1242] | 854 | } else {
|
---|
[3193] | 855 | log_msg(2, "This is a regular (full) backup");
|
---|
[1242] | 856 | }
|
---|
| 857 |
|
---|
[3211] | 858 | read_cfg_var(cfg_file, "please-dont-eject", value);
|
---|
[3610] | 859 | tmp1 = call_program_and_get_last_line_of_output("cat "CMDLINE);
|
---|
| 860 | if (value[0] || strstr(tmp1, "donteject")) {
|
---|
[3158] | 861 | bkpinfo->please_dont_eject = TRUE;
|
---|
| 862 | log_msg(2, "Ok, I shan't eject when restoring! Groovy.");
|
---|
[1242] | 863 | }
|
---|
[3610] | 864 | mr_free(tmp1);
|
---|
[1242] | 865 |
|
---|
[3430] | 866 | /* TODO: Read here the boot_* variables */
|
---|
[3397] | 867 | read_cfg_var(cfg_file, "boot-type", value);
|
---|
| 868 | if (!strcmp(value, "BIOS")) {
|
---|
| 869 | bkpinfo->boot_type = BIOS;
|
---|
| 870 | } else if (!strcmp(value, "EFI")) {
|
---|
| 871 | bkpinfo->boot_type = EFI;
|
---|
| 872 | } else if (!strcmp(value, "UEFI")) {
|
---|
| 873 | bkpinfo->boot_type = UEFI;
|
---|
| 874 | } else {
|
---|
| 875 | log_msg(1, "No known boot type found");
|
---|
| 876 | }
|
---|
| 877 | log_msg(1, "Found %s boot type",value);
|
---|
| 878 |
|
---|
[2380] | 879 | if (bkpinfo->backup_media_type == netfs) {
|
---|
[1736] | 880 | if (!cfgf) {
|
---|
[3193] | 881 | if (bkpinfo->netfs_mount) {
|
---|
| 882 | log_msg(2, "netfs_mount remains %s", bkpinfo->netfs_mount);
|
---|
| 883 | }
|
---|
[3207] | 884 | if (bkpinfo->netfs_remote_dir != NULL) {
|
---|
[3193] | 885 | log_msg(2, "netfs_remote_dir remains %s", bkpinfo->netfs_remote_dir);
|
---|
| 886 | }
|
---|
| 887 | 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] | 888 | } else {
|
---|
[3211] | 889 | read_cfg_var(cfg_file, "netfs-server-mount", value);
|
---|
[3193] | 890 | mr_free(bkpinfo->netfs_mount);
|
---|
| 891 | mr_asprintf(bkpinfo->netfs_mount, "%s", value);
|
---|
[3278] | 892 | if (bkpinfo->netfs_mount != NULL) {
|
---|
| 893 | log_msg(2, "netfs_mount is %s", bkpinfo->netfs_mount);
|
---|
| 894 | }
|
---|
[3193] | 895 |
|
---|
[3278] | 896 | read_cfg_var(cfg_file, "iso-dir", value);
|
---|
[3193] | 897 | mr_free(bkpinfo->netfs_remote_dir);
|
---|
| 898 | mr_asprintf(bkpinfo->netfs_remote_dir, "%s", value);
|
---|
| 899 | if (bkpinfo->netfs_remote_dir != NULL) {
|
---|
| 900 | log_msg(2, "netfs_remote_dir is %s", bkpinfo->netfs_remote_dir);
|
---|
| 901 | }
|
---|
[3278] | 902 |
|
---|
[3193] | 903 | if (bkpinfo->netfs_proto != NULL) {
|
---|
| 904 | log_msg(2, "netfs_proto is %s", bkpinfo->netfs_proto);
|
---|
| 905 | }
|
---|
| 906 | if (bkpinfo->netfs_user != NULL) {
|
---|
[2847] | 907 | log_msg(2, "netfs_user is %s", bkpinfo->netfs_user);
|
---|
| 908 | }
|
---|
[1] | 909 | }
|
---|
[3610] | 910 | tmp1 = call_program_and_get_last_line_of_output("cat "CMDLINE);
|
---|
| 911 | if (strstr(tmp1, "pxe")) {
|
---|
[1968] | 912 | /* We need to override values in PXE mode as it's
|
---|
[2380] | 913 | * already done in start-netfs */
|
---|
| 914 | envtmp1 = getenv("netfsmount");
|
---|
[1736] | 915 | if (envtmp1 == NULL) {
|
---|
[2380] | 916 | fatal_error("no netfsmount variable in environment");
|
---|
[1736] | 917 | }
|
---|
| 918 | envtmp2 = getenv("dirimg");
|
---|
| 919 | if (envtmp2 == NULL) {
|
---|
| 920 | fatal_error("no dirimg variable in environment");
|
---|
| 921 | }
|
---|
[3193] | 922 | mr_free(bkpinfo->netfs_mount);
|
---|
| 923 | mr_asprintf(bkpinfo->netfs_mount, "%s", envtmp1);
|
---|
| 924 |
|
---|
| 925 | mr_free(bkpinfo->netfs_remote_dir);
|
---|
| 926 | mr_asprintf(bkpinfo->netfs_remote_dir, "%s", envtmp2);
|
---|
[1] | 927 | }
|
---|
[3610] | 928 | mr_free(tmp1);
|
---|
[1242] | 929 | } else if (bkpinfo->backup_media_type == iso) {
|
---|
[1736] | 930 | /* Patch by Conor Daly 23-june-2004
|
---|
| 931 | * to correctly mount iso-dev and set a sensible
|
---|
| 932 | * isodir in disaster recovery mode
|
---|
| 933 | */
|
---|
[3193] | 934 | mr_asprintf(old_isodir, "%s", bkpinfo->isodir);
|
---|
[3836] | 935 | if (read_cfg_var(cfg_file, "iso-mnt", iso_mnt) != 0) {
|
---|
| 936 | iso_mnt[0] = '\0';
|
---|
[128] | 937 | }
|
---|
[3836] | 938 | if (read_cfg_var(cfg_file, "iso-dir", iso_path) != 0) {
|
---|
| 939 | iso_path[0] = '\0';
|
---|
| 940 | }
|
---|
| 941 | mr_asprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
|
---|
[3839] | 942 | if (!strcmp(bkpinfo->isodir,"")) {
|
---|
[3836] | 943 | mr_asprintf(bkpinfo->isodir, "%s", old_isodir);
|
---|
| 944 | }
|
---|
| 945 |
|
---|
[3158] | 946 | if ((!bkpinfo->disaster_recovery) || (g_isodir_device[0] != '\0')) {
|
---|
[1736] | 947 | if (strcmp(old_isodir, bkpinfo->isodir)) {
|
---|
[3193] | 948 | log_it("user nominated isodir %s differs from archive, keeping user's choice: %s\n", bkpinfo->isodir, old_isodir );
|
---|
[3836] | 949 | mr_asprintf(bkpinfo->isodir, "%s", old_isodir);
|
---|
[1736] | 950 | }
|
---|
| 951 | }
|
---|
[3211] | 952 | mr_free(old_isodir);
|
---|
| 953 |
|
---|
[3158] | 954 | if (g_isodir_device[0] == '\0') {
|
---|
| 955 | /* We don't want to loose our conf made earlier in iso_fiddly_bits
|
---|
| 956 | * so go here only if job not done already */
|
---|
[3211] | 957 | read_cfg_var(cfg_file, "iso-dev", g_isodir_device);
|
---|
[3158] | 958 | }
|
---|
| 959 |
|
---|
| 960 | log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir, g_isodir_device);
|
---|
[3193] | 961 |
|
---|
[1736] | 962 | if (bkpinfo->disaster_recovery) {
|
---|
| 963 | if (is_this_device_mounted(g_isodir_device)) {
|
---|
| 964 | log_msg(2, "NB: isodir is already mounted");
|
---|
| 965 | /* Find out where it's mounted */
|
---|
[3193] | 966 | mr_asprintf(command, "mount | grep -E '^%s' | tail -n1 | cut -d' ' -f3", g_isodir_device);
|
---|
[1736] | 967 | log_it("command = %s", command);
|
---|
[3610] | 968 | tmp1 = call_program_and_get_last_line_of_output(command);
|
---|
| 969 | log_it("res of it = %s", tmp1);
|
---|
| 970 | sprintf(iso_mnt, "%s", tmp1);
|
---|
[3193] | 971 | mr_free(command);
|
---|
[3610] | 972 | mr_free(tmp1);
|
---|
[1736] | 973 | } else {
|
---|
[3194] | 974 | sprintf(iso_mnt, "/tmp/isodir");
|
---|
[3193] | 975 | mr_asprintf(tmp1, "mkdir -p %s", iso_mnt);
|
---|
| 976 | run_program_and_log_output(tmp1, 5);
|
---|
| 977 | mr_free(tmp1);
|
---|
| 978 |
|
---|
| 979 | mr_asprintf(tmp1, "mount %s %s", g_isodir_device, iso_mnt);
|
---|
| 980 | if (run_program_and_log_output(tmp1, 3)) {
|
---|
| 981 | log_msg(1, "Unable to mount isodir. Perhaps this is really a CD backup?");
|
---|
[1736] | 982 | bkpinfo->backup_media_type = cdr;
|
---|
[3822] | 983 | mr_asprintf(bkpinfo->media_device, "%s", "/dev/cdrom"); /* superfluous */
|
---|
[3836] | 984 | mr_free(bkpinfo->isodir);
|
---|
| 985 | iso_mnt[0] = iso_path[0] = '\0';
|
---|
[1736] | 986 | if (mount_media()) {
|
---|
[3193] | 987 | mr_free(tmp1);
|
---|
| 988 | fatal_error("Unable to mount isodir. Failed to mount CD-ROM as well.");
|
---|
[1736] | 989 | } else {
|
---|
[3193] | 990 | log_msg(1, "You backed up to disk, then burned some CDs.");
|
---|
[1736] | 991 | }
|
---|
[128] | 992 | }
|
---|
[3193] | 993 | mr_free(tmp1);
|
---|
[128] | 994 | }
|
---|
[1736] | 995 | /* bkpinfo->isodir should now be the true path to prefix-1.iso etc... */
|
---|
[3193] | 996 | /* except when already done in iso_fiddly_bits */
|
---|
[3158] | 997 | if ((bkpinfo->backup_media_type == iso) && (g_isodir_device[0] == '\0')) {
|
---|
[3836] | 998 | mr_asprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
|
---|
[1736] | 999 | }
|
---|
[1] | 1000 | }
|
---|
[1242] | 1001 | }
|
---|
[3211] | 1002 | mr_free(cfg_file);
|
---|
[1] | 1003 |
|
---|
[1242] | 1004 | if (media_specified_by_user != none) {
|
---|
[1736] | 1005 | if (g_restoring_live_from_cd) {
|
---|
| 1006 | if (bkpinfo->backup_media_type != media_specified_by_user) {
|
---|
[3158] | 1007 | log_msg(2, "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)");
|
---|
[1736] | 1008 | interactively_obtain_media_parameters_from_user(FALSE);
|
---|
| 1009 | media_specified_by_user = bkpinfo->backup_media_type;
|
---|
| 1010 | get_cfg_file_from_archive();
|
---|
| 1011 | }
|
---|
[128] | 1012 | }
|
---|
[1736] | 1013 | bkpinfo->backup_media_type = media_specified_by_user;
|
---|
[1242] | 1014 | }
|
---|
| 1015 | g_backup_media_type = bkpinfo->backup_media_type;
|
---|
| 1016 | return (0);
|
---|
[1] | 1017 |
|
---|
| 1018 | }
|
---|
[128] | 1019 |
|
---|
[1] | 1020 | /**************************************************************************
|
---|
[1242] | 1021 | *END_READ_CFG_FILE_INTO_BKPINFO *
|
---|
| 1022 | **************************************************************************/
|
---|
[1] | 1023 |
|
---|
| 1024 |
|
---|
| 1025 |
|
---|
[128] | 1026 |
|
---|
[1] | 1027 | /**
|
---|
[1843] | 1028 | * Allow the user to edit the filelist and biggielist.
|
---|
| 1029 | * The filelist is unlinked after it is read.
|
---|
| 1030 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 1031 | * - @c bkpinfo->backup_media_type
|
---|
| 1032 | * - @c bkpinfo->isodir
|
---|
| 1033 | * - @c bkpinfo->media_device
|
---|
| 1034 | * - @c bkpinfo->tmpdir
|
---|
| 1035 | * @return The filelist structure containing the information read from disk.
|
---|
| 1036 | */
|
---|
[1] | 1037 | struct
|
---|
[1645] | 1038 | s_node *process_filelist_and_biggielist()
|
---|
[1] | 1039 | {
|
---|
[1242] | 1040 | struct s_node *filelist;
|
---|
[1] | 1041 |
|
---|
[3193] | 1042 | char *command = NULL;
|
---|
[3613] | 1043 | char *old_pwd = NULL;
|
---|
[3076] | 1044 | char *q;
|
---|
[1242] | 1045 | int res = 0;
|
---|
| 1046 | pid_t pid;
|
---|
[2049] | 1047 | bool extract_mountlist_stub = FALSE;
|
---|
[1] | 1048 |
|
---|
[1242] | 1049 | assert(bkpinfo != NULL);
|
---|
[1] | 1050 |
|
---|
[2049] | 1051 | /* If those files already exist, do not overwrite them later on */
|
---|
| 1052 | if (does_file_exist("/"MOUNTLIST_FNAME_STUB)) {
|
---|
| 1053 | extract_mountlist_stub = FALSE;
|
---|
| 1054 | } else {
|
---|
| 1055 | extract_mountlist_stub = TRUE;
|
---|
| 1056 | }
|
---|
| 1057 |
|
---|
[1242] | 1058 | if (does_file_exist(g_filelist_full)
|
---|
| 1059 | && does_file_exist(g_biggielist_txt)) {
|
---|
[1987] | 1060 | log_msg(1, "%s exists", g_filelist_full);
|
---|
| 1061 | log_msg(1, "%s exists", g_biggielist_txt);
|
---|
| 1062 | log_msg(2,
|
---|
[1242] | 1063 | "Filelist and biggielist already recovered from media. Yay!");
|
---|
| 1064 | } else {
|
---|
[3613] | 1065 | old_pwd = mr_getcwd();
|
---|
[3076] | 1066 | if (chdir(bkpinfo->tmpdir)) {
|
---|
| 1067 | // FIXME
|
---|
| 1068 | }
|
---|
[1987] | 1069 | log_msg(1, "chdir(%s)", bkpinfo->tmpdir);
|
---|
| 1070 | log_to_screen("Extracting filelist and biggielist from media...");
|
---|
| 1071 | unlink("/tmp/filelist.full");
|
---|
[2029] | 1072 | unlink(FILELIST_FULL_STUB);
|
---|
[1987] | 1073 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
[3193] | 1074 | 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] | 1075 | log_msg(1, "tarcommand = %s", command);
|
---|
| 1076 | run_program_and_log_output(command, 1);
|
---|
[3193] | 1077 | mr_free(command);
|
---|
| 1078 |
|
---|
[2029] | 1079 | if (!does_file_exist(FILELIST_FULL_STUB)) {
|
---|
| 1080 | /* Doing that allow us to remain compatible with pre-2.2.5 versions */
|
---|
| 1081 | log_msg(2, "pre-2.2.4 compatible mode on");
|
---|
[3193] | 1082 | 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] | 1083 | log_msg(1, "tarcommand = %s", command);
|
---|
| 1084 | run_program_and_log_output(command, 1);
|
---|
[3193] | 1085 | mr_free(command);
|
---|
[2029] | 1086 | }
|
---|
[1987] | 1087 | } else {
|
---|
[3193] | 1088 | log_msg(2, "Calling insist_on_this_cd_number; bkpinfo->isodir=%s", bkpinfo->isodir);
|
---|
[1987] | 1089 | insist_on_this_cd_number(1);
|
---|
| 1090 | log_msg(2, "Back from iotcn");
|
---|
| 1091 | run_program_and_log_output("mount", 1);
|
---|
[3193] | 1092 | 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] | 1093 |
|
---|
[1987] | 1094 | log_msg(1, "tarcommand = %s", command);
|
---|
| 1095 | run_program_and_log_output(command, 1);
|
---|
[3193] | 1096 | mr_free(command);
|
---|
| 1097 |
|
---|
[2029] | 1098 | if (!does_file_exist(FILELIST_FULL_STUB)) {
|
---|
| 1099 | /* Doing that allow us to remain compatible with pre-2.2.5 versions */
|
---|
| 1100 | log_msg(2, "pre-2.2.4 compatible mode on");
|
---|
[3193] | 1101 | 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] | 1102 |
|
---|
| 1103 | log_msg(1, "tarcommand = %s", command);
|
---|
| 1104 | run_program_and_log_output(command, 1);
|
---|
[3193] | 1105 | mr_free(command);
|
---|
[2029] | 1106 | }
|
---|
[1987] | 1107 | if (!does_file_exist(BIGGIELIST_TXT_STUB)) {
|
---|
[3193] | 1108 | fatal_error("all.tar.gz did not include " BIGGIELIST_TXT_STUB);
|
---|
[1987] | 1109 | }
|
---|
| 1110 | if (!does_file_exist(FILELIST_FULL_STUB)) {
|
---|
[3193] | 1111 | fatal_error("all.tar.gz did not include " FILELIST_FULL_STUB);
|
---|
[1987] | 1112 | }
|
---|
[128] | 1113 | }
|
---|
[3193] | 1114 | mr_asprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB, g_mondo_cfg_file);
|
---|
[1987] | 1115 | run_program_and_log_output(command, FALSE);
|
---|
[3193] | 1116 | mr_free(command);
|
---|
[1] | 1117 |
|
---|
[3193] | 1118 | mr_asprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir, BIGGIELIST_TXT_STUB, g_biggielist_txt);
|
---|
[1987] | 1119 | log_msg(1, "command = %s", command);
|
---|
| 1120 | paranoid_system(command);
|
---|
[3193] | 1121 | mr_free(command);
|
---|
| 1122 |
|
---|
| 1123 | mr_asprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir, FILELIST_FULL_STUB, g_filelist_full);
|
---|
[1987] | 1124 | log_msg(1, "command = %s", command);
|
---|
| 1125 | paranoid_system(command);
|
---|
[3193] | 1126 | mr_free(command);
|
---|
[1987] | 1127 | }
|
---|
[1242] | 1128 |
|
---|
[1987] | 1129 | if (am_I_in_disaster_recovery_mode()
|
---|
| 1130 | &&
|
---|
[2049] | 1131 | /* If it was there, do not overwrite it */
|
---|
| 1132 | (extract_mountlist_stub)
|
---|
| 1133 | &&
|
---|
[1987] | 1134 | ask_me_yes_or_no("Do you want to retrieve the mountlist as well?"))
|
---|
| 1135 | {
|
---|
[3193] | 1136 | mr_asprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB, bkpinfo->tmpdir);
|
---|
| 1137 | paranoid_system(command);
|
---|
| 1138 | mr_free(command);
|
---|
[1987] | 1139 | }
|
---|
[1] | 1140 |
|
---|
[3613] | 1141 | if (chdir(old_pwd)) {
|
---|
[3076] | 1142 | // FIXME
|
---|
| 1143 | }
|
---|
[3613] | 1144 | mr_free(old_pwd);
|
---|
[2049] | 1145 |
|
---|
[1987] | 1146 | if (!does_file_exist(g_biggielist_txt)) {
|
---|
| 1147 | log_msg(1, "Warning - %s not found", g_biggielist_txt);
|
---|
| 1148 | }
|
---|
| 1149 | if (!does_file_exist(g_filelist_full)) {
|
---|
| 1150 | log_msg(1, "Warning - %s does not exist", g_filelist_full);
|
---|
| 1151 | }
|
---|
[1] | 1152 |
|
---|
[1987] | 1153 | log_msg(2, "Forking");
|
---|
| 1154 | pid = fork();
|
---|
| 1155 | switch (pid) {
|
---|
| 1156 | case -1:
|
---|
| 1157 | fatal_error("Forking error");
|
---|
| 1158 | break;
|
---|
[1] | 1159 |
|
---|
[1987] | 1160 | case 0:
|
---|
| 1161 | log_to_screen("Pre-processing filelist");
|
---|
| 1162 | if (!does_file_exist(g_biggielist_txt)) {
|
---|
[3193] | 1163 | mr_asprintf(command, "echo -n > %s", g_biggielist_txt);
|
---|
[128] | 1164 | paranoid_system(command);
|
---|
[3193] | 1165 | mr_free(command);
|
---|
[128] | 1166 | }
|
---|
[3193] | 1167 | mr_asprintf(command, "grep -E '^/dev/.*' %s > %s", g_biggielist_txt, g_filelist_imagedevs);
|
---|
[128] | 1168 | paranoid_system(command);
|
---|
[3193] | 1169 | mr_free(command);
|
---|
[128] | 1170 | exit(0);
|
---|
| 1171 | break;
|
---|
| 1172 |
|
---|
| 1173 | default:
|
---|
[541] | 1174 | open_evalcall_form("Pre-processing filelist");
|
---|
[128] | 1175 | while (!waitpid(pid, (int *) 0, WNOHANG)) {
|
---|
| 1176 | usleep(100000);
|
---|
| 1177 | update_evalcall_form(0);
|
---|
| 1178 | }
|
---|
[1] | 1179 | }
|
---|
[128] | 1180 | close_evalcall_form();
|
---|
[1] | 1181 |
|
---|
[128] | 1182 | log_msg(3, "loading filelist");
|
---|
| 1183 | filelist = load_filelist(g_filelist_full);
|
---|
| 1184 | log_msg(3, "deleting original filelist");
|
---|
| 1185 | unlink(g_filelist_full);
|
---|
| 1186 | if (g_text_mode) {
|
---|
[3076] | 1187 | q = NULL;
|
---|
| 1188 | while (q == NULL) {
|
---|
| 1189 | printf("Restore which directory? --> ");
|
---|
[3193] | 1190 | mr_getline(q, stdin);
|
---|
[3076] | 1191 | }
|
---|
[3193] | 1192 | toggle_path_selection(filelist, q, TRUE);
|
---|
| 1193 | if (strlen(q) == 0) {
|
---|
[128] | 1194 | res = 1;
|
---|
| 1195 | } else {
|
---|
| 1196 | res = 0;
|
---|
| 1197 | }
|
---|
[3193] | 1198 | mr_free(q);
|
---|
[128] | 1199 | } else {
|
---|
| 1200 | res = edit_filelist(filelist);
|
---|
[1] | 1201 | }
|
---|
[128] | 1202 | if (res) {
|
---|
| 1203 | log_msg(2, "User hit 'cancel'. Freeing filelist and aborting.");
|
---|
| 1204 | free_filelist(filelist);
|
---|
| 1205 | return (NULL);
|
---|
| 1206 | }
|
---|
| 1207 | ask_about_these_imagedevs(g_filelist_imagedevs, g_imagedevs_restthese);
|
---|
| 1208 | close_evalcall_form();
|
---|
[1] | 1209 |
|
---|
[128] | 1210 | // NB: It's not necessary to add g_biggielist_txt to the filelist.full
|
---|
| 1211 | // file. The filelist.full file already contains the filename of EVERY
|
---|
| 1212 | // file backed up - regular and biggie files.
|
---|
[1] | 1213 |
|
---|
[128] | 1214 | // However, we do want to make sure the imagedevs selected by the user
|
---|
| 1215 | // are flagged for restoring.
|
---|
| 1216 | if (length_of_file(g_imagedevs_restthese) > 2) {
|
---|
| 1217 | add_list_of_files_to_filelist(filelist, g_imagedevs_restthese,
|
---|
| 1218 | TRUE);
|
---|
| 1219 | }
|
---|
[1] | 1220 |
|
---|
[128] | 1221 | return (filelist);
|
---|
| 1222 | }
|
---|
[1] | 1223 |
|
---|
| 1224 | /**************************************************************************
|
---|
| 1225 | *END_ PROCESS_FILELIST_AND_BIGGIELIST *
|
---|
| 1226 | **************************************************************************/
|
---|
| 1227 |
|
---|
| 1228 |
|
---|
| 1229 |
|
---|
| 1230 |
|
---|
| 1231 | /**
|
---|
| 1232 | * Make a backup copy of <tt>path_root</tt>/<tt>filename</tt>.
|
---|
| 1233 | * The backup filename is the filename of the original with ".pristine" added.
|
---|
| 1234 | * @param path_root The place where the filesystem is mounted (e.g. MNT_RESTORING).
|
---|
| 1235 | * @param filename The filename (absolute path) within @p path_root.
|
---|
| 1236 | * @return 0 for success, nonzero for failure.
|
---|
| 1237 | */
|
---|
[128] | 1238 | int backup_crucial_file(char *path_root, char *filename)
|
---|
[1] | 1239 | {
|
---|
[3193] | 1240 | char *tmp = NULL;
|
---|
| 1241 | char *command = NULL;
|
---|
[128] | 1242 | int res;
|
---|
[1] | 1243 |
|
---|
[128] | 1244 | assert(path_root != NULL);
|
---|
| 1245 | assert_string_is_neither_NULL_nor_zerolength(filename);
|
---|
| 1246 |
|
---|
[3193] | 1247 | mr_asprintf(tmp, "%s/%s", path_root, filename);
|
---|
| 1248 | mr_asprintf(command, "cp -f %s %s.pristine", tmp, tmp);
|
---|
| 1249 | mr_free(tmp);
|
---|
[128] | 1250 |
|
---|
| 1251 | res = run_program_and_log_output(command, 5);
|
---|
[3193] | 1252 | mr_free(command);
|
---|
[128] | 1253 | return (res);
|
---|
[1] | 1254 | }
|
---|
| 1255 |
|
---|
[2094] | 1256 | void offer_to_make_initrd() {
|
---|
[1] | 1257 |
|
---|
[2094] | 1258 | if (bkpinfo->restore_mode != nuke) {
|
---|
[2110] | 1259 | if (ask_me_yes_or_no
|
---|
| 1260 | ("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] | 1261 | log_msg(1,"Launching shell for manual initrd recreation");
|
---|
[2758] | 1262 | if (does_file_exist(MNT_RESTORING"/etc/arch-release")) {
|
---|
| 1263 | 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");
|
---|
| 1264 | } else {
|
---|
[3157] | 1265 | 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] | 1266 | }
|
---|
[2110] | 1267 | mvaddstr_and_log_it(g_currentY, 0, "Modifying initrd...");
|
---|
| 1268 | if (!g_text_mode) {
|
---|
| 1269 | newtSuspend();
|
---|
| 1270 | }
|
---|
[3076] | 1271 | paranoid_system("chroot " MNT_RESTORING);
|
---|
[2110] | 1272 | if (!g_text_mode) {
|
---|
| 1273 | newtResume();
|
---|
| 1274 | }
|
---|
| 1275 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
| 1276 | } else {
|
---|
[2094] | 1277 | return;
|
---|
| 1278 | }
|
---|
| 1279 | } else {
|
---|
| 1280 | log_to_screen("Non-interactive mode: no way to give you the keyboard so that you re-generate your initrd. Hope it's OK");
|
---|
| 1281 | log_msg(1,"Non-interactive mode: no way to give you the keyboard so that you re-generate your initrd. Hope it's OK");
|
---|
| 1282 | }
|
---|
| 1283 | }
|
---|
| 1284 |
|
---|
| 1285 |
|
---|
[1] | 1286 | /**
|
---|
| 1287 | * Install the user's boot loader in the MBR.
|
---|
| 1288 | * Currently LILO, ELILO, GRUB, RAW (dd of MBR), and the FreeBSD bootloader are supported.
|
---|
| 1289 | * @param offer_to_hack_scripts If TRUE, then offer to hack the user's fstab for them.
|
---|
| 1290 | * @return 0 for success, nonzero for failure.
|
---|
| 1291 | */
|
---|
[128] | 1292 | int run_boot_loader(bool offer_to_hack_scripts)
|
---|
[1] | 1293 | {
|
---|
[128] | 1294 | int res;
|
---|
| 1295 | int retval = 0;
|
---|
[1] | 1296 |
|
---|
| 1297 | /** malloc *******/
|
---|
[3193] | 1298 | char *device = NULL;
|
---|
[3746] | 1299 | char *disk = NULL;
|
---|
[3193] | 1300 | char *name = NULL;
|
---|
[3746] | 1301 | char *type = NULL;
|
---|
[1845] | 1302 | char *cmd = NULL;
|
---|
[1] | 1303 |
|
---|
[128] | 1304 | malloc_string(device);
|
---|
| 1305 | malloc_string(name);
|
---|
[3746] | 1306 | malloc_string(type);
|
---|
[1845] | 1307 |
|
---|
| 1308 | /* In order to have a working bootloader, we need to have all devices
|
---|
| 1309 | * ready in the chroot. If they are not there (udev) then copy them from
|
---|
| 1310 | * the current /dev location
|
---|
| 1311 | */
|
---|
[3185] | 1312 | mr_asprintf(cmd,"tar cf - /dev | ( cd %s ; tar xf - )",MNT_RESTORING);
|
---|
[1845] | 1313 | run_program_and_log_output(cmd, 3);
|
---|
[3746] | 1314 | mr_free(cmd);
|
---|
[1845] | 1315 |
|
---|
[128] | 1316 | backup_crucial_file(MNT_RESTORING, "/etc/fstab");
|
---|
[2095] | 1317 | backup_crucial_file(MNT_RESTORING, "/boot/grub/menu.lst");
|
---|
[2449] | 1318 | backup_crucial_file(MNT_RESTORING, "/boot/grub/grub.cfg");
|
---|
[2944] | 1319 | backup_crucial_file(MNT_RESTORING, "/boot/grub2/grub.cfg");
|
---|
[128] | 1320 | backup_crucial_file(MNT_RESTORING, "/etc/lilo.conf");
|
---|
| 1321 | backup_crucial_file(MNT_RESTORING, "/etc/elilo.conf");
|
---|
[1845] | 1322 | backup_crucial_file(MNT_RESTORING, "/boot/grub/device.map");
|
---|
[2944] | 1323 | backup_crucial_file(MNT_RESTORING, "/boot/grub2/device.map");
|
---|
[1845] | 1324 | backup_crucial_file(MNT_RESTORING, "/etc/mtab");
|
---|
[128] | 1325 | read_cfg_var(g_mondo_cfg_file, "bootloader.device", device);
|
---|
| 1326 | read_cfg_var(g_mondo_cfg_file, "bootloader.name", name);
|
---|
[3746] | 1327 | read_cfg_var(g_mondo_cfg_file, "boot-type", type);
|
---|
| 1328 | log_msg(2, "run_boot_loader: device='%s', name='%s', type='%s'", device, name, type);
|
---|
[3193] | 1329 | sync();
|
---|
[2094] | 1330 |
|
---|
| 1331 | offer_to_make_initrd();
|
---|
[3746] | 1332 |
|
---|
| 1333 | disk = truncate_to_drive_name(device);
|
---|
| 1334 | if (strcmp(type,"BIOS") == 0) {
|
---|
| 1335 | // Force installation of a MBR bootloader brought by mindi on the disk
|
---|
| 1336 | // in case none was available and we then start from a partition
|
---|
| 1337 | log_msg(2, "Reinstalling mbr.bin on %s", disk);
|
---|
| 1338 | mr_system("dd bs=440 count=1 conv=notrunc if=/tmp/mbr.bin of=%s &> /dev/null",disk);
|
---|
| 1339 | } else {
|
---|
| 1340 | // Same for GPT
|
---|
| 1341 | log_msg(2, "Reinstalling gptmbr.bin on %s", disk);
|
---|
| 1342 | mr_system("dd bs=440 count=1 conv=notrunc if=/tmp/gptmbr.bin of=%s &> /dev/null",disk);
|
---|
| 1343 | }
|
---|
| 1344 |
|
---|
| 1345 | // Now reinstall bootloader
|
---|
[128] | 1346 | if (!strcmp(name, "LILO")) {
|
---|
| 1347 | res = run_lilo(offer_to_hack_scripts);
|
---|
| 1348 | } else if (!strcmp(name, "ELILO")) {
|
---|
| 1349 | res = run_elilo(offer_to_hack_scripts);
|
---|
| 1350 | } else if (!strcmp(name, "GRUB")) {
|
---|
| 1351 | res = run_grub(offer_to_hack_scripts, device);
|
---|
| 1352 | } else if (!strcmp(name, "RAW")) {
|
---|
| 1353 | res = run_raw_mbr(offer_to_hack_scripts, device);
|
---|
| 1354 | }
|
---|
[1] | 1355 | #ifdef __FreeBSD__
|
---|
[128] | 1356 | else if (!strcmp(name, "BOOT0")) {
|
---|
[3185] | 1357 | mr_asprintf(tmp, "boot0cfg -B %s", device);
|
---|
[128] | 1358 | res = run_program_and_log_output(tmp, FALSE);
|
---|
[1873] | 1359 | paranoid_free(tmp);
|
---|
[128] | 1360 | } else {
|
---|
[3185] | 1361 | mr_asprintf(tmp, "ls /dev | grep -Eq '^%ss[1-4].*'", device);
|
---|
[128] | 1362 | if (!system(tmp)) {
|
---|
[3193] | 1363 | mr_free(tmp);
|
---|
[3185] | 1364 | mr_asprintf(tmp, MNT_RESTORING "/sbin/fdisk -B %s", device);
|
---|
[128] | 1365 | res = run_program_and_log_output(tmp, 3);
|
---|
| 1366 | } else {
|
---|
[3193] | 1367 | log_msg(1, "I'm not running any boot loader. You have a DD boot drive. It's already loaded up.");
|
---|
[128] | 1368 | }
|
---|
[3193] | 1369 | mr_free(tmp);
|
---|
[128] | 1370 | }
|
---|
[1] | 1371 | #else
|
---|
[128] | 1372 | else {
|
---|
| 1373 | log_to_screen
|
---|
[541] | 1374 | ("Unable to determine type of boot loader. Defaulting to LILO.");
|
---|
[128] | 1375 | res = run_lilo(offer_to_hack_scripts);
|
---|
| 1376 | }
|
---|
[1] | 1377 | #endif
|
---|
[128] | 1378 | retval += res;
|
---|
| 1379 | if (res) {
|
---|
[541] | 1380 | log_to_screen("Your boot loader returned an error");
|
---|
[128] | 1381 | } else {
|
---|
[541] | 1382 | log_to_screen("Your boot loader ran OK");
|
---|
[128] | 1383 | }
|
---|
| 1384 | paranoid_free(device);
|
---|
| 1385 | paranoid_free(name);
|
---|
| 1386 | return (retval);
|
---|
[1] | 1387 | }
|
---|
[128] | 1388 |
|
---|
[1] | 1389 | /**************************************************************************
|
---|
| 1390 | *END_ RUN_BOOT_LOADER *
|
---|
| 1391 | **************************************************************************/
|
---|
| 1392 |
|
---|
| 1393 |
|
---|
| 1394 |
|
---|
| 1395 | /**
|
---|
| 1396 | * Attempt to find the user's editor.
|
---|
| 1397 | * @return The editor found ("vi" if none could be found).
|
---|
[3866] | 1398 | * @note The returned string points to an allocated storage that needs to be freed by caller
|
---|
[1] | 1399 | */
|
---|
[3193] | 1400 | char *find_my_editor(void) {
|
---|
| 1401 |
|
---|
[3866] | 1402 | char *output = NULL ;
|
---|
| 1403 |
|
---|
| 1404 | if ((output = find_home_of_exe("pico")) == NULL) {
|
---|
| 1405 | if ((output = find_home_of_exe("nano")) == NULL) {
|
---|
| 1406 | if ((output = find_home_of_exe("e3em")) == NULL) {
|
---|
| 1407 | if ((output = find_home_of_exe("e3vi")) == NULL) {
|
---|
| 1408 | if ((output = find_home_of_exe("vim")) == NULL) {
|
---|
| 1409 | output = find_home_of_exe("vi");
|
---|
| 1410 | }
|
---|
| 1411 | }
|
---|
| 1412 | }
|
---|
| 1413 | }
|
---|
[128] | 1414 | }
|
---|
[3866] | 1415 | if (output == NULL) {
|
---|
| 1416 | log_msg(2, " (find_my_editor) --- warning - no editor found, even vi");
|
---|
[128] | 1417 | }
|
---|
| 1418 | return (output);
|
---|
[1] | 1419 | }
|
---|
| 1420 |
|
---|
| 1421 |
|
---|
| 1422 | /**
|
---|
| 1423 | * Install GRUB on @p bd.
|
---|
| 1424 | * @param offer_to_run_stabgrub If TRUE, then offer to hack the user's fstab for them.
|
---|
| 1425 | * @param bd The boot device where GRUB is installed.
|
---|
| 1426 | * @return 0 for success, nonzero for failure.
|
---|
| 1427 | */
|
---|
[128] | 1428 | int run_grub(bool offer_to_run_stabgrub, char *bd)
|
---|
[1] | 1429 | {
|
---|
| 1430 | /** malloc **/
|
---|
[3193] | 1431 | char *command = NULL;
|
---|
| 1432 | char *boot_device = NULL;
|
---|
| 1433 | char *tmp = NULL;
|
---|
| 1434 | char *editor = NULL;
|
---|
[1] | 1435 |
|
---|
[3193] | 1436 | bool done;
|
---|
[2950] | 1437 | int res = 0; /* FALSE */
|
---|
| 1438 | bool mntlistchg = FALSE;
|
---|
| 1439 | FILE *fin = NULL;
|
---|
[1] | 1440 |
|
---|
[128] | 1441 | malloc_string(boot_device);
|
---|
[3193] | 1442 |
|
---|
[128] | 1443 | assert_string_is_neither_NULL_nor_zerolength(bd);
|
---|
| 1444 | strcpy(boot_device, bd);
|
---|
| 1445 |
|
---|
[3297] | 1446 | if (offer_to_run_stabgrub && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?")) {
|
---|
[128] | 1447 | /* interactive mode */
|
---|
[3297] | 1448 | mvaddstr_and_log_it(g_currentY, 0, "Modifying fstab, mtab, device.map and menu.lst/grub.cfg, and running GRUB...");
|
---|
[2950] | 1449 | /* Did we changed the mountlist ? If yes, then force editing conf files */
|
---|
| 1450 | if ((fin = fopen(MONDO_MNTLISTCHG, "r")) != NULL) {
|
---|
| 1451 | mntlistchg = TRUE;
|
---|
| 1452 | }
|
---|
[128] | 1453 | for (done = FALSE; !done;) {
|
---|
[3297] | 1454 | 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] | 1455 | /* Only try to adapt grub here first if the mountlist wasn't changed before */
|
---|
| 1456 | if (! mntlistchg) {
|
---|
[3542] | 1457 | mr_asprintf(command, "mr-stabgrub-me %s", boot_device);
|
---|
[2950] | 1458 | res = run_program_and_log_output(command, 1);
|
---|
[3193] | 1459 | mr_free(command);
|
---|
[2950] | 1460 | }
|
---|
[3193] | 1461 |
|
---|
| 1462 | if ((res) || (mntlistchg)) {
|
---|
[2950] | 1463 | if (res) {
|
---|
| 1464 | 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");
|
---|
| 1465 | } else {
|
---|
| 1466 | 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");
|
---|
| 1467 | }
|
---|
[3866] | 1468 | editor = find_my_editor());
|
---|
| 1469 | if (editor == NULL) {
|
---|
| 1470 | popup_and_OK("No editor found. You won't be able to edit conf files");
|
---|
| 1471 | } else {
|
---|
| 1472 | if (!g_text_mode) {
|
---|
| 1473 | newtSuspend();
|
---|
| 1474 | }
|
---|
| 1475 | mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
|
---|
| 1476 | paranoid_system(tmp);
|
---|
| 1477 | mr_free(tmp);
|
---|
[3193] | 1478 |
|
---|
[3866] | 1479 | mr_asprintf(tmp, "chroot %s %s /etc/mtab", MNT_RESTORING, editor);
|
---|
| 1480 | paranoid_system(tmp);
|
---|
| 1481 | mr_free(tmp);
|
---|
| 1482 |
|
---|
| 1483 | if (does_file_exist(MNT_RESTORING"/boot/grub/menu.lst")) {
|
---|
| 1484 | mr_asprintf(tmp, "chroot %s %s /boot/grub/menu.lst", MNT_RESTORING, editor);
|
---|
| 1485 | } else if (does_file_exist(MNT_RESTORING"/boot/grub/grub.cfg")) {
|
---|
| 1486 | mr_asprintf(tmp, "chroot %s %s /boot/grub/grub.cfg", MNT_RESTORING, editor);
|
---|
| 1487 | } else if (does_file_exist(MNT_RESTORING"/boot/grub2/grub.cfg")) {
|
---|
| 1488 | mr_asprintf(tmp, "chroot %s %s /boot/grub2/grub.cfg", MNT_RESTORING, editor);
|
---|
| 1489 | }
|
---|
| 1490 | paranoid_system(tmp);
|
---|
| 1491 | mr_free(tmp);
|
---|
| 1492 |
|
---|
| 1493 | if (does_file_exist(MNT_RESTORING"/boot/grub/device.map")) {
|
---|
| 1494 | mr_asprintf(tmp, "chroot %s %s /boot/grub/device.map", MNT_RESTORING, editor);
|
---|
| 1495 | } else if (does_file_exist(MNT_RESTORING"/boot/grub2/device.map")) {
|
---|
| 1496 | mr_asprintf(tmp, "chroot %s %s /boot/grub2/device.map", MNT_RESTORING, editor);
|
---|
| 1497 | }
|
---|
| 1498 | paranoid_system(tmp);
|
---|
| 1499 | mr_free(tmp);
|
---|
| 1500 | if (!g_text_mode) {
|
---|
| 1501 | newtResume();
|
---|
| 1502 | }
|
---|
[2904] | 1503 | }
|
---|
[3193] | 1504 | mr_free(editor);
|
---|
| 1505 |
|
---|
[3542] | 1506 | mr_asprintf(command, "mr-stabgrub-me %s", boot_device);
|
---|
[2904] | 1507 | res = run_program_and_log_output(command, 1);
|
---|
[3193] | 1508 | mr_free(command);
|
---|
| 1509 |
|
---|
[2904] | 1510 | if (res) {
|
---|
[3193] | 1511 | 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] | 1512 | newtSuspend();
|
---|
[3076] | 1513 | paranoid_system("chroot " MNT_RESTORING);
|
---|
[2904] | 1514 | newtResume();
|
---|
| 1515 | } else {
|
---|
| 1516 | popup_and_OK("GRUB is now installed correctly");
|
---|
| 1517 | done = TRUE;
|
---|
| 1518 | }
|
---|
[128] | 1519 | } else {
|
---|
| 1520 | done = TRUE;
|
---|
| 1521 | }
|
---|
| 1522 | }
|
---|
[3193] | 1523 | } else {
|
---|
[128] | 1524 | /* nuke mode */
|
---|
[3542] | 1525 | if (!run_program_and_log_output("which mr-grub", FALSE)) {
|
---|
| 1526 | log_msg(1, "Yay! mr-grub found...");
|
---|
| 1527 | mr_asprintf(command, "mr-grub %s /"MOUNTLIST_FNAME_STUB, boot_device);
|
---|
[3193] | 1528 | log_msg(1, "command = %s", command);
|
---|
| 1529 | } else {
|
---|
[3297] | 1530 | // Or grub2-install
|
---|
[3193] | 1531 | mr_asprintf(command, "chroot " MNT_RESTORING " grub-install %s", boot_device);
|
---|
[3542] | 1532 | log_msg(1, "WARNING - mr-grub not found; using grub-install");
|
---|
[3193] | 1533 | }
|
---|
| 1534 | mvaddstr_and_log_it(g_currentY, 0, "Running GRUB... ");
|
---|
[2227] | 1535 | log_it("%s",command);
|
---|
[128] | 1536 | res = run_program_and_log_output(command, 1);
|
---|
[3193] | 1537 | mr_free(command);
|
---|
| 1538 |
|
---|
[128] | 1539 | if (res) {
|
---|
[3299] | 1540 | 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] | 1541 | newtSuspend();
|
---|
[3076] | 1542 | paranoid_system("chroot " MNT_RESTORING);
|
---|
[128] | 1543 | newtResume();
|
---|
| 1544 | }
|
---|
[1] | 1545 | }
|
---|
[128] | 1546 | if (res) {
|
---|
[541] | 1547 | mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
|
---|
[128] | 1548 | log_to_screen
|
---|
[1315] | 1549 | ("GRUB ran w/error(s). See %s for more info.", MONDO_LOGFILE);
|
---|
[128] | 1550 | log_msg(1, "Type:-");
|
---|
[3542] | 1551 | log_msg(1, " mr-mount-me");
|
---|
[128] | 1552 | log_msg(1, " chroot " MNT_RESTORING);
|
---|
[3707] | 1553 | log_msg(1, " mount /boot if needed");
|
---|
[128] | 1554 | log_msg(1, " grub-install '(hd0)'");
|
---|
| 1555 | log_msg(1, " exit");
|
---|
[3542] | 1556 | log_msg(1, " mr-unmount-me");
|
---|
[128] | 1557 | log_msg(1,
|
---|
| 1558 | "If you're really stuck, please e-mail the mailing list.");
|
---|
| 1559 | } else {
|
---|
[541] | 1560 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
[128] | 1561 | }
|
---|
| 1562 | paranoid_free(boot_device);
|
---|
[1] | 1563 |
|
---|
[128] | 1564 | return (res);
|
---|
[1] | 1565 | }
|
---|
[128] | 1566 |
|
---|
[1] | 1567 | /**************************************************************************
|
---|
| 1568 | *END_RUN_GRUB *
|
---|
| 1569 | **************************************************************************/
|
---|
| 1570 |
|
---|
| 1571 |
|
---|
| 1572 | /**
|
---|
| 1573 | * Install ELILO on the user's boot drive (determined by elilo.conf).
|
---|
| 1574 | * @param offer_to_run_stabelilo If TRUE, then offer to hack the user's fstab for them.
|
---|
| 1575 | * @return 0 for success, nonzero for failure.
|
---|
| 1576 | */
|
---|
[128] | 1577 | int run_elilo(bool offer_to_run_stabelilo)
|
---|
[1] | 1578 | {
|
---|
| 1579 | /** malloc **/
|
---|
[3193] | 1580 | char *command = NULL;
|
---|
| 1581 | char *tmp = NULL;
|
---|
| 1582 | char *editor = NULL;
|
---|
[1] | 1583 |
|
---|
[128] | 1584 | int res;
|
---|
| 1585 | int done;
|
---|
[1] | 1586 |
|
---|
[128] | 1587 | if (offer_to_run_stabelilo
|
---|
[2094] | 1588 | && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?"))
|
---|
[1] | 1589 |
|
---|
[128] | 1590 | /* interactive mode */
|
---|
| 1591 | {
|
---|
| 1592 | mvaddstr_and_log_it(g_currentY,
|
---|
| 1593 | 0,
|
---|
[541] | 1594 | "Modifying fstab and elilo.conf... ");
|
---|
[3542] | 1595 | mr_asprintf(command, "mr-stabelilo-me");
|
---|
[128] | 1596 | res = run_program_and_log_output(command, 3);
|
---|
[3193] | 1597 | mr_free(command);
|
---|
| 1598 |
|
---|
[128] | 1599 | if (res) {
|
---|
[3866] | 1600 | popup_and_OK("You will now edit fstab and elilo.conf, to make sure they match your new mountlist.");
|
---|
[128] | 1601 | for (done = FALSE; !done;) {
|
---|
[3866] | 1602 | editor = find_my_editor();
|
---|
| 1603 | if (editor == NULL) {
|
---|
| 1604 | popup_and_OK("No editor found. You won't be able to edit conf files");
|
---|
| 1605 | done = TRUE;
|
---|
| 1606 | } else {
|
---|
[3193] | 1607 |
|
---|
[3866] | 1608 | if (!g_text_mode) {
|
---|
| 1609 | newtSuspend();
|
---|
| 1610 | }
|
---|
| 1611 | mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
|
---|
| 1612 | paranoid_system(tmp);
|
---|
| 1613 | mr_free(tmp);
|
---|
| 1614 |
|
---|
| 1615 | mr_asprintf(tmp, "chroot %s %s /etc/elilo.conf", MNT_RESTORING, editor);
|
---|
| 1616 | paranoid_system(tmp);
|
---|
| 1617 | mr_free(tmp);
|
---|
| 1618 | mr_free(editor);
|
---|
[3193] | 1619 |
|
---|
[3866] | 1620 | if (!g_text_mode) {
|
---|
| 1621 | newtResume();
|
---|
| 1622 | }
|
---|
[1] | 1623 | // newtCls();
|
---|
[3866] | 1624 | if (ask_me_yes_or_no("Edit them again?")) {
|
---|
| 1625 | continue;
|
---|
| 1626 | }
|
---|
| 1627 | done = TRUE;
|
---|
[128] | 1628 | }
|
---|
[3866] | 1629 | mr_free(editor);
|
---|
[128] | 1630 | }
|
---|
| 1631 | } else {
|
---|
[541] | 1632 | log_to_screen("elilo.conf and fstab were modified OK");
|
---|
[1] | 1633 | }
|
---|
[128] | 1634 | } else
|
---|
| 1635 | /* nuke mode */
|
---|
[1] | 1636 | {
|
---|
[128] | 1637 | res = TRUE;
|
---|
[1] | 1638 | }
|
---|
[128] | 1639 | return (res);
|
---|
| 1640 | }
|
---|
[1] | 1641 |
|
---|
| 1642 | /**************************************************************************
|
---|
| 1643 | *END_RUN_ELILO *
|
---|
| 1644 | **************************************************************************/
|
---|
| 1645 |
|
---|
| 1646 |
|
---|
| 1647 | /**
|
---|
| 1648 | * Install LILO on the user's boot drive (determined by /etc/lilo.conf).
|
---|
| 1649 | * @param offer_to_run_stablilo If TRUE, then offer to hack the user's fstab for them.
|
---|
| 1650 | * @return 0 for success, nonzero for failure.
|
---|
| 1651 | */
|
---|
[128] | 1652 | int run_lilo(bool offer_to_run_stablilo)
|
---|
[1] | 1653 | {
|
---|
| 1654 | /** malloc **/
|
---|
[3193] | 1655 | char *command = NULL;
|
---|
| 1656 | char *tmp = NULL;
|
---|
| 1657 | char *editor = NULL;
|
---|
[1] | 1658 |
|
---|
[128] | 1659 | int res;
|
---|
| 1660 | int done;
|
---|
| 1661 | bool run_lilo_M = FALSE;
|
---|
[1] | 1662 |
|
---|
[128] | 1663 | if (!run_program_and_log_output
|
---|
| 1664 | ("grep \"boot.*=.*/dev/md\" " MNT_RESTORING "/etc/lilo.conf", 1)) {
|
---|
| 1665 | run_lilo_M = TRUE;
|
---|
| 1666 | }
|
---|
[1] | 1667 |
|
---|
[128] | 1668 | if (offer_to_run_stablilo
|
---|
[2094] | 1669 | && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?"))
|
---|
[1] | 1670 |
|
---|
[128] | 1671 | /* interactive mode */
|
---|
| 1672 | {
|
---|
| 1673 | mvaddstr_and_log_it(g_currentY,
|
---|
| 1674 | 0,
|
---|
[541] | 1675 | "Modifying fstab and lilo.conf, and running LILO... ");
|
---|
[3542] | 1676 | mr_asprintf(command, "mr-stablilo-me");
|
---|
[128] | 1677 | res = run_program_and_log_output(command, 3);
|
---|
[3193] | 1678 | mr_free(command);
|
---|
| 1679 |
|
---|
[128] | 1680 | if (res) {
|
---|
| 1681 | popup_and_OK
|
---|
[541] | 1682 | ("You will now edit fstab and lilo.conf, to make sure they match your new mountlist.");
|
---|
[128] | 1683 | for (done = FALSE; !done;) {
|
---|
[3866] | 1684 | editor = find_my_editor();
|
---|
| 1685 | if (editor == NULL) {
|
---|
| 1686 | popup_and_OK("No editor found. You won't be able to edit conf files");
|
---|
| 1687 | } else {
|
---|
| 1688 | if (!g_text_mode) {
|
---|
| 1689 | newtSuspend();
|
---|
| 1690 | }
|
---|
| 1691 | mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
|
---|
| 1692 | paranoid_system(tmp);
|
---|
| 1693 | mr_free(tmp);
|
---|
| 1694 |
|
---|
| 1695 | mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor);
|
---|
| 1696 | paranoid_system(tmp);
|
---|
| 1697 | mr_free(tmp);
|
---|
| 1698 | mr_free(editor);
|
---|
| 1699 |
|
---|
| 1700 | if (!g_text_mode) {
|
---|
| 1701 | newtResume();
|
---|
| 1702 | }
|
---|
| 1703 | // newtCls();
|
---|
| 1704 | if (ask_me_yes_or_no("Edit them again?")) {
|
---|
| 1705 | continue;
|
---|
| 1706 | }
|
---|
[128] | 1707 | }
|
---|
[3193] | 1708 | mr_free(editor);
|
---|
| 1709 |
|
---|
[3866] | 1710 | res = run_program_and_log_output("chroot " MNT_RESTORING " lilo -L", 3);
|
---|
[128] | 1711 | if (res) {
|
---|
[3866] | 1712 | res = run_program_and_log_output("chroot " MNT_RESTORING " lilo", 3);
|
---|
[128] | 1713 | }
|
---|
| 1714 | if (res) {
|
---|
[3866] | 1715 | done = ask_me_yes_or_no("LILO failed. Re-edit system files?");
|
---|
[128] | 1716 | } else {
|
---|
| 1717 | done = TRUE;
|
---|
| 1718 | }
|
---|
| 1719 | }
|
---|
| 1720 | } else {
|
---|
[541] | 1721 | log_to_screen("lilo.conf and fstab were modified OK");
|
---|
[1] | 1722 | }
|
---|
[128] | 1723 | } else
|
---|
| 1724 | /* nuke mode */
|
---|
| 1725 | {
|
---|
| 1726 | mvaddstr_and_log_it(g_currentY,
|
---|
| 1727 | 0,
|
---|
[541] | 1728 | "Running LILO... ");
|
---|
[128] | 1729 | res =
|
---|
| 1730 | run_program_and_log_output("chroot " MNT_RESTORING " lilo -L",
|
---|
| 1731 | 3);
|
---|
| 1732 | if (res) {
|
---|
| 1733 | res =
|
---|
| 1734 | run_program_and_log_output("chroot " MNT_RESTORING " lilo",
|
---|
| 1735 | 3);
|
---|
[1] | 1736 | }
|
---|
[128] | 1737 | if (res) {
|
---|
[541] | 1738 | mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
|
---|
[128] | 1739 | log_to_screen
|
---|
[541] | 1740 | ("Failed to re-jig fstab and/or lilo. Edit/run manually, please.");
|
---|
[128] | 1741 | } else {
|
---|
[541] | 1742 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
[128] | 1743 | }
|
---|
[1] | 1744 | }
|
---|
[128] | 1745 | if (run_lilo_M) {
|
---|
| 1746 | run_program_and_log_output("chroot " MNT_RESTORING
|
---|
| 1747 | " lilo -M /dev/hda", 3);
|
---|
| 1748 | run_program_and_log_output("chroot " MNT_RESTORING
|
---|
| 1749 | " lilo -M /dev/sda", 3);
|
---|
[1] | 1750 | }
|
---|
[128] | 1751 | return (res);
|
---|
| 1752 | }
|
---|
[1] | 1753 |
|
---|
| 1754 | /**************************************************************************
|
---|
| 1755 | *END_RUN_LILO *
|
---|
| 1756 | **************************************************************************/
|
---|
| 1757 |
|
---|
| 1758 |
|
---|
| 1759 | /**
|
---|
| 1760 | * Install a raw MBR onto @p bd.
|
---|
| 1761 | * @param offer_to_hack_scripts If TRUE, then offer to hack the user's fstab for them.
|
---|
| 1762 | * @param bd The device to copy the stored MBR to.
|
---|
| 1763 | * @return 0 for success, nonzero for failure.
|
---|
| 1764 | */
|
---|
[128] | 1765 | int run_raw_mbr(bool offer_to_hack_scripts, char *bd)
|
---|
[1] | 1766 | {
|
---|
| 1767 | /** malloc **/
|
---|
[3193] | 1768 | char *command = NULL;
|
---|
| 1769 | char *boot_device = NULL;
|
---|
| 1770 | char *tmp = NULL;
|
---|
[128] | 1771 | char *editor;
|
---|
| 1772 | int res;
|
---|
| 1773 | int done;
|
---|
[1] | 1774 |
|
---|
[128] | 1775 | malloc_string(boot_device);
|
---|
| 1776 | assert_string_is_neither_NULL_nor_zerolength(bd);
|
---|
[1] | 1777 |
|
---|
[128] | 1778 | strcpy(boot_device, bd);
|
---|
[1] | 1779 |
|
---|
[128] | 1780 | if (offer_to_hack_scripts
|
---|
[3193] | 1781 | && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?")) {
|
---|
[128] | 1782 | /* interactive mode */
|
---|
[3383] | 1783 | mvaddstr_and_log_it(g_currentY, 0, "Modifying fstab and restoring MBR... ");
|
---|
[128] | 1784 | for (done = FALSE; !done;) {
|
---|
[3866] | 1785 | popup_and_OK("You will now edit fstab");
|
---|
| 1786 | editor = find_my_editor());
|
---|
| 1787 | if (editor == NULL) {
|
---|
| 1788 | popup_and_OK("No editor found. You won't be able to edit conf files");
|
---|
| 1789 | } else {
|
---|
[128] | 1790 | if (!g_text_mode) {
|
---|
| 1791 | newtSuspend();
|
---|
| 1792 | }
|
---|
[3193] | 1793 | mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
|
---|
| 1794 |
|
---|
[128] | 1795 | paranoid_system(tmp);
|
---|
[3193] | 1796 | mr_free(tmp);
|
---|
[128] | 1797 | if (!g_text_mode) {
|
---|
| 1798 | newtResume();
|
---|
| 1799 | }
|
---|
| 1800 | }
|
---|
[3866] | 1801 | mr_free(editor);
|
---|
| 1802 |
|
---|
[3193] | 1803 | 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] | 1804 | mr_asprintf(command, "mr-stabraw-me %s", boot_device);
|
---|
[128] | 1805 | res = run_program_and_log_output(command, 3);
|
---|
[3193] | 1806 | mr_free(command);
|
---|
| 1807 |
|
---|
[128] | 1808 | if (res) {
|
---|
[541] | 1809 | done = ask_me_yes_or_no("Modifications failed. Re-try?");
|
---|
[128] | 1810 | } else {
|
---|
| 1811 | done = TRUE;
|
---|
| 1812 | }
|
---|
| 1813 | }
|
---|
[3193] | 1814 | } else {
|
---|
[128] | 1815 | /* nuke mode */
|
---|
[3542] | 1816 | mr_asprintf(command, "mr-raw %s /"MOUNTLIST_FNAME_STUB, boot_device);
|
---|
[3193] | 1817 | log_msg(2, "run_raw_mbr() --- command='%s'", command);
|
---|
| 1818 |
|
---|
[3383] | 1819 | mvaddstr_and_log_it(g_currentY, 0, "Restoring MBR... ");
|
---|
[128] | 1820 | res = run_program_and_log_output(command, 3);
|
---|
[3193] | 1821 | mr_free(command);
|
---|
[1] | 1822 | }
|
---|
[128] | 1823 | if (res) {
|
---|
[541] | 1824 | mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
|
---|
[3383] | 1825 | log_to_screen("MBR+fstab processed w/error(s). See %s for more info.", MONDO_LOGFILE);
|
---|
[128] | 1826 | } else {
|
---|
[541] | 1827 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
[128] | 1828 | }
|
---|
| 1829 | paranoid_free(boot_device);
|
---|
| 1830 | return (res);
|
---|
[1] | 1831 | }
|
---|
[128] | 1832 |
|
---|
[1] | 1833 | /**************************************************************************
|
---|
| 1834 | *END_RUN_RAW_MBR *
|
---|
| 1835 | **************************************************************************/
|
---|
| 1836 |
|
---|
| 1837 |
|
---|
| 1838 |
|
---|
| 1839 | /**
|
---|
| 1840 | * malloc() and set sensible defaults for the mondorestore filename variables.
|
---|
| 1841 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 1842 | * - @c bkpinfo->tmpdir
|
---|
| 1843 | * - @c bkpinfo->disaster_recovery
|
---|
| 1844 | */
|
---|
[1645] | 1845 | void setup_MR_global_filenames()
|
---|
[1] | 1846 | {
|
---|
[128] | 1847 | assert(bkpinfo != NULL);
|
---|
[1] | 1848 |
|
---|
[128] | 1849 | malloc_string(g_biggielist_txt);
|
---|
| 1850 | malloc_string(g_filelist_full);
|
---|
| 1851 | malloc_string(g_filelist_imagedevs);
|
---|
| 1852 | malloc_string(g_imagedevs_restthese);
|
---|
| 1853 | malloc_string(g_mondo_cfg_file);
|
---|
| 1854 | malloc_string(g_mountlist_fname);
|
---|
| 1855 | malloc_string(g_mondo_home);
|
---|
| 1856 | malloc_string(g_isodir_device);
|
---|
| 1857 | malloc_string(g_isodir_format);
|
---|
[1] | 1858 |
|
---|
[3833] | 1859 | sprintf(g_biggielist_txt, "%s/%s", bkpinfo->tmpdir, BIGGIELIST_TXT_STUB);
|
---|
| 1860 | sprintf(g_filelist_full, "%s/%s", bkpinfo->tmpdir, FILELIST_FULL_STUB);
|
---|
| 1861 | sprintf(g_filelist_imagedevs, "%s/tmp/filelist.imagedevs", bkpinfo->tmpdir);
|
---|
| 1862 | // sprintf(g_imagedevs_pot, "%s/tmp/imagedevs.pot", bkpinfo->tmpdir);
|
---|
[128] | 1863 | sprintf(g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these",
|
---|
[3833] | 1864 | bkpinfo->tmpdir);
|
---|
[128] | 1865 | if (bkpinfo->disaster_recovery) {
|
---|
| 1866 | sprintf(g_mondo_cfg_file, "/%s", MONDO_CFG_FILE_STUB);
|
---|
| 1867 | sprintf(g_mountlist_fname, "/%s", MOUNTLIST_FNAME_STUB);
|
---|
| 1868 | } else {
|
---|
[3833] | 1869 | sprintf(g_mondo_cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB);
|
---|
| 1870 | sprintf(g_mountlist_fname, "%s/%s", bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
|
---|
[128] | 1871 | }
|
---|
[1] | 1872 | }
|
---|
[128] | 1873 |
|
---|
[1] | 1874 | /**************************************************************************
|
---|
| 1875 | *END_SET_GLOBAL_FILENAME *
|
---|
| 1876 | **************************************************************************/
|
---|
| 1877 |
|
---|
| 1878 |
|
---|
| 1879 | /**
|
---|
| 1880 | * Copy @p input_file (containing the result of a compare) to @p output_file,
|
---|
| 1881 | * deleting spurious "changes" along the way.
|
---|
| 1882 | * @param output_file The output file to write with spurious changes removed.
|
---|
| 1883 | * @param input_file The input file, a list of changed files created by a compare.
|
---|
| 1884 | */
|
---|
[128] | 1885 | void streamline_changes_file(char *output_file, char *input_file)
|
---|
[1] | 1886 | {
|
---|
[128] | 1887 | FILE *fin;
|
---|
| 1888 | FILE *fout;
|
---|
[3193] | 1889 | char *incoming = NULL;
|
---|
[1] | 1890 |
|
---|
[128] | 1891 | assert_string_is_neither_NULL_nor_zerolength(output_file);
|
---|
| 1892 | assert_string_is_neither_NULL_nor_zerolength(input_file);
|
---|
| 1893 |
|
---|
| 1894 | if (!(fin = fopen(input_file, "r"))) {
|
---|
| 1895 | log_OS_error(input_file);
|
---|
| 1896 | return;
|
---|
| 1897 | }
|
---|
| 1898 | if (!(fout = fopen(output_file, "w"))) {
|
---|
| 1899 | fatal_error("cannot open output_file");
|
---|
| 1900 | }
|
---|
[3193] | 1901 | for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
|
---|
[128] | 1902 | if (strncmp(incoming, "etc/adjtime", 11)
|
---|
| 1903 | && strncmp(incoming, "etc/mtab", 8)
|
---|
| 1904 | && strncmp(incoming, "tmp/", 4)
|
---|
| 1905 | && strncmp(incoming, "boot/map", 8)
|
---|
| 1906 | && !strstr(incoming, "incheckentry")
|
---|
| 1907 | && strncmp(incoming, "etc/mail/statistics", 19)
|
---|
| 1908 | && strncmp(incoming, "var/", 4))
|
---|
| 1909 | fprintf(fout, "%s", incoming); /* don't need \n here, for some reason.. */
|
---|
[3193] | 1910 | mr_free(incoming);
|
---|
[128] | 1911 | }
|
---|
[3193] | 1912 | mr_free(incoming);
|
---|
[128] | 1913 | paranoid_fclose(fout);
|
---|
| 1914 | paranoid_fclose(fin);
|
---|
[1] | 1915 | }
|
---|
[128] | 1916 |
|
---|
[1] | 1917 | /**************************************************************************
|
---|
| 1918 | *END_STREAMLINE_CHANGES_FILE *
|
---|
| 1919 | **************************************************************************/
|
---|
| 1920 |
|
---|
| 1921 |
|
---|
| 1922 | /**
|
---|
| 1923 | * Give the user twenty seconds to press Ctrl-Alt-Del before we nuke their drives.
|
---|
| 1924 | */
|
---|
[128] | 1925 | void twenty_seconds_til_yikes()
|
---|
[1] | 1926 | {
|
---|
[128] | 1927 | int i;
|
---|
| 1928 | /* MALLOC * */
|
---|
[3193] | 1929 | char *tmp = NULL;
|
---|
[1] | 1930 |
|
---|
[128] | 1931 | if (does_file_exist("/tmp/NOPAUSE")) {
|
---|
| 1932 | return;
|
---|
| 1933 | }
|
---|
[541] | 1934 | open_progress_form("CAUTION",
|
---|
| 1935 | "Be advised: I am about to ERASE your hard disk(s)!",
|
---|
| 1936 | "You may press Ctrl+Alt+Del to abort safely.",
|
---|
[128] | 1937 | "", 20);
|
---|
| 1938 | for (i = 0; i < 20; i++) {
|
---|
| 1939 | g_current_progress = i;
|
---|
[3193] | 1940 | mr_asprintf(tmp, "You have %d seconds left to abort.", 20 - i);
|
---|
[128] | 1941 | update_progress_form(tmp);
|
---|
[3193] | 1942 | mr_free(tmp);
|
---|
[128] | 1943 | sleep(1);
|
---|
| 1944 | }
|
---|
| 1945 | close_progress_form();
|
---|
[1] | 1946 | }
|
---|
[128] | 1947 |
|
---|
[1] | 1948 | /**************************************************************************
|
---|
| 1949 | *END_TWENTY_SECONDS_TIL_YIKES *
|
---|
| 1950 | **************************************************************************/
|
---|
| 1951 |
|
---|
| 1952 |
|
---|
| 1953 | /**
|
---|
| 1954 | * Unmount all devices in @p p_external_copy_of_mountlist.
|
---|
| 1955 | * @param p_external_copy_of_mountlist The mountlist to guide the devices to unmount.
|
---|
| 1956 | * @return 0 for success, nonzero for failure.
|
---|
| 1957 | */
|
---|
[128] | 1958 | int unmount_all_devices(struct mountlist_itself
|
---|
| 1959 | *p_external_copy_of_mountlist)
|
---|
[1] | 1960 | {
|
---|
[128] | 1961 | struct mountlist_itself *mountlist;
|
---|
| 1962 | int retval = 0, lino, res = 0, i;
|
---|
[3193] | 1963 | char *command = NULL;
|
---|
[2211] | 1964 | char *tmp = NULL;
|
---|
[1] | 1965 |
|
---|
[128] | 1966 | assert(p_external_copy_of_mountlist != NULL);
|
---|
[1] | 1967 |
|
---|
[128] | 1968 | mountlist = malloc(sizeof(struct mountlist_itself));
|
---|
[3301] | 1969 | memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist, sizeof(struct mountlist_itself));
|
---|
[128] | 1970 | sort_mountlist_by_mountpoint(mountlist, 0);
|
---|
[1] | 1971 |
|
---|
[3600] | 1972 | run_program_and_log_output("df -m -P -T", 3);
|
---|
[541] | 1973 | mvaddstr_and_log_it(g_currentY, 0, "Unmounting devices ");
|
---|
[3301] | 1974 | open_progress_form("Unmounting devices", "Unmounting all devices that were mounted,", "in preparation for the post-restoration reboot.", "", mountlist->entries);
|
---|
[3076] | 1975 | if (chdir("/")) {
|
---|
| 1976 | // FIXME
|
---|
| 1977 | }
|
---|
[3301] | 1978 | for (i = 0; i < 10 && run_program_and_log_output("ps | grep buffer | grep -v \"grep buffer\"", TRUE) == 0; i++) {
|
---|
[128] | 1979 | sleep(1);
|
---|
| 1980 | log_msg(2, "Waiting for buffer() to finish");
|
---|
| 1981 | }
|
---|
[1] | 1982 |
|
---|
[3193] | 1983 | sync();
|
---|
[1] | 1984 |
|
---|
[3544] | 1985 | /* after that what is logged is not copied on disk, typically the result of labelling */
|
---|
[3185] | 1986 | mr_asprintf(tmp, "cp -f %s " MNT_RESTORING "/var/log", MONDO_LOGFILE);
|
---|
[1322] | 1987 | if (run_program_and_log_output(tmp, FALSE)) {
|
---|
[3653] | 1988 | log_msg(1, "Error. Failed to copy log to the machine's /var/log dir. (Mounted read-only?)");
|
---|
[1] | 1989 | }
|
---|
[2211] | 1990 | paranoid_free(tmp);
|
---|
[128] | 1991 | if (does_file_exist("/tmp/DUMBASS-GENTOO")) {
|
---|
[3301] | 1992 | run_program_and_log_output("mkdir -p " MNT_RESTORING "/mnt/.boot.d", 5);
|
---|
[1] | 1993 | }
|
---|
[1971] | 1994 |
|
---|
| 1995 | /* Unmounting the local /proc and /sys first */
|
---|
[3193] | 1996 | run_program_and_log_output("umount -d " MNT_RESTORING "/proc",3);
|
---|
| 1997 | run_program_and_log_output("umount -d " MNT_RESTORING "/sys",3);
|
---|
[1971] | 1998 |
|
---|
[3734] | 1999 | /* Unmounting potential btrfs subvolumes */
|
---|
| 2000 | if (does_file_exist("/tmp/umount-btrfs-subvol")) {
|
---|
| 2001 | run_program_and_log_output("/tmp/umount-btrfs-subvol",3);
|
---|
| 2002 | }
|
---|
| 2003 |
|
---|
[128] | 2004 | for (lino = mountlist->entries - 1; lino >= 0; lino--) {
|
---|
| 2005 | if (!strcmp(mountlist->el[lino].mountpoint, "lvm")) {
|
---|
| 2006 | continue;
|
---|
| 2007 | }
|
---|
[3185] | 2008 | mr_asprintf(tmp, "Unmounting device %s ", mountlist->el[lino].device);
|
---|
[128] | 2009 | update_progress_form(tmp);
|
---|
[2211] | 2010 |
|
---|
[3439] | 2011 | //TODO: this should be done in a certain order normally if there are cascading mount
|
---|
[128] | 2012 | if (is_this_device_mounted(mountlist->el[lino].device)) {
|
---|
| 2013 | if (!strcmp(mountlist->el[lino].mountpoint, "swap")) {
|
---|
[3193] | 2014 | mr_asprintf(command, "swapoff %s", mountlist->el[lino].device);
|
---|
[128] | 2015 | } else {
|
---|
| 2016 | if (!strcmp(mountlist->el[lino].mountpoint, "/1")) {
|
---|
[3193] | 2017 | mr_asprintf(command, "umount -d %s/", MNT_RESTORING);
|
---|
[128] | 2018 | log_msg(3,
|
---|
| 2019 | "Well, I know a certain kitty-kitty who'll be sleeping with Mommy tonight...");
|
---|
| 2020 | } else {
|
---|
[3193] | 2021 | mr_asprintf(command, "umount -d " MNT_RESTORING "%s", mountlist->el[lino].mountpoint);
|
---|
[2144] | 2022 |
|
---|
| 2023 | /* To support latest Ubuntu where /var is a separate FS
|
---|
| 2024 | * Cf: http://linux.derkeiler.com/Mailing-Lists/Ubuntu/2007-04/msg01319.html
|
---|
| 2025 | * we need to create some dirs under the real / before unmounting it */
|
---|
| 2026 | if (!strcmp(mountlist->el[lino].mountpoint, "/")) {
|
---|
| 2027 | run_program_and_log_output("mkdir -p " MNT_RESTORING "/var/lock", FALSE);
|
---|
| 2028 | run_program_and_log_output("mkdir -p " MNT_RESTORING "/var/run", FALSE);
|
---|
| 2029 | }
|
---|
[128] | 2030 | }
|
---|
| 2031 | }
|
---|
| 2032 | log_msg(10, "The 'umount' command is '%s'", command);
|
---|
| 2033 | res = run_program_and_log_output(command, 3);
|
---|
[3193] | 2034 | mr_free(command);
|
---|
[128] | 2035 | } else {
|
---|
[2211] | 2036 | mr_strcat(tmp, "...not mounted anyway :-) OK");
|
---|
[128] | 2037 | res = 0;
|
---|
| 2038 | }
|
---|
| 2039 | g_current_progress++;
|
---|
| 2040 | if (res) {
|
---|
[2211] | 2041 | mr_strcat(tmp, "...Failed");
|
---|
[128] | 2042 | retval++;
|
---|
| 2043 | log_to_screen(tmp);
|
---|
| 2044 | } else {
|
---|
| 2045 | log_msg(2, tmp);
|
---|
| 2046 | }
|
---|
[2211] | 2047 | paranoid_free(tmp);
|
---|
[128] | 2048 | }
|
---|
| 2049 | close_progress_form();
|
---|
| 2050 | if (retval) {
|
---|
[541] | 2051 | mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
|
---|
[128] | 2052 | } else {
|
---|
[541] | 2053 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
[128] | 2054 | }
|
---|
| 2055 | if (retval) {
|
---|
[541] | 2056 | log_to_screen("Unable to unmount some of your partitions.");
|
---|
[128] | 2057 | } else {
|
---|
[541] | 2058 | log_to_screen("All partitions were unmounted OK.");
|
---|
[128] | 2059 | }
|
---|
[3439] | 2060 | mr_asprintf(command, "mount");
|
---|
| 2061 | log_msg(4, "mount result after unmounting all FS", command);
|
---|
| 2062 | (void)run_program_and_log_output(command, 3);
|
---|
| 2063 | mr_free(command);
|
---|
[128] | 2064 | free(mountlist);
|
---|
| 2065 | return (retval);
|
---|
[1] | 2066 | }
|
---|
[128] | 2067 |
|
---|
[1] | 2068 | /**************************************************************************
|
---|
| 2069 | *END_UNMOUNT_ALL_DEVICES *
|
---|
| 2070 | **************************************************************************/
|
---|
| 2071 |
|
---|
| 2072 | /**
|
---|
[3271] | 2073 | * Extract mondorestore.cfg and the mountlist from the tape inserted
|
---|
[1] | 2074 | * to the ./tmp/ directory.
|
---|
| 2075 | * @param dev The tape device to read from.
|
---|
| 2076 | * @return 0 for success, nonzero for failure.
|
---|
| 2077 | */
|
---|
[128] | 2078 | int extract_cfg_file_and_mountlist_from_tape_dev(char *dev)
|
---|
[1] | 2079 | {
|
---|
[3193] | 2080 | char *command = NULL;
|
---|
[128] | 2081 | int res = 0;
|
---|
[1] | 2082 |
|
---|
[1968] | 2083 | if (bkpinfo->use_obdr) {
|
---|
| 2084 | skip_obdr();
|
---|
[1990] | 2085 | } else {
|
---|
[3430] | 2086 | // TODO: below 32KB seems to block at least on RHAS 2.1 and MDK 10.0
|
---|
[1990] | 2087 | set_tape_block_size_with_mt(bkpinfo->internal_tape_block_size);
|
---|
[1968] | 2088 | }
|
---|
[1990] | 2089 |
|
---|
[3193] | 2090 | 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] | 2091 | log_msg(2, "command = '%s'", command);
|
---|
| 2092 | res = run_program_and_log_output(command, -1);
|
---|
[3193] | 2093 | mr_free(command);
|
---|
| 2094 |
|
---|
[2029] | 2095 | if (res != 0) {
|
---|
| 2096 | if (does_file_exist(MONDO_CFG_FILE_STUB)) {
|
---|
| 2097 | res = 0;
|
---|
| 2098 | } else {
|
---|
| 2099 | /* Doing that allow us to remain compatible with pre-2.2.5 versions */
|
---|
| 2100 | log_msg(2, "pre-2.2.4 compatible mode on");
|
---|
[3194] | 2101 | 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] | 2102 | log_msg(2, "command = '%s'", command);
|
---|
| 2103 | res = run_program_and_log_output(command, -1);
|
---|
[3193] | 2104 | mr_free(command);
|
---|
[2029] | 2105 | if ((res != 0) && (does_file_exist(MONDO_CFG_FILE_STUB))) {
|
---|
| 2106 | res = 0;
|
---|
| 2107 | }
|
---|
| 2108 | }
|
---|
[128] | 2109 | }
|
---|
| 2110 | paranoid_free(command);
|
---|
| 2111 | return (res);
|
---|
[1] | 2112 | }
|
---|
| 2113 |
|
---|
[128] | 2114 |
|
---|
[1] | 2115 | /**
|
---|
[3753] | 2116 | * Get the configuration file from the tape, or CD.
|
---|
[1] | 2117 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 2118 | * - @c bkpinfo->backup_media_type
|
---|
| 2119 | * - @c bkpinfo->media_device
|
---|
| 2120 | * - @c bkpinfo->tmpdir
|
---|
| 2121 | * @return 0 for success, nonzero for failure.
|
---|
| 2122 | */
|
---|
[1645] | 2123 | int get_cfg_file_from_archive()
|
---|
[1] | 2124 | {
|
---|
[128] | 2125 | int retval = 0;
|
---|
| 2126 |
|
---|
[1] | 2127 | /** malloc *****/
|
---|
[3193] | 2128 | char *command = NULL;
|
---|
| 2129 | char *cfg_file = NULL;
|
---|
| 2130 | char *tmp = NULL;
|
---|
[3610] | 2131 | char *tmp1 = NULL;
|
---|
[3193] | 2132 | char *mountpt = NULL;
|
---|
| 2133 | char *mountlist_file = NULL;
|
---|
[2206] | 2134 | bool extract_mountlist_stub = FALSE;
|
---|
| 2135 | bool extract_i_want_my_lvm = FALSE;
|
---|
[1] | 2136 |
|
---|
[128] | 2137 | bool try_plan_B;
|
---|
| 2138 |
|
---|
| 2139 | assert(bkpinfo != NULL);
|
---|
| 2140 | log_msg(2, "gcffa --- starting");
|
---|
[541] | 2141 | log_to_screen("I'm thinking...");
|
---|
[3193] | 2142 | mr_asprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
|
---|
[3076] | 2143 | if (chdir(bkpinfo->tmpdir)) {
|
---|
| 2144 | // FIXME
|
---|
| 2145 | }
|
---|
[3193] | 2146 | mr_asprintf(cfg_file, "%s", MONDO_CFG_FILE_STUB);
|
---|
[128] | 2147 | unlink(cfg_file); // cfg_file[] is missing the '/' at the start, FYI, by intent
|
---|
[3193] | 2148 | mr_free(cfg_file);
|
---|
| 2149 |
|
---|
[128] | 2150 | unlink(FILELIST_FULL_STUB);
|
---|
| 2151 | unlink(BIGGIELIST_TXT_STUB);
|
---|
[3194] | 2152 | mr_asprintf(command, "mkdir -p %s", mountpt);
|
---|
[128] | 2153 | run_program_and_log_output(command, FALSE);
|
---|
[3193] | 2154 | mr_free(command);
|
---|
[128] | 2155 |
|
---|
[3193] | 2156 | mr_asprintf(cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB);
|
---|
| 2157 | mr_asprintf(mountlist_file, "%s/%s", bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
|
---|
[128] | 2158 | log_msg(2, "mountpt = %s; cfg_file=%s", mountpt, cfg_file);
|
---|
[3193] | 2159 | mr_free(mountpt);
|
---|
[128] | 2160 |
|
---|
| 2161 | if (!does_file_exist(cfg_file)) {
|
---|
| 2162 | log_msg(2, "gcffa --- we don't have cfg file yet.");
|
---|
| 2163 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 2164 | try_plan_B = TRUE;
|
---|
| 2165 | } else {
|
---|
[1736] | 2166 | log_msg(2, "gcffa --- calling mount_media now :)");
|
---|
| 2167 | if (!mount_media()) {
|
---|
[3263] | 2168 | log_msg(2, "gcffa --- managed to mount CD; so, no need for Plan B");
|
---|
[128] | 2169 | try_plan_B = FALSE;
|
---|
| 2170 | } else {
|
---|
| 2171 | try_plan_B = TRUE;
|
---|
| 2172 | }
|
---|
[1645] | 2173 | if (what_number_cd_is_this() > 1) {
|
---|
| 2174 | insist_on_this_cd_number((g_current_media_number = 1));
|
---|
[128] | 2175 | }
|
---|
| 2176 | }
|
---|
| 2177 | if (try_plan_B) {
|
---|
| 2178 | log_msg(2, "gcffa --- OK, switching to Plan B");
|
---|
[3076] | 2179 | if (chdir(bkpinfo->tmpdir)) {
|
---|
| 2180 | // FIXME
|
---|
| 2181 | }
|
---|
[128] | 2182 | run_program_and_log_output("mkdir -p tmp", FALSE);
|
---|
[1] | 2183 |
|
---|
[3822] | 2184 | if (bkpinfo->media_device == NULL) {
|
---|
| 2185 | mr_asprintf(bkpinfo->media_device, "%s", "/dev/st0");
|
---|
| 2186 | log_msg(2, "media_device is blank; assuming %s", bkpinfo->media_device);
|
---|
[128] | 2187 | }
|
---|
[3193] | 2188 | mr_asprintf(tmp, "%s", bkpinfo->media_device);
|
---|
[3822] | 2189 | if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device)) {
|
---|
| 2190 | mr_free(bkpinfo->media_device);
|
---|
| 2191 | mr_asprintf(bkpinfo->media_device, "%s", "/dev/st0");
|
---|
| 2192 | if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device)) {
|
---|
| 2193 | mr_free(bkpinfo->media_device);
|
---|
| 2194 | mr_asprintf(bkpinfo->media_device, "%s", "/dev/osst0");
|
---|
| 2195 | if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device)) {
|
---|
| 2196 | mr_free(bkpinfo->media_device);
|
---|
| 2197 | mr_asprintf(bkpinfo->media_device, "%s", "/dev/ht0");
|
---|
| 2198 | if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device)) {
|
---|
| 2199 | log_msg(3, "I tried lots of devices but none worked.");
|
---|
| 2200 | mr_free(bkpinfo->media_device);
|
---|
[128] | 2201 | }
|
---|
| 2202 | }
|
---|
| 2203 | }
|
---|
| 2204 | }
|
---|
[3822] | 2205 | if (bkpinfo->media_device == NULL) {
|
---|
| 2206 | bkpinfo->media_device = tmp;
|
---|
| 2207 | } else {
|
---|
| 2208 | mr_free(tmp);
|
---|
| 2209 | }
|
---|
[1] | 2210 |
|
---|
[3271] | 2211 | if (!does_file_exist("tmp/mondorestore.cfg")) {
|
---|
[1885] | 2212 | log_to_screen("Cannot find config info on media");
|
---|
[128] | 2213 | return (1);
|
---|
| 2214 | }
|
---|
| 2215 | } else {
|
---|
[2049] | 2216 | if (does_file_exist("/"MOUNTLIST_FNAME_STUB)) {
|
---|
| 2217 | extract_mountlist_stub = FALSE;
|
---|
| 2218 | } else {
|
---|
| 2219 | extract_mountlist_stub = TRUE;
|
---|
| 2220 | }
|
---|
| 2221 | if (does_file_exist("/"IWANTMYLVM_STUB)) {
|
---|
| 2222 | extract_i_want_my_lvm = FALSE;
|
---|
| 2223 | } else {
|
---|
| 2224 | extract_i_want_my_lvm = TRUE;
|
---|
| 2225 | }
|
---|
| 2226 |
|
---|
[3263] | 2227 | log_msg(2, "gcffa --- Plan B, a.k.a. untarring some file from all.tar.gz");
|
---|
[3193] | 2228 | 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] | 2229 | run_program_and_log_output(command, TRUE);
|
---|
[3193] | 2230 | mr_free(command);
|
---|
| 2231 |
|
---|
[128] | 2232 | if (!does_file_exist(MONDO_CFG_FILE_STUB)) {
|
---|
[2029] | 2233 | /* Doing that allow us to remain compatible with pre-2.2.5 versions */
|
---|
| 2234 | log_msg(2, "pre-2.2.4 compatible mode on");
|
---|
[3193] | 2235 | 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] | 2236 | run_program_and_log_output(command, TRUE);
|
---|
[3193] | 2237 | mr_free(command);
|
---|
[2029] | 2238 | if (!does_file_exist(MONDO_CFG_FILE_STUB)) {
|
---|
| 2239 | fatal_error
|
---|
| 2240 | ("Please reinsert the disk/CD and try again.");
|
---|
| 2241 | }
|
---|
[128] | 2242 | }
|
---|
[1] | 2243 | }
|
---|
[128] | 2244 | }
|
---|
| 2245 | if (does_file_exist(MONDO_CFG_FILE_STUB)) {
|
---|
| 2246 | log_msg(1, "gcffa --- great! We've got the config file");
|
---|
[3610] | 2247 | tmp1 = call_program_and_get_last_line_of_output("pwd");
|
---|
| 2248 | mr_asprintf(tmp, "%s/%s", tmp1, MONDO_CFG_FILE_STUB);
|
---|
[3193] | 2249 | mr_asprintf(command, "cp -f %s %s", tmp, cfg_file);
|
---|
[2227] | 2250 | log_it("%s",command);
|
---|
[3263] | 2251 | if (strcmp(tmp, cfg_file) && run_program_and_log_output(command, 1)) {
|
---|
[128] | 2252 | log_msg(1,
|
---|
| 2253 | "... but an error occurred when I tried to move it to %s",
|
---|
| 2254 | cfg_file);
|
---|
| 2255 | } else {
|
---|
| 2256 | log_msg(1, "... and I moved it successfully to %s", cfg_file);
|
---|
| 2257 | }
|
---|
[3193] | 2258 | mr_free(command);
|
---|
| 2259 |
|
---|
[3610] | 2260 | mr_asprintf(command, "cp -f %s/%s %s", tmp1, MOUNTLIST_FNAME_STUB, mountlist_file);
|
---|
| 2261 | mr_free(tmp1);
|
---|
[2227] | 2262 | log_it("%s",command);
|
---|
[2049] | 2263 | if (extract_mountlist_stub) {
|
---|
[3263] | 2264 | if (strcmp(tmp, cfg_file) && run_program_and_log_output(command, 1)) {
|
---|
[2049] | 2265 | log_msg(1, "Failed to get mountlist");
|
---|
[128] | 2266 | } else {
|
---|
[2049] | 2267 | log_msg(1, "Got mountlist too");
|
---|
[3193] | 2268 | mr_free(command);
|
---|
| 2269 | mr_asprintf(command, "cp -f %s %s", mountlist_file, g_mountlist_fname);
|
---|
[2049] | 2270 | if (run_program_and_log_output(command, 1)) {
|
---|
| 2271 | log_msg(1, "Failed to copy mountlist to /tmp");
|
---|
| 2272 | } else {
|
---|
| 2273 | log_msg(1, "Copied mountlist to /tmp as well OK");
|
---|
[3193] | 2274 | mr_free(command);
|
---|
| 2275 | mr_asprintf(command, "cp -f %s /tmp/",IWANTMYLVM_STUB);
|
---|
[2049] | 2276 | run_program_and_log_output(command, 1);
|
---|
| 2277 | }
|
---|
[128] | 2278 | }
|
---|
| 2279 | }
|
---|
[3193] | 2280 | mr_free(command);
|
---|
| 2281 | mr_free(tmp);
|
---|
[128] | 2282 | }
|
---|
[3193] | 2283 |
|
---|
[2878] | 2284 | run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
|
---|
[128] | 2285 | if (!does_file_exist(cfg_file)) {
|
---|
[2227] | 2286 | log_it("%s",cfg_file);
|
---|
[128] | 2287 | log_msg(1, "%s not found", cfg_file);
|
---|
[3263] | 2288 | log_to_screen("Oh dear. Unable to recover configuration file from boot disk");
|
---|
[128] | 2289 | return (1);
|
---|
| 2290 | }
|
---|
[1] | 2291 |
|
---|
[3271] | 2292 | log_to_screen("Recovered mondorestore.cfg");
|
---|
[128] | 2293 | if (!does_file_exist(MOUNTLIST_FNAME_STUB)) {
|
---|
[541] | 2294 | log_to_screen("...but not mountlist.txt - a pity, really...");
|
---|
[3263] | 2295 | } else {
|
---|
[2049] | 2296 | /* Is this code really useful ??? */
|
---|
| 2297 | if (extract_mountlist_stub) {
|
---|
[3193] | 2298 | mr_asprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB, bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
|
---|
[2049] | 2299 | run_program_and_log_output(command, FALSE);
|
---|
[3193] | 2300 | mr_free(command);
|
---|
[2049] | 2301 | }
|
---|
[128] | 2302 | }
|
---|
[1] | 2303 |
|
---|
[3193] | 2304 | mr_asprintf(command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB);
|
---|
| 2305 | mr_free(cfg_file);
|
---|
| 2306 |
|
---|
[128] | 2307 | run_program_and_log_output(command, FALSE);
|
---|
[3193] | 2308 | mr_free(command);
|
---|
| 2309 |
|
---|
[2049] | 2310 | if (extract_mountlist_stub) {
|
---|
[3193] | 2311 | mr_asprintf(command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB);
|
---|
[2049] | 2312 | run_program_and_log_output(command, FALSE);
|
---|
[3193] | 2313 | mr_free(command);
|
---|
[2049] | 2314 | }
|
---|
[3193] | 2315 | mr_free(mountlist_file);
|
---|
| 2316 |
|
---|
| 2317 | mr_asprintf(command, "cp -f etc/raidtab /etc/");
|
---|
[128] | 2318 | run_program_and_log_output(command, FALSE);
|
---|
[3193] | 2319 | mr_free(command);
|
---|
| 2320 |
|
---|
[2049] | 2321 | if (extract_i_want_my_lvm) {
|
---|
[3193] | 2322 | mr_asprintf(command, "cp -f %s /tmp/",IWANTMYLVM_STUB);
|
---|
[2049] | 2323 | run_program_and_log_output(command, FALSE);
|
---|
[3193] | 2324 | mr_free(command);
|
---|
[2049] | 2325 | }
|
---|
[128] | 2326 | g_backup_media_type = bkpinfo->backup_media_type;
|
---|
| 2327 | return (retval);
|
---|
[1] | 2328 | }
|
---|
| 2329 |
|
---|
| 2330 | /**************************************************************************
|
---|
| 2331 | *END_GET_CFG_FILE_FROM_ARCHIVE *
|
---|
| 2332 | **************************************************************************/
|
---|
| 2333 |
|
---|
| 2334 | /* @} - end restoreUtilityGroup */
|
---|
| 2335 |
|
---|
[2982] | 2336 | void wait_until_software_raids_are_prepped(char *mdstat_file, int wait_for_percentage)
|
---|
[1] | 2337 | {
|
---|
[558] | 2338 | struct raidlist_itself *raidlist;
|
---|
[2982] | 2339 | int unfinished_mdstat_devices = 9999;
|
---|
| 2340 | int i = 0;
|
---|
[3193] | 2341 | char *screen_message = NULL;
|
---|
[1] | 2342 |
|
---|
[558] | 2343 | raidlist = malloc(sizeof(struct raidlist_itself));
|
---|
[128] | 2344 |
|
---|
| 2345 | assert(wait_for_percentage <= 100);
|
---|
[2230] | 2346 | log_it("wait_until_software_raids_are_prepped");
|
---|
[128] | 2347 | while (unfinished_mdstat_devices > 0) {
|
---|
[558] | 2348 | // FIXME: Prefix '/dev/' should really be dynamic!
|
---|
[2982] | 2349 | if (parse_mdstat(MDSTAT_FILE, raidlist, "/dev/")) {
|
---|
[558] | 2350 | log_to_screen("Sorry, cannot read %s", MDSTAT_FILE);
|
---|
| 2351 | log_msg(1,"Sorry, cannot read %s", MDSTAT_FILE);
|
---|
[128] | 2352 | return;
|
---|
[1] | 2353 | }
|
---|
[2982] | 2354 | for (unfinished_mdstat_devices = 0; i <= raidlist->entries; i++) {
|
---|
[558] | 2355 | if (raidlist->el[i].progress < wait_for_percentage) {
|
---|
[128] | 2356 | unfinished_mdstat_devices++;
|
---|
[704] | 2357 | if (raidlist->el[i].progress == -1) // delayed while another partition inits
|
---|
| 2358 | {
|
---|
| 2359 | continue;
|
---|
| 2360 | }
|
---|
[558] | 2361 | log_msg(1,"Sync'ing %s (i=%d)", raidlist->el[i].raid_device, i);
|
---|
[3193] | 2362 | mr_asprintf(screen_message, "Sync'ing %s", raidlist->el[i].raid_device);
|
---|
[128] | 2363 | open_evalcall_form(screen_message);
|
---|
[3193] | 2364 | mr_free(screen_message);
|
---|
| 2365 |
|
---|
[558] | 2366 | while (raidlist->el[i].progress < wait_for_percentage) {
|
---|
| 2367 | log_msg(1,"Percentage sync'ed: %d", raidlist->el[i].progress);
|
---|
| 2368 | update_evalcall_form(raidlist->el[i].progress);
|
---|
[128] | 2369 | sleep(2);
|
---|
[558] | 2370 | // FIXME: Prefix '/dev/' should really be dynamic!
|
---|
[2982] | 2371 | if (parse_mdstat(MDSTAT_FILE, raidlist, "/dev/")) {
|
---|
[128] | 2372 | break;
|
---|
| 2373 | }
|
---|
| 2374 | }
|
---|
| 2375 | close_evalcall_form();
|
---|
| 2376 | }
|
---|
[1] | 2377 | }
|
---|
[128] | 2378 | }
|
---|
[558] | 2379 | paranoid_free(raidlist);
|
---|
[3194] | 2380 | }
|
---|