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