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