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