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