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