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