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