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