source: MondoRescue/branches/3.2/mondo/src/mondorestore/mondo-rstr-tools.c@ 3601

Last change on this file since 3601 was 3601, checked in by Bruno Cornec, 8 years ago

Fix #804 by adding logging for /boot content

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