source: MondoRescue/branches/2.2.5/mondo/src/mondorestore/mondo-rstr-tools.c@ 1848

Last change on this file since 1848 was 1848, checked in by Bruno Cornec, 16 years ago

Never tries to eject a NFS media (report from Brian McKee)

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