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

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

Use variable DF in mindi to be able to support the ESX vdf

  • Property svn:keywords set to Id
File size: 78.3 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 "../common/my-stuff.h"
128#include "../common/mondostructures.h"
129#include "../common/libmondo.h"
130#include "mr-externs.h"
131//#include "mondo-restore.h"
132//#include "mondo-rstr-compare-EXT.h"
133#include "mondo-rstr-tools.h"
134
135extern bool g_sigpipe_caught;
136extern bool g_ISO_restore_mode; /* are we in Iso Mode? */
137extern bool g_I_have_just_nuked;
138extern char *g_tmpfs_mountpt;
139extern char *g_isodir_device;
140extern char *g_isodir_format;
141extern long g_current_progress, g_maximum_progress;
142extern char *g_biggielist_txt; // where 'biggielist.txt' is stored, on ramdisk / tempdir;
143 // biggielist.txt is the list of big files stored on the
144 // backup media set in question
145extern char *g_filelist_full; // filelist.full.gz is the list of all regular files
146 // (excluding big files) stored on the backup media set
147extern char *g_biggielist_pot; // list of big files which _could_ be restored, if the
148 // user chooses them
149extern char *g_filelist_imagedevs; // list of devices (e.g. /dev/hda1, /dev/sda5) which
150 // were archived as images, not just /dev entries
151 // ... e.g. NTFS, BeOS partitions
152extern char *g_imagedevs_restthese; // of the imagedevs listed in FILELIST_IMAGEDEVS,
153 // restore only these
154extern char *g_mondo_cfg_file; // where m*ndo-restore.cfg (the config file) is stored
155extern char *g_mountlist_fname; // where mountlist.txt (the mountlist file) is stored
156extern char *g_mondo_home; // homedir of Mondo; usually /usr/local/share/mondo
157
158extern t_bkptype g_backup_media_type;
159
160extern int g_partition_table_locked_up;
161extern char *MONDO_LOGFILE;
162
163/* Reference to global bkpinfo */
164extern struct s_bkpinfo *bkpinfo;
165
166/* Should we use or not extended attributes and acl when restoring */
167char *g_getfattr = NULL;
168char *g_getfacl = NULL;
169
170/**
171* @addtogroup restoreUtilityGroup
172* @{
173*/
174/**
175* Free the malloc()s for the filename variables.
176*/
177void free_MR_global_filenames()
178{
179paranoid_free(g_biggielist_txt);
180paranoid_free(g_filelist_full);
181paranoid_free(g_filelist_imagedevs);
182// paranoid_free (g_imagedevs_pot );
183paranoid_free(g_imagedevs_restthese);
184paranoid_free(g_mondo_cfg_file);
185paranoid_free(g_mountlist_fname);
186paranoid_free(g_mondo_home);
187paranoid_free(g_tmpfs_mountpt);
188paranoid_free(g_isodir_device);
189paranoid_free(g_isodir_format);
190
191}
192
193
194
195/**
196* Ask the user which imagedevs from the list contained in @p infname should
197* actually be restored.
198* @param infname The file containing a list of all imagedevs.
199* @param outfname The location of the output file containing the imagedevs the user wanted to restore.
200* @ingroup restoreUtilityGroup
201*/
202void ask_about_these_imagedevs(char *infname, char *outfname)
203{
204FILE *fin;
205FILE *fout;
206/************************************************************************
207* allocate memory regions. test and set -sab 16 feb 2003 *
208************************************************************************/
209char *incoming_ptr;
210char *question_ptr;
211
212char incoming[MAX_STR_LEN] = "\0";
213char question[MAX_STR_LEN];
214
215assert_string_is_neither_NULL_nor_zerolength(infname);
216assert_string_is_neither_NULL_nor_zerolength(outfname);
217
218incoming_ptr = malloc(sizeof(incoming));
219if (incoming_ptr == NULL) {
220fprintf(stderr, "Out of Memory\n");
221exit(EXIT_FAILURE);
222}
223
224question_ptr = malloc(sizeof(question));
225if (question_ptr == NULL) {
226fprintf(stderr, "Out of Memory\n");
227exit(EXIT_FAILURE);
228}
229
230memset(incoming_ptr, '\0', sizeof(incoming));
231memset(question_ptr, '\0', sizeof(question));
232
233
234
235if (!(fin = fopen(infname, "r"))) {
236fatal_error("Cannot openin infname");
237}
238if (!(fout = fopen(outfname, "w"))) {
239fatal_error("Cannot openin outfname");
240}
241for (fgets(incoming_ptr, MAX_STR_LEN, fin);
242 !feof(fin); fgets(incoming_ptr, MAX_STR_LEN, fin)) {
243strip_spaces(incoming_ptr);
244
245if (incoming[0] == '\0') {
246 continue;
247}
248
249sprintf(question_ptr,
250 "Should I restore the image of %s ?", incoming_ptr);
251
252if (ask_me_yes_or_no(question_ptr)) {
253 fprintf(fout, "%s\n", incoming_ptr);
254}
255}
256
257/*** free memory ***********/
258paranoid_free(incoming_ptr);
259incoming_ptr = NULL;
260paranoid_free(question_ptr);
261question_ptr = NULL;
262
263
264paranoid_fclose(fout);
265paranoid_fclose(fin);
266}
267
268/**************************************************************************
269*ASK_ABOUT_THESE_IMAGEDEVS *
270**************************************************************************/
271
272
273
274
275
276
277
278
279/**
280* Extract @c mondo-restore.cfg and @c mountlist.txt from @p ramdisk_fname.
281* @param bkpinfo The backup information structure. @c tmpdir is the only field used.
282* @param ramdisk_fname The filename of the @b compressed ramdisk to look in.
283* @param output_cfg_file Where to put the configuration file extracted.
284* @param output_mountlist_file Where to put the mountlist file extracted.
285* @return 0 for success, nonzero for failure.
286* @ingroup restoreUtilityGroup
287*/
288int
289extract_config_file_from_ramdisk(char *ramdisk_fname,
290 char *output_cfg_file,
291 char *output_mountlist_file)
292{
293char *mountpt;
294char *command;
295char *orig_fname;
296int retval = 0;
297
298assert(bkpinfo != NULL);
299malloc_string(mountpt);
300malloc_string(command);
301malloc_string(orig_fname);
302assert_string_is_neither_NULL_nor_zerolength(ramdisk_fname);
303assert_string_is_neither_NULL_nor_zerolength(output_cfg_file);
304assert_string_is_neither_NULL_nor_zerolength(output_mountlist_file);
305sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
306sprintf(command, "mkdir -p %s", mountpt);
307run_program_and_log_output(command, FALSE);
308sprintf(command, "gzip -dc %s > %s/mindi.rd 2> /dev/null",
309 ramdisk_fname, bkpinfo->tmpdir);
310
311run_program_and_log_output(command, FALSE);
312sprintf(command, "umount %s", mountpt);
313
314run_program_and_log_output(command, FALSE);
315
316sprintf(command, "mount -o loop %s/mindi.rd -t ext2 %s",
317 bkpinfo->tmpdir, mountpt);
318
319run_program_and_log_output(command, FALSE);
320
321sprintf(command, "mkdir -p %s/tmp", bkpinfo->tmpdir);
322
323run_program_and_log_output(command, FALSE);
324
325sprintf(command, "cp -f %s/%s %s", // %s/%s becomes {mountpt}/tmp/m*ndo-restore.cfg
326 mountpt, g_mondo_cfg_file, output_cfg_file);
327run_program_and_log_output(command, FALSE);
328
329sprintf(orig_fname, "%s/%s", mountpt, g_mountlist_fname);
330if (does_file_exist(orig_fname)) {
331sprintf(command, "cp -f %s %s", orig_fname, output_mountlist_file);
332run_program_and_log_output(command, FALSE);
333}
334sprintf(command, "umount %s", mountpt);
335run_program_and_log_output(command, FALSE);
336if (!does_file_exist(output_cfg_file)
337|| (!does_file_exist(output_mountlist_file)
338 && does_file_exist(orig_fname))) {
339log_msg(2, "Failed to extract %s and/or %s from ramdisk",
340 output_cfg_file, output_mountlist_file);
341retval = 1;
342} else {
343retval = 0;
344}
345paranoid_free(mountpt);
346paranoid_free(command);
347paranoid_free(orig_fname);
348return (retval);
349
350}
351
352
353
354
355/**
356* Keep trying to get mondo-restore.cfg from the archive, until the user gives up.
357*/
358void get_cfg_file_from_archive_or_bust()
359{
360while (get_cfg_file_from_archive()) {
361if (!ask_me_yes_or_no
362 ("Failed to find config file/archives. Choose another source?"))
363{
364 fatal_error("Could not find config file/archives. Aborting.");
365}
366interactively_obtain_media_parameters_from_user(FALSE);
367}
368}
369
370
371/**
372* Determine whether @p list_fname contains a line containing @p f.
373* @param f The line to search for.
374* @param list_fname The file to search in.
375* @param preamble Ignore this beginning part of @p f ("" to disable).
376* @return TRUE if it's in the list, FALSE if it's not.
377*/
378bool is_file_in_list(char *f, char *list_fname, char *preamble)
379{
380
381/** needs malloc **/
382char *command;
383char *file;
384char *tmp;
385int res;
386
387malloc_string(command);
388malloc_string(file);
389malloc_string(tmp);
390assert_string_is_neither_NULL_nor_zerolength(f);
391assert_string_is_neither_NULL_nor_zerolength(list_fname);
392assert(preamble != NULL);
393
394if (strncmp(preamble, f, strlen(preamble)) == 0) {
395strcpy(file, f + strlen(preamble));
396} else {
397strcpy(file, f);
398}
399if (file[0] == '/' && file[1] == '/') {
400strcpy(tmp, file);
401strcpy(file, tmp + 1);
402}
403sprintf(tmp,
404 "Checking to see if f=%s, file=%s, is in the list of biggiefiles",
405 f, file);
406log_msg(2, tmp);
407sprintf(command, "grep -E '^%s$' %s", file, list_fname);
408res = run_program_and_log_output(command, FALSE);
409paranoid_free(command);
410paranoid_free(file);
411paranoid_free(tmp);
412if (res) {
413return (FALSE);
414} else {
415return (TRUE);
416}
417}
418
419/**************************************************************************
420*END_IS_FILE_IN_LIST *
421**************************************************************************/
422
423
424
425/**
426* Set up an ISO backup.
427* @param bkpinfo The backup information structure. Fields used:
428* - @c bkpinfo->backup_media_type
429* - @c bkpinfo->disaster_recovery
430* - @c bkpinfo->isodir
431* @param nuke_me_please If TRUE, we're in nuke mode; if FALSE we're in interactive mode.
432* @return 0 for success, nonzero for failure.
433*/
434int iso_fiddly_bits(bool nuke_me_please)
435{
436char *mount_isodir_command, *tmp, *command;
437int retval = 0, i;
438bool already_mounted = FALSE;
439
440assert(bkpinfo != NULL);
441malloc_string(mount_isodir_command);
442malloc_string(tmp);
443malloc_string(command);
444g_ISO_restore_mode = TRUE;
445read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
446if (bkpinfo->disaster_recovery) {
447/* Patch Conor Daly 26-june-2004
448* Don't let this clobber an existing bkpinfo->isodir */
449if (!bkpinfo->isodir[0]) {
450 strcpy(bkpinfo->isodir, "/tmp/isodir");
451}
452/* End patch */
453sprintf(command, "mkdir -p %s", bkpinfo->isodir);
454run_program_and_log_output(command, 5);
455log_msg(2, "Setting isodir to %s", bkpinfo->isodir);
456}
457
458if (!get_isodir_info
459(g_isodir_device, g_isodir_format, bkpinfo->isodir,
460 nuke_me_please)) {
461return (1);
462}
463paranoid_system("umount " MNT_CDROM " 2> /dev/null"); /* just in case */
464
465if (is_this_device_mounted(g_isodir_device)) {
466log_to_screen("WARNING - isodir is already mounted");
467already_mounted = TRUE;
468} else {
469sprintf(mount_isodir_command, "mount %s", g_isodir_device);
470if (strlen(g_isodir_format) > 1) {
471 sprintf(mount_isodir_command + strlen(mount_isodir_command),
472 " -t %s", g_isodir_format);
473}
474strcat(mount_isodir_command, " -o ro ");
475strcat(mount_isodir_command, bkpinfo->isodir);
476run_program_and_log_output("df -m", FALSE);
477sprintf(tmp,
478 "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?",
479 mount_isodir_command);
480log_msg(1, tmp);
481if (run_program_and_log_output(mount_isodir_command, FALSE)) {
482 popup_and_OK
483 ("Cannot mount the device where the ISO files are stored.");
484 return (1);
485}
486log_to_screen
487 ("I have mounted the device where the ISO files are stored.");
488}
489if (!IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
490 mount_media();
491}
492i = what_number_cd_is_this(); /* has the side-effect of calling mount_media() */
493sprintf(tmp, "%s #%d has been mounted via loopback mount",
494 media_descriptor_string(bkpinfo->backup_media_type), i);
495log_msg(1, tmp);
496if (i < 0) {
497popup_and_OK
498 ("Cannot find ISO images in the directory you specified.");
499retval = 1;
500}
501log_msg(2, "%ld: bkpinfo->isodir is now %s", __LINE__,
502 bkpinfo->isodir);
503paranoid_free(mount_isodir_command);
504paranoid_free(tmp);
505paranoid_free(command);
506return (retval);
507}
508
509
510
511
512/**
513* Kill all Petris processes.
514*/
515void kill_petris(void)
516{
517char *command;
518malloc_string(command);
519sprintf(command,
520 "kill `ps 2> /dev/null | grep petris 2> /dev/null | grep -v grep | cut -d' ' -f2` 2> /dev/null");
521paranoid_system(command);
522paranoid_free(command);
523}
524
525/**************************************************************************
526*END_KILL_PETRIS *
527**************************************************************************/
528
529
530/**
531* Mount @p device at @p mpt as @p format.
532* @param device The device (/dev entry) to mount.
533* @param mpt The directory to mount it on.
534* @param format The filesystem type of @p device.
535* @param writeable If TRUE, mount read-write; if FALSE, mount read-only.
536* @return 0 for success, nonzero for failure.
537*/
538int mount_device(char *device, char *mpt, char *format, bool writeable)
539{
540int res = 0;
541
542/** malloc **/
543char *tmp, *command, *mountdir, *mountpoint, *additional_parameters;
544
545assert_string_is_neither_NULL_nor_zerolength(device);
546assert_string_is_neither_NULL_nor_zerolength(mpt);
547assert(format != NULL);
548malloc_string(tmp);
549malloc_string(command);
550malloc_string(mountdir);
551malloc_string(mountpoint);
552malloc_string(additional_parameters);
553
554if (!strcmp(mpt, "/1")) {
555 strcpy(mountpoint, "/");
556 log_msg(3, "Mommm! SME is being a dildo!");
557} else {
558 strcpy(mountpoint, mpt);
559}
560
561if (!strcmp(mountpoint, "lvm")) {
562 return (0);
563}
564if (!strcmp(mountpoint, "image")) {
565 return (0);
566}
567sprintf(tmp, "Mounting device %s ", device);
568log_msg(1, tmp);
569if (writeable) {
570 strcpy(additional_parameters, "-o rw");
571} else {
572 strcpy(additional_parameters, "-o ro");
573}
574if (find_home_of_exe("setfattr")) {
575 strcat(additional_parameters, ",user_xattr");
576}
577if (find_home_of_exe("setfacl")) {
578 strcat(additional_parameters, ",acl");
579}
580
581if (!strcmp(mountpoint, "swap")) {
582 sprintf(command, "swapon %s", device);
583} else {
584if (!strcmp(mountpoint, "/")) {
585 strcpy(mountdir, MNT_RESTORING);
586} else {
587 sprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint);
588}
589sprintf(command, "mkdir -p %s", mountdir);
590run_program_and_log_output(command, FALSE);
591sprintf(command, "mount -t %s %s %s %s 2>> %s", format, device,
592 additional_parameters, mountdir, MONDO_LOGFILE);
593log_msg(2, "command='%s'", command);
594}
595res = run_program_and_log_output(command, TRUE);
596if (res && (strstr(command, "xattr") || strstr(command, "acl"))) {
597 log_msg(1, "Re-trying without the fancy extra parameters");
598 sprintf(command, "mount -t %s %s %s 2>> %s", format, device,
599 mountdir, MONDO_LOGFILE);
600 res = run_program_and_log_output(command, TRUE);
601}
602if (res) {
603 log_msg(1, "Unable to mount device %s (type %s) at %s", device,
604 format, mountdir);
605 log_msg(1, "command was '%s'", command);
606 if (!strcmp(mountpoint, "swap")) {
607 log_to_screen(tmp);
608 } else {
609 log_msg(2, "Retrying w/o the '-t' switch");
610 sprintf(command, "mount %s %s 2>> %s", device, mountdir,
611 MONDO_LOGFILE);
612 log_msg(2, "2nd command = '%s'", command);
613 res = run_program_and_log_output(command, TRUE);
614 if (res == 0) {
615 log_msg(1,
616 "That's OK. I called mount w/o a filesystem type and it worked fine in the end.");
617 } else {
618 log_to_screen(tmp);
619 }
620 }
621}
622if (res && !strcmp(mountpoint, "swap")) {
623 log_msg(2, "That's ok. It's just a swap partition.");
624 log_msg(2, "Non-fatal error. Returning 0.");
625 res = 0;
626}
627
628paranoid_free(tmp);
629paranoid_free(command);
630paranoid_free(mountdir);
631paranoid_free(mountpoint);
632paranoid_free(additional_parameters);
633
634return (res);
635}
636
637/**************************************************************************
638*END_MOUNT_DEVICE *
639**************************************************************************/
640
641
642/**
643* Mount all devices in @p p_external_copy_of_mountlist on @p MNT_RESTORING.
644* @param p_external_copy_of_mountlist The mountlist containing devices to be mounted.
645* @param writeable If TRUE, then mount read-write; if FALSE mount read-only.
646* @return The number of errors encountered (0 for success).
647*/
648int mount_all_devices(struct mountlist_itself
649 *p_external_copy_of_mountlist, bool writeable)
650{
651int retval = 0, lino, res;
652char *tmp, *these_failed, *format;
653struct mountlist_itself *mountlist;
654
655malloc_string(tmp);
656malloc_string(format);
657malloc_string(these_failed);
658assert(p_external_copy_of_mountlist != NULL);
659mountlist = malloc(sizeof(struct mountlist_itself));
660memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist,
661 sizeof(struct mountlist_itself));
662sort_mountlist_by_mountpoint(mountlist, 0);
663
664/** menset **/
665these_failed[0] = '\0';
666
667mvaddstr_and_log_it(g_currentY, 0, "Mounting devices ");
668open_progress_form("Mounting devices",
669 "I am now mounting all the drives.",
670 "This should not take long.",
671 "", mountlist->entries);
672
673for (lino = 0; lino < mountlist->entries; lino++) {
674if (!strcmp(mountlist->el[lino].device, "/proc")) {
675 log_msg(1,
676 "Again with the /proc - why is this in your mountlist?");
677} else if (is_this_device_mounted(mountlist->el[lino].device)) {
678 sprintf(tmp, "%s is already mounted",
679 mountlist->el[lino].device);
680 log_to_screen(tmp);
681} else if (strcmp(mountlist->el[lino].mountpoint, "none")
682 && strcmp(mountlist->el[lino].mountpoint, "lvm")
683 && strcmp(mountlist->el[lino].mountpoint, "raid")
684 && strcmp(mountlist->el[lino].mountpoint, "image")) {
685 sprintf(tmp, "Mounting %s", mountlist->el[lino].device);
686 update_progress_form(tmp);
687 strcpy(format, mountlist->el[lino].format);
688 /* BERLIOS: removed as it doen't make sens to not mount ext3 partitions as ext3
689 if (!strcmp(format, "ext3")) {
690 strcpy(format, "ext2");
691 }
692 */
693 res = mount_device(mountlist->el[lino].device,
694 mountlist->el[lino].mountpoint,
695 format, writeable);
696 retval += res;
697 if (res) {
698 strcat(these_failed, mountlist->el[lino].device);
699 strcat(these_failed, " ");
700 }
701}
702g_current_progress++;
703}
704close_progress_form();
705if (retval) {
706if (g_partition_table_locked_up > 0) {
707 log_to_screen
708 ("fdisk's ictol() call to refresh its copy of the partition table causes the kernel to");
709 log_to_screen
710 ("lock up the partition table. You might have to reboot and use Interactive Mode to");
711 log_to_screen
712 ("format and restore *without* partitioning first. Sorry for the inconvenience.");
713}
714sprintf(tmp, "Could not mount device(s) %s- shall I abort?",
715 these_failed);
716if (!ask_me_yes_or_no(tmp)) {
717 retval = 0;
718 log_to_screen
719 ("Continuing, although some device(s) failed to be mounted");
720 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
721} else {
722 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
723 log_to_screen
724 ("Unable to mount some or all of your partitions.");
725}
726} else {
727log_to_screen("All partitions were mounted OK.");
728mvaddstr_and_log_it(g_currentY++, 74, "Done.");
729}
730run_program_and_log_output("df -m", 3);
731paranoid_free(mountlist);
732paranoid_free(tmp);
733paranoid_free(format);
734paranoid_free(these_failed);
735return (retval);
736}
737
738/**************************************************************************
739*END_MOUNT_ALL_DEVICES *
740**************************************************************************/
741
742
743/**
744* Mount the CD-ROM or USB device at /mnt/cdrom.
745* @param bkpinfo The backup information structure. Fields used:
746* - @c bkpinfo->backup_media_type
747* - @c bkpinfo->disaster_recovery
748* - @c bkpinfo->isodir
749* - @c bkpinfo->media_device
750* @return 0 for success, nonzero for failure.
751*/
752int mount_media()
753{
754char *mount_cmd;
755int i, res;
756#ifdef __FreeBSD__
757char mdd[32];
758char *mddev = mdd;
759#endif
760
761malloc_string(mount_cmd);
762assert(bkpinfo != NULL);
763
764if (bkpinfo->backup_media_type == tape
765 || bkpinfo->backup_media_type == udev) {
766 log_msg(8, "Tape/udev. Therefore, no need to mount a media.");
767 paranoid_free(mount_cmd);
768 return 0;
769}
770
771if (!run_program_and_log_output("mount | grep -F " MNT_CDROM, FALSE)) {
772 log_msg(2, "mount_media() - media already mounted. Fair enough.");
773 paranoid_free(mount_cmd);
774 return (0);
775}
776
777if (bkpinfo->backup_media_type == nfs) {
778 log_msg(2, "Mounting for NFS thingy");
779 log_msg(2, "isodir = %s", bkpinfo->isodir);
780 if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/"))
781 && am_I_in_disaster_recovery_mode()) {
782 strcpy(bkpinfo->isodir, "/tmp/isodir");
783 log_msg(1, "isodir is being set to %s", bkpinfo->isodir);
784 }
785#ifdef __FreeBSD__
786 sprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir,
787 bkpinfo->nfs_remote_dir, bkpinfo->prefix, g_current_media_number);
788 mddev = make_vn(mount_cmd);
789 sprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev);
790#else
791 sprintf(mount_cmd, "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s",
792 bkpinfo->isodir, bkpinfo->nfs_remote_dir,
793 bkpinfo->prefix, g_current_media_number, MNT_CDROM);
794#endif
795
796} else if (bkpinfo->backup_media_type == iso) {
797#ifdef __FreeBSD__
798 sprintf(mount_cmd, "%s/%s-%d.iso", bkpinfo->isodir,
799 bkpinfo->prefix, g_current_media_number);
800 mddev = make_vn(mount_cmd);
801 sprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM);
802#else
803 sprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s",
804 bkpinfo->isodir, bkpinfo->prefix, g_current_media_number, MNT_CDROM);
805#endif
806} else if (bkpinfo->backup_media_type == usb) {
807 sprintf(mount_cmd, "mount -t vfat %s %s", bkpinfo->media_device, MNT_CDROM);
808} else if (strstr(bkpinfo->media_device, "/dev/")) {
809#ifdef __FreeBSD__
810 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
811 MNT_CDROM);
812#else
813 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
814 bkpinfo->media_device, MNT_CDROM);
815#endif
816} else {
817 if (bkpinfo->disaster_recovery
818 && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
819 strcpy(bkpinfo->media_device,
820 last_line_of_file("/tmp/CDROM-LIVES-HERE"));
821 } else {
822 find_cdrom_device(bkpinfo->media_device, TRUE);
823 }
824
825#ifdef __FreeBSD__
826 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
827 MNT_CDROM);
828#else
829 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
830 bkpinfo->media_device, MNT_CDROM);
831#endif
832}
833
834log_msg(2, "(mount_media) --- command = %s", mount_cmd);
835for (i = 0; i < 2; i++) {
836res = run_program_and_log_output(mount_cmd, FALSE);
837if (!res) {
838 break;
839} else {
840 log_msg(2, "Failed to mount device.");
841 sleep(5);
842 run_program_and_log_output("sync", FALSE);
843}
844}
845if (res) {
846 log_msg(2, "Failed, despite %d attempts", i);
847} else {
848 log_msg(2, "Mounted CD-ROM drive OK");
849}
850paranoid_free(mount_cmd);
851return (res);
852}
853
854
855
856
857
858/**************************************************************************
859*END_MOUNT_CDROM *
860**************************************************************************/
861
862
863
864/**
865* Fix some miscellaneous things in the filesystem so the system will come
866* up correctly on the first boot.
867*/
868void protect_against_braindead_sysadmins()
869{
870run_program_and_log_output("touch " MNT_RESTORING "/var/log/pacct",
871 FALSE);
872run_program_and_log_output("touch " MNT_RESTORING "/var/account/pacct",
873 FALSE);
874if (run_program_and_log_output("ls " MNT_RESTORING " /tmp", FALSE)) {
875run_program_and_log_output("chmod 1777 " MNT_RESTORING "/tmp",
876 FALSE);
877}
878run_program_and_log_output("mkdir -p " MNT_RESTORING
879 "/var/run/console", FALSE);
880run_program_and_log_output("chmod 777 " MNT_RESTORING "/dev/null",
881 FALSE);
882run_program_and_log_output("cd " MNT_RESTORING
883 "; 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",
884 TRUE);
885run_program_and_log_output("rm -f " MNT_RESTORING "/var/run/*.pid",
886 TRUE);
887run_program_and_log_output("rm -f " MNT_RESTORING "/var/lock/subsys/*",
888 TRUE);
889}
890
891/**************************************************************************
892*END_PROTECT_AGAINST_BRAINDEAD_SYSADMINS *
893**************************************************************************/
894
895
896
897
898/**
899* Fill out @p bkpinfo based on @p cfg_file.
900* @param cfg_file The mondo-restore.cfg file to read into @p bkpinfo.
901* @param bkpinfo The backup information structure to fill out with information
902* from @p cfg_file.
903* @return 0 for success, nonzero for failure.
904*/
905int read_cfg_file_into_bkpinfo(char *cfgf)
906{
907/** add mallocs **/
908char *value = NULL;
909char *tmp = NULL;
910char *envtmp1 = NULL;
911char *envtmp2 = NULL;
912char *command = NULL;
913char *iso_mnt = NULL;
914char *iso_path = NULL;
915char *old_isodir = NULL;
916char cfg_file[100];
917t_bkptype media_specified_by_user;
918
919malloc_string(command);
920malloc_string(iso_mnt);
921malloc_string(iso_path);
922malloc_string(old_isodir);
923malloc_string(value);
924malloc_string(tmp);
925// assert_string_is_neither_NULL_nor_zerolength(cfg_file);
926assert(bkpinfo != NULL);
927
928if (!cfgf) {
929strcpy(cfg_file, g_mondo_cfg_file);
930} else {
931strcpy(cfg_file, cfgf);
932}
933
934media_specified_by_user = bkpinfo->backup_media_type; // or 'none', if not specified
935
936if (0 == read_cfg_var(cfg_file, "backup-media-type", value)) {
937if (!strcmp(value, "cdstream")) {
938 bkpinfo->backup_media_type = cdstream;
939} else if (!strcmp(value, "cdr")) {
940 bkpinfo->backup_media_type = cdr;
941} else if (!strcmp(value, "cdrw")) {
942 bkpinfo->backup_media_type = cdrw;
943} else if (!strcmp(value, "dvd")) {
944 bkpinfo->backup_media_type = dvd;
945} else if (!strcmp(value, "usb")) {
946 bkpinfo->backup_media_type = usb;
947 bkpinfo->please_dont_eject = TRUE;
948} else if (!strcmp(value, "iso")) {
949/*
950if (am_I_in_disaster_recovery_mode()
951&& !run_program_and_log_output("mount /dev/cdrom "MNT_CDROM, 1)
952&& does_file_exist(MNT_CDROM"/archives/filelist.0"))
953*/
954
955// Patch by Conor Daly - 2004/07/12
956 bkpinfo->backup_media_type = iso;
957 if (am_I_in_disaster_recovery_mode()) {
958 /* Check to see if CD is already mounted before mounting it... */
959 if (!is_this_device_mounted("/dev/cdrom")) {
960 log_msg(2,
961 "NB: CDROM device not mounted, mounting...");
962 run_program_and_log_output("mount /dev/cdrom "
963 MNT_CDROM, 1);
964 }
965 if (does_file_exist(MNT_CDROM "/archives/filelist.0")) {
966 bkpinfo->backup_media_type = cdr;
967 run_program_and_log_output("umount " MNT_CDROM, 1);
968 log_it
969 ("Re-jigging configuration AGAIN. CD-R, not ISO.");
970 }
971 }
972 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
973 strcpy(bkpinfo->prefix,value);
974 } else {
975 strcpy(bkpinfo->prefix,STD_PREFIX);
976 }
977} else if (!strcmp(value, "nfs")) {
978 bkpinfo->backup_media_type = nfs;
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
1477 malloc_string(device);
1478 malloc_string(tmp);
1479 malloc_string(name);
1480 backup_crucial_file(MNT_RESTORING, "/etc/fstab");
1481 backup_crucial_file(MNT_RESTORING, "/etc/grub.conf");
1482 backup_crucial_file(MNT_RESTORING, "/etc/lilo.conf");
1483 backup_crucial_file(MNT_RESTORING, "/etc/elilo.conf");
1484 read_cfg_var(g_mondo_cfg_file, "bootloader.device", device);
1485 read_cfg_var(g_mondo_cfg_file, "bootloader.name", name);
1486 sprintf(tmp, "run_boot_loader: device='%s', name='%s'", device, name);
1487 log_msg(2, tmp);
1488 system("sync");
1489 if (!strcmp(name, "LILO")) {
1490 res = run_lilo(offer_to_hack_scripts);
1491 } else if (!strcmp(name, "ELILO")) {
1492 res = run_elilo(offer_to_hack_scripts);
1493 } else if (!strcmp(name, "GRUB")) {
1494// if ( does_file_exist(DO_MBR_PLEASE) || (offer_to_hack_scripts && ask_me_yes_or_no("Because of bugs in GRUB, you're much better off running mondorestore --mbr after this program terminates. Are you sure you want to install GRUB right now?")))
1495// {
1496 res = run_grub(offer_to_hack_scripts, device);
1497// unlink(DO_MBR_PLEASE);
1498// }
1499// else
1500// {
1501// log_msg(1, "Not running run_grub(). Was a bad idea anyway.");
1502// res = 1;
1503// }
1504 } else if (!strcmp(name, "RAW")) {
1505 res = run_raw_mbr(offer_to_hack_scripts, device);
1506 }
1507#ifdef __FreeBSD__
1508 else if (!strcmp(name, "BOOT0")) {
1509 sprintf(tmp, "boot0cfg -B %s", device);
1510 res = run_program_and_log_output(tmp, FALSE);
1511 } else {
1512 sprintf(tmp, "ls /dev | grep -Eq '^%ss[1-4].*'", device);
1513 if (!system(tmp)) {
1514 sprintf(tmp, MNT_RESTORING "/sbin/fdisk -B %s", device);
1515 res = run_program_and_log_output(tmp, 3);
1516 } else {
1517 log_msg(1,
1518 "I'm not running any boot loader. You have a DD boot drive. It's already loaded up.");
1519 }
1520 }
1521#else
1522 else {
1523 log_to_screen
1524 ("Unable to determine type of boot loader. Defaulting to LILO.");
1525 res = run_lilo(offer_to_hack_scripts);
1526 }
1527#endif
1528 retval += res;
1529 if (res) {
1530 log_to_screen("Your boot loader returned an error");
1531 } else {
1532 log_to_screen("Your boot loader ran OK");
1533 }
1534 paranoid_free(device);
1535 paranoid_free(tmp);
1536 paranoid_free(name);
1537 return (retval);
1538}
1539
1540/**************************************************************************
1541 *END_ RUN_BOOT_LOADER *
1542 **************************************************************************/
1543
1544
1545
1546/**
1547 * Attempt to find the user's editor.
1548 * @return The editor found ("vi" if none could be found).
1549 * @note The returned string points to static storage that will be overwritten with each call.
1550 */
1551char *find_my_editor(void)
1552{
1553 static char output[MAX_STR_LEN];
1554 if (find_home_of_exe("pico")) {
1555 strcpy(output, "pico");
1556 } else if (find_home_of_exe("nano")) {
1557 strcpy(output, "nano");
1558 } else if (find_home_of_exe("e3em")) {
1559 strcpy(output, "e3em");
1560 } else if (find_home_of_exe("e3vi")) {
1561 strcpy(output, "e3vi");
1562 } else {
1563 strcpy(output, "vi");
1564 }
1565 if (!find_home_of_exe(output)) {
1566 log_msg(2, " (find_my_editor) --- warning - %s not found", output);
1567 }
1568 return (output);
1569}
1570
1571
1572/**
1573 * Install GRUB on @p bd.
1574 * @param offer_to_run_stabgrub If TRUE, then offer to hack the user's fstab for them.
1575 * @param bd The boot device where GRUB is installed.
1576 * @return 0 for success, nonzero for failure.
1577 */
1578int run_grub(bool offer_to_run_stabgrub, char *bd)
1579{
1580 /** malloc **/
1581 char *command;
1582 char *boot_device;
1583 char *rootdev;
1584 char *rootdrive;
1585 char *conffile;
1586 char *tmp;
1587 char *editor;
1588
1589 int res;
1590 int done;
1591
1592 malloc_string(command);
1593 malloc_string(boot_device);
1594 malloc_string(tmp);
1595 malloc_string(editor);
1596 malloc_string(rootdev);
1597 malloc_string(rootdrive);
1598 malloc_string(conffile);
1599 assert_string_is_neither_NULL_nor_zerolength(bd);
1600 strcpy(editor, find_my_editor());
1601 strcpy(boot_device, bd);
1602
1603 if (!run_program_and_log_output("which grub-MR", FALSE)) {
1604 log_msg(1, "Yay! grub-MR found...");
1605 sprintf(command, "grub-MR %s /tmp/mountlist.txt", boot_device);
1606 log_msg(1, "command = %s", command);
1607 } else {
1608 sprintf(command, "chroot " MNT_RESTORING " grub-install %s",
1609 boot_device);
1610 log_msg(1, "WARNING - grub-MR not found; using grub-install");
1611 }
1612 if (offer_to_run_stabgrub
1613 && ask_me_yes_or_no("Did you change the mountlist?"))
1614 /* interactive mode */
1615 {
1616 mvaddstr_and_log_it(g_currentY,
1617 0,
1618 "Modifying fstab, mtab, device.map and grub.conf, and running GRUB... ");
1619 for (done = FALSE; !done;) {
1620 popup_and_get_string("Boot device",
1621 "Please confirm/enter the boot device. If in doubt, try /dev/hda",
1622 boot_device, MAX_STR_LEN / 4);
1623 sprintf(command, "stabgrub-me %s", boot_device);
1624 res = run_program_and_log_output(command, 1);
1625 if (res) {
1626 popup_and_OK
1627 ("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.");
1628 newtSuspend();
1629 system("chroot " MNT_RESTORING);
1630 newtResume();
1631 popup_and_OK("Thank you.");
1632 } else {
1633 done = TRUE;
1634 }
1635 popup_and_OK("You will now edit fstab, mtab, device.map and grub.conf");
1636 if (!g_text_mode) {
1637 newtSuspend();
1638 }
1639 sprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
1640 paranoid_system(tmp);
1641 sprintf(tmp, "chroot %s %s /etc/mtab", MNT_RESTORING, editor);
1642 paranoid_system(tmp);
1643 sprintf(tmp, "chroot %s %s /etc/grub.conf", MNT_RESTORING, editor);
1644 paranoid_system(tmp);
1645 sprintf(tmp, "chroot %s %s /boot/grub/device.map", MNT_RESTORING, editor);
1646 paranoid_system(tmp);
1647 if (!g_text_mode) {
1648 newtResume();
1649 }
1650 }
1651 } else
1652 /* nuke mode */
1653 {
1654 mvaddstr_and_log_it(g_currentY,
1655 0,
1656 "Running GRUB... ");
1657 iamhere(command);
1658 res = run_program_and_log_output(command, 1);
1659 if (res) {
1660 popup_and_OK
1661 ("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.");
1662 newtSuspend();
1663 system("chroot " MNT_RESTORING);
1664 newtResume();
1665 popup_and_OK("Thank you.");
1666 }
1667 }
1668 if (res) {
1669 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
1670 log_to_screen
1671 ("GRUB ran w/error(s). See %s for more info.", MONDO_LOGFILE);
1672 log_msg(1, "Type:-");
1673 log_msg(1, " mount-me");
1674 log_msg(1, " chroot " MNT_RESTORING);
1675 log_msg(1, " mount /boot");
1676 log_msg(1, " grub-install '(hd0)'");
1677 log_msg(1, " exit");
1678 log_msg(1, " unmount-me");
1679 log_msg(1,
1680 "If you're really stuck, please e-mail the mailing list.");
1681 } else {
1682 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1683 }
1684 paranoid_free(rootdev);
1685 paranoid_free(rootdrive);
1686 paranoid_free(conffile);
1687 paranoid_free(command);
1688 paranoid_free(boot_device);
1689 paranoid_free(tmp);
1690 paranoid_free(editor);
1691
1692 return (res);
1693}
1694
1695/**************************************************************************
1696 *END_RUN_GRUB *
1697 **************************************************************************/
1698
1699
1700/**
1701 * Install ELILO on the user's boot drive (determined by elilo.conf).
1702 * @param offer_to_run_stabelilo If TRUE, then offer to hack the user's fstab for them.
1703 * @return 0 for success, nonzero for failure.
1704 */
1705int run_elilo(bool offer_to_run_stabelilo)
1706{
1707 /** malloc **/
1708 char *command;
1709 char *tmp;
1710 char *editor;
1711
1712 int res;
1713 int done;
1714
1715 malloc_string(command);
1716 malloc_string(tmp);
1717 malloc_string(editor);
1718 strcpy(editor, find_my_editor());
1719 if (offer_to_run_stabelilo
1720 && ask_me_yes_or_no("Did you change the mountlist?"))
1721
1722 /* interactive mode */
1723 {
1724 mvaddstr_and_log_it(g_currentY,
1725 0,
1726 "Modifying fstab and elilo.conf... ");
1727 sprintf(command, "stabelilo-me");
1728 res = run_program_and_log_output(command, 3);
1729 if (res) {
1730 popup_and_OK
1731 ("You will now edit fstab and elilo.conf, to make sure they match your new mountlist.");
1732 for (done = FALSE; !done;) {
1733 if (!g_text_mode) {
1734 newtSuspend();
1735 }
1736 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
1737 paranoid_system(tmp);
1738 sprintf(tmp, "%s " MNT_RESTORING "/etc/elilo.conf",
1739 editor);
1740 paranoid_system(tmp);
1741 if (!g_text_mode) {
1742 newtResume();
1743 }
1744// newtCls();
1745 if (ask_me_yes_or_no("Edit them again?")) {
1746 continue;
1747 }
1748 done = TRUE;
1749 }
1750 } else {
1751 log_to_screen("elilo.conf and fstab were modified OK");
1752 }
1753 } else
1754 /* nuke mode */
1755 {
1756 res = TRUE;
1757 }
1758 paranoid_free(command);
1759 paranoid_free(tmp);
1760 paranoid_free(editor);
1761 return (res);
1762}
1763
1764/**************************************************************************
1765 *END_RUN_ELILO *
1766 **************************************************************************/
1767
1768
1769/**
1770 * Install LILO on the user's boot drive (determined by /etc/lilo.conf).
1771 * @param offer_to_run_stablilo If TRUE, then offer to hack the user's fstab for them.
1772 * @return 0 for success, nonzero for failure.
1773 */
1774int run_lilo(bool offer_to_run_stablilo)
1775{
1776 /** malloc **/
1777 char *command;
1778 char *tmp;
1779 char *editor;
1780
1781 int res;
1782 int done;
1783 bool run_lilo_M = FALSE;
1784 malloc_string(command);
1785 malloc_string(tmp);
1786 malloc_string(editor);
1787
1788 if (!run_program_and_log_output
1789 ("grep \"boot.*=.*/dev/md\" " MNT_RESTORING "/etc/lilo.conf", 1)) {
1790 run_lilo_M = TRUE;
1791 }
1792
1793 strcpy(editor, find_my_editor());
1794 if (offer_to_run_stablilo
1795 && ask_me_yes_or_no("Did you change the mountlist?"))
1796
1797 /* interactive mode */
1798 {
1799 mvaddstr_and_log_it(g_currentY,
1800 0,
1801 "Modifying fstab and lilo.conf, and running LILO... ");
1802 sprintf(command, "stablilo-me");
1803 res = run_program_and_log_output(command, 3);
1804 if (res) {
1805 popup_and_OK
1806 ("You will now edit fstab and lilo.conf, to make sure they match your new mountlist.");
1807 for (done = FALSE; !done;) {
1808 if (!g_text_mode) {
1809 newtSuspend();
1810 }
1811 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
1812 paranoid_system(tmp);
1813 sprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor);
1814 paranoid_system(tmp);
1815 if (!g_text_mode) {
1816 newtResume();
1817 }
1818// newtCls();
1819 if (ask_me_yes_or_no("Edit them again?")) {
1820 continue;
1821 }
1822 res =
1823 run_program_and_log_output("chroot " MNT_RESTORING
1824 " lilo -L", 3);
1825 if (res) {
1826 res =
1827 run_program_and_log_output("chroot " MNT_RESTORING
1828 " lilo", 3);
1829 }
1830 if (res) {
1831 done =
1832 ask_me_yes_or_no
1833 ("LILO failed. Re-edit system files?");
1834 } else {
1835 done = TRUE;
1836 }
1837 }
1838 } else {
1839 log_to_screen("lilo.conf and fstab were modified OK");
1840 }
1841 } else
1842 /* nuke mode */
1843 {
1844 mvaddstr_and_log_it(g_currentY,
1845 0,
1846 "Running LILO... ");
1847 res =
1848 run_program_and_log_output("chroot " MNT_RESTORING " lilo -L",
1849 3);
1850 if (res) {
1851 res =
1852 run_program_and_log_output("chroot " MNT_RESTORING " lilo",
1853 3);
1854 }
1855 if (res) {
1856 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
1857 log_to_screen
1858 ("Failed to re-jig fstab and/or lilo. Edit/run manually, please.");
1859 } else {
1860 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1861 }
1862 }
1863 if (run_lilo_M) {
1864 run_program_and_log_output("chroot " MNT_RESTORING
1865 " lilo -M /dev/hda", 3);
1866 run_program_and_log_output("chroot " MNT_RESTORING
1867 " lilo -M /dev/sda", 3);
1868 }
1869 paranoid_free(command);
1870 paranoid_free(tmp);
1871 paranoid_free(editor);
1872 return (res);
1873}
1874
1875/**************************************************************************
1876 *END_RUN_LILO *
1877 **************************************************************************/
1878
1879
1880/**
1881 * Install a raw MBR onto @p bd.
1882 * @param offer_to_hack_scripts If TRUE, then offer to hack the user's fstab for them.
1883 * @param bd The device to copy the stored MBR to.
1884 * @return 0 for success, nonzero for failure.
1885 */
1886int run_raw_mbr(bool offer_to_hack_scripts, char *bd)
1887{
1888 /** malloc **/
1889 char *command;
1890 char *boot_device;
1891 char *tmp;
1892 char *editor;
1893 int res;
1894 int done;
1895
1896 malloc_string(command);
1897 malloc_string(boot_device);
1898 malloc_string(tmp);
1899 malloc_string(editor);
1900 assert_string_is_neither_NULL_nor_zerolength(bd);
1901
1902 strcpy(editor, find_my_editor());
1903 strcpy(boot_device, bd);
1904 sprintf(command, "raw-MR %s /tmp/mountlist.txt", boot_device);
1905 log_msg(2, "run_raw_mbr() --- command='%s'", command);
1906
1907 if (offer_to_hack_scripts
1908 && ask_me_yes_or_no("Did you change the mountlist?"))
1909 /* interactive mode */
1910 {
1911 mvaddstr_and_log_it(g_currentY, 0,
1912 "Modifying fstab and restoring MBR... ");
1913 for (done = FALSE; !done;) {
1914 if (!run_program_and_log_output("which vi", FALSE)) {
1915 popup_and_OK("You will now edit fstab");
1916 if (!g_text_mode) {
1917 newtSuspend();
1918 }
1919 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
1920 paranoid_system(tmp);
1921 if (!g_text_mode) {
1922 newtResume();
1923 }
1924// newtCls();
1925 }
1926 popup_and_get_string("Boot device",
1927 "Please confirm/enter the boot device. If in doubt, try /dev/hda",
1928 boot_device, MAX_STR_LEN / 4);
1929 sprintf(command, "stabraw-me %s", boot_device);
1930 res = run_program_and_log_output(command, 3);
1931 if (res) {
1932 done = ask_me_yes_or_no("Modifications failed. Re-try?");
1933 } else {
1934 done = TRUE;
1935 }
1936 }
1937 } else
1938 /* nuke mode */
1939 {
1940 mvaddstr_and_log_it(g_currentY, 0,
1941 "Restoring MBR... ");
1942 res = run_program_and_log_output(command, 3);
1943 }
1944 if (res) {
1945 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
1946 log_to_screen
1947 ("MBR+fstab processed w/error(s). See %s for more info.", MONDO_LOGFILE);
1948 } else {
1949 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1950 }
1951 paranoid_free(command);
1952 paranoid_free(boot_device);
1953 paranoid_free(tmp);
1954 paranoid_free(editor);
1955 return (res);
1956}
1957
1958/**************************************************************************
1959 *END_RUN_RAW_MBR *
1960 **************************************************************************/
1961
1962
1963
1964
1965
1966/**
1967 * Turn signal trapping on or off.
1968 * @param on If TRUE, then do full cleanup when we receive a signal; if FALSE, then
1969 * print a message and exit immediately.
1970 */
1971void set_signals(int on)
1972{
1973 int signals[] =
1974 { SIGKILL, SIGPIPE, SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT,
1975SIGSTOP, 0 };
1976 int i;
1977 for (i = 0; signals[i]; i++) {
1978 if (on) {
1979 signal(signals[i], terminate_daemon);
1980 } else {
1981 signal(signals[i], termination_in_progress);
1982 }
1983 }
1984}
1985
1986/**************************************************************************
1987 *END_SET_SIGNALS *
1988 **************************************************************************/
1989
1990
1991/**
1992 * malloc() and set sensible defaults for the mondorestore filename variables.
1993 * @param bkpinfo The backup information structure. Fields used:
1994 * - @c bkpinfo->tmpdir
1995 * - @c bkpinfo->disaster_recovery
1996 */
1997void setup_MR_global_filenames()
1998{
1999 char *temppath;
2000
2001 assert(bkpinfo != NULL);
2002
2003 malloc_string(g_biggielist_txt);
2004 malloc_string(g_filelist_full);
2005 malloc_string(g_filelist_imagedevs);
2006 malloc_string(g_imagedevs_restthese);
2007 malloc_string(g_mondo_cfg_file);
2008 malloc_string(g_mountlist_fname);
2009 malloc_string(g_mondo_home);
2010 malloc_string(g_tmpfs_mountpt);
2011 malloc_string(g_isodir_device);
2012 malloc_string(g_isodir_format);
2013
2014 temppath = bkpinfo->tmpdir;
2015
2016 sprintf(g_biggielist_txt, "%s/%s", temppath, BIGGIELIST_TXT_STUB);
2017 sprintf(g_filelist_full, "%s/%s", temppath, FILELIST_FULL_STUB);
2018 sprintf(g_filelist_imagedevs, "%s/tmp/filelist.imagedevs", temppath);
2019// sprintf(g_imagedevs_pot, "%s/tmp/imagedevs.pot", temppath);
2020 sprintf(g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these",
2021 temppath);
2022 if (bkpinfo->disaster_recovery) {
2023 sprintf(g_mondo_cfg_file, "/%s", MONDO_CFG_FILE_STUB);
2024 sprintf(g_mountlist_fname, "/%s", MOUNTLIST_FNAME_STUB);
2025 } else {
2026 sprintf(g_mondo_cfg_file, "%s/%s", temppath, MONDO_CFG_FILE_STUB);
2027 sprintf(g_mountlist_fname, "%s/%s", temppath,
2028 MOUNTLIST_FNAME_STUB);
2029 }
2030}
2031
2032/**************************************************************************
2033 *END_SET_GLOBAL_FILENAME *
2034 **************************************************************************/
2035
2036
2037/**
2038 * Copy @p input_file (containing the result of a compare) to @p output_file,
2039 * deleting spurious "changes" along the way.
2040 * @param output_file The output file to write with spurious changes removed.
2041 * @param input_file The input file, a list of changed files created by a compare.
2042 */
2043void streamline_changes_file(char *output_file, char *input_file)
2044{
2045 FILE *fin;
2046 FILE *fout;
2047 /** malloc **/
2048 char *incoming;
2049
2050 assert_string_is_neither_NULL_nor_zerolength(output_file);
2051 assert_string_is_neither_NULL_nor_zerolength(input_file);
2052 malloc_string(incoming);
2053
2054 if (!(fin = fopen(input_file, "r"))) {
2055 log_OS_error(input_file);
2056 return;
2057 }
2058 if (!(fout = fopen(output_file, "w"))) {
2059 fatal_error("cannot open output_file");
2060 }
2061 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
2062 fgets(incoming, MAX_STR_LEN - 1, fin)) {
2063 if (strncmp(incoming, "etc/adjtime", 11)
2064 && strncmp(incoming, "etc/mtab", 8)
2065 && strncmp(incoming, "tmp/", 4)
2066 && strncmp(incoming, "boot/map", 8)
2067 && !strstr(incoming, "incheckentry")
2068 && strncmp(incoming, "etc/mail/statistics", 19)
2069 && strncmp(incoming, "var/", 4))
2070 fprintf(fout, "%s", incoming); /* don't need \n here, for some reason.. */
2071 }
2072 paranoid_fclose(fout);
2073 paranoid_fclose(fin);
2074 paranoid_free(incoming);
2075}
2076
2077/**************************************************************************
2078 *END_STREAMLINE_CHANGES_FILE *
2079 **************************************************************************/
2080
2081
2082/**
2083 * Exit due to a signal (normal cleanup).
2084 * @param sig The signal we're exiting due to.
2085 */
2086void terminate_daemon(int sig)
2087{
2088 log_to_screen
2089 ("Mondorestore is terminating in response to a signal from the OS");
2090 paranoid_MR_finish(254);
2091}
2092
2093/**************************************************************************
2094 *END_TERMINATE_DAEMON *
2095 **************************************************************************/
2096
2097
2098/**
2099 * Give the user twenty seconds to press Ctrl-Alt-Del before we nuke their drives.
2100 */
2101void twenty_seconds_til_yikes()
2102{
2103 int i;
2104 /* MALLOC * */
2105 char *tmp;
2106
2107 malloc_string(tmp);
2108 if (does_file_exist("/tmp/NOPAUSE")) {
2109 return;
2110 }
2111 open_progress_form("CAUTION",
2112 "Be advised: I am about to ERASE your hard disk(s)!",
2113 "You may press Ctrl+Alt+Del to abort safely.",
2114 "", 20);
2115 for (i = 0; i < 20; i++) {
2116 g_current_progress = i;
2117 sprintf(tmp, "You have %d seconds left to abort.", 20 - i);
2118 update_progress_form(tmp);
2119 sleep(1);
2120 }
2121 close_progress_form();
2122 paranoid_free(tmp);
2123}
2124
2125/**************************************************************************
2126 *END_TWENTY_SECONDS_TIL_YIKES *
2127 **************************************************************************/
2128
2129
2130
2131
2132
2133/**
2134 * Exit due to a signal (no cleanup).
2135 * @param sig The signal we're exiting due to.
2136 */
2137void termination_in_progress(int sig)
2138{
2139 log_msg(1, "Termination in progress");
2140 usleep(1000);
2141 pthread_exit(0);
2142}
2143
2144/**************************************************************************
2145 *END_TERMINATION_IN_PROGRESS *
2146 **************************************************************************/
2147
2148
2149
2150/**
2151 * Unmount all devices in @p p_external_copy_of_mountlist.
2152 * @param p_external_copy_of_mountlist The mountlist to guide the devices to unmount.
2153 * @return 0 for success, nonzero for failure.
2154 */
2155int unmount_all_devices(struct mountlist_itself
2156 *p_external_copy_of_mountlist)
2157{
2158 struct mountlist_itself *mountlist;
2159 int retval = 0, lino, res = 0, i;
2160 char *command;
2161 char *tmp;
2162
2163 malloc_string(command);
2164 malloc_string(tmp);
2165 assert(p_external_copy_of_mountlist != NULL);
2166
2167 mountlist = malloc(sizeof(struct mountlist_itself));
2168 memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist,
2169 sizeof(struct mountlist_itself));
2170 sort_mountlist_by_mountpoint(mountlist, 0);
2171
2172 run_program_and_log_output("df -m", 3);
2173 mvaddstr_and_log_it(g_currentY, 0, "Unmounting devices ");
2174 open_progress_form("Unmounting devices",
2175 "Unmounting all devices that were mounted,",
2176 "in preparation for the post-restoration reboot.",
2177 "", mountlist->entries);
2178 chdir("/");
2179 for (i = 0;
2180 i < 10
2181 &&
2182 run_program_and_log_output
2183 ("ps | grep buffer | grep -v \"grep buffer\"", TRUE) == 0;
2184 i++) {
2185 sleep(1);
2186 log_msg(2, "Waiting for buffer() to finish");
2187 }
2188
2189 paranoid_system("sync");
2190
2191 sprintf(tmp, "cp -f %s " MNT_RESTORING "/var/log", MONDO_LOGFILE);
2192 if (run_program_and_log_output(tmp, FALSE)) {
2193 log_msg(1,
2194 "Error. Failed to copy log to PC's /var/log dir. (Mounted read-only?)");
2195 }
2196 if (does_file_exist("/tmp/DUMBASS-GENTOO")) {
2197 run_program_and_log_output("mkdir -p " MNT_RESTORING
2198 "/mnt/.boot.d", 5);
2199 }
2200 for (lino = mountlist->entries - 1; lino >= 0; lino--) {
2201 if (!strcmp(mountlist->el[lino].mountpoint, "lvm")) {
2202 continue;
2203 }
2204 sprintf(tmp, "Unmounting device %s ", mountlist->el[lino].device);
2205
2206 update_progress_form(tmp);
2207 if (is_this_device_mounted(mountlist->el[lino].device)) {
2208 if (!strcmp(mountlist->el[lino].mountpoint, "swap")) {
2209 sprintf(command, "swapoff %s", mountlist->el[lino].device);
2210 } else {
2211 if (!strcmp(mountlist->el[lino].mountpoint, "/1")) {
2212 sprintf(command, "umount %s/", MNT_RESTORING);
2213 log_msg(3,
2214 "Well, I know a certain kitty-kitty who'll be sleeping with Mommy tonight...");
2215 } else {
2216 sprintf(command, "umount " MNT_RESTORING "%s",
2217 mountlist->el[lino].mountpoint);
2218 }
2219 }
2220 log_msg(10, "The 'umount' command is '%s'", command);
2221 res = run_program_and_log_output(command, 3);
2222 } else {
2223 strcat(tmp, "...not mounted anyway :-) OK");
2224 res = 0;
2225 }
2226 g_current_progress++;
2227 if (res) {
2228 strcat(tmp, "...Failed");
2229 retval++;
2230 log_to_screen(tmp);
2231 } else {
2232 log_msg(2, tmp);
2233 }
2234 }
2235 close_progress_form();
2236 if (retval) {
2237 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
2238 } else {
2239 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2240 }
2241 if (retval) {
2242 log_to_screen("Unable to unmount some of your partitions.");
2243 } else {
2244 log_to_screen("All partitions were unmounted OK.");
2245 }
2246 free(mountlist);
2247 paranoid_free(command);
2248 paranoid_free(tmp);
2249 return (retval);
2250}
2251
2252/**************************************************************************
2253 *END_UNMOUNT_ALL_DEVICES *
2254 **************************************************************************/
2255
2256
2257
2258/**
2259 * Extract mondo-restore.cfg and the mountlist from the tape inserted
2260 * to the ./tmp/ directory.
2261 * @param dev The tape device to read from.
2262 * @return 0 for success, nonzero for failure.
2263 */
2264int extract_cfg_file_and_mountlist_from_tape_dev(char *dev)
2265{
2266 char *command;
2267 int res = 0;
2268 // BCO: below 32KB seems to block at least on RHAS 2.1 and MDK 10.0
2269 long tape_block_size = 32768;
2270
2271 malloc_string(command);
2272
2273 // tar -zxvf-
2274 sprintf(command,
2275 "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx %s %s %s %s %s",
2276 dev,
2277 tape_block_size,
2278 1024L * 1024 * 32 / tape_block_size,
2279 MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB,
2280 BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, "tmp/i-want-my-lvm");
2281 log_msg(2, "command = '%s'", command);
2282 res = run_program_and_log_output(command, -1);
2283 if (res != 0 && does_file_exist(MONDO_CFG_FILE_STUB)) {
2284 res = 0;
2285 }
2286 paranoid_free(command);
2287 return (res);
2288}
2289
2290
2291
2292/**
2293 * Get the configuration file from the floppy, tape, or CD.
2294 * @param bkpinfo The backup information structure. Fields used:
2295 * - @c bkpinfo->backup_media_type
2296 * - @c bkpinfo->media_device
2297 * - @c bkpinfo->tmpdir
2298 * @return 0 for success, nonzero for failure.
2299 */
2300int get_cfg_file_from_archive()
2301{
2302 int retval = 0;
2303
2304 /** malloc *****/
2305 char *device;
2306 char *command;
2307 char *cfg_file;
2308 char *mounted_cfgf_path;
2309 char *tmp;
2310 char *mountpt;
2311 char *ramdisk_fname;
2312 char *mountlist_file;
2313 int res;
2314
2315 bool try_plan_B;
2316
2317 assert(bkpinfo != NULL);
2318 malloc_string(cfg_file);
2319 malloc_string(mounted_cfgf_path);
2320 malloc_string(mountpt);
2321 malloc_string(ramdisk_fname);
2322 malloc_string(mountlist_file);
2323 malloc_string(device);
2324 malloc_string(command);
2325 malloc_string(tmp);
2326 log_msg(2, "gcffa --- starting");
2327 log_to_screen("I'm thinking...");
2328 sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
2329 device[0] = '\0';
2330 chdir(bkpinfo->tmpdir);
2331 strcpy(cfg_file, MONDO_CFG_FILE_STUB);
2332 unlink(cfg_file); // cfg_file[] is missing the '/' at the start, FYI, by intent
2333 unlink(FILELIST_FULL_STUB);
2334 unlink(BIGGIELIST_TXT_STUB);
2335 unlink("tmp/i-want-my-lvm");
2336 sprintf(command, "mkdir -p %s", mountpt);
2337 run_program_and_log_output(command, FALSE);
2338
2339// unlink( "tmp/mondo-restore.cfg" ); // superfluous, surely?
2340
2341 sprintf(cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB);
2342 sprintf(mountlist_file, "%s/%s", bkpinfo->tmpdir,
2343 MOUNTLIST_FNAME_STUB);
2344 // make_hole_for_file( cfg_file );
2345 // make_hole_for_file( mountlist_file);
2346 log_msg(2, "mountpt = %s; cfg_file=%s", mountpt, cfg_file);
2347
2348 /* Floppy? */
2349 sprintf(tmp, "mkdir -p %s", mountpt);
2350 run_program_and_log_output(tmp, FALSE);
2351 sprintf(tmp, "mkdir -p %s/tmp", bkpinfo->tmpdir);
2352 run_program_and_log_output(tmp, FALSE);
2353
2354 /* Is there a floppy drive detected */
2355 sprintf(tmp, "%s", call_program_and_get_last_line_of_output("dmesg | grep -i floppy"));
2356 if (strcmp(tmp, "")) {
2357 sprintf(command, "mount /dev/fd0u1722 %s", mountpt);
2358 sprintf(tmp,
2359 "(sleep 15; kill `ps | grep \"%s\" | cut -d' ' -f1` 2> /dev/null) &",
2360 command);
2361 log_msg(1, "tmp = '%s'", tmp);
2362 system(tmp);
2363 res = run_program_and_log_output(command, FALSE);
2364 if (res) {
2365 sprintf(command, "mount /dev/fd0H1440 %s", mountpt);
2366 res = run_program_and_log_output(command, FALSE);
2367 }
2368 } else {
2369 res = 1;
2370 }
2371 if (res) {
2372 try_plan_B = TRUE;
2373 } else {
2374 try_plan_B = TRUE;
2375 log_msg(2,
2376 "Mounted floppy OK but I don't trust it because the archives might contain more up-to-date config file than the floppy does.");
2377 // NB: If busybox does not support 'mount -o loop' then Plan A WILL NOT WORK.
2378 log_msg(2, "Processing floppy (plan A?)");
2379 sprintf(ramdisk_fname, "%s/mindi.rdz", mountpt);
2380 if (!does_file_exist(ramdisk_fname)) {
2381 sprintf(ramdisk_fname, "%s/initrd.img", mountpt);
2382 }
2383 if (!does_file_exist(ramdisk_fname)) {
2384 log_msg(2,
2385 "Cannot find ramdisk file on mountpoint. Are you sure that's a boot disk in the drive?");
2386 }
2387 if (extract_config_file_from_ramdisk(ramdisk_fname, cfg_file, mountlist_file)) {
2388 log_msg(2,
2389 "Warning - failed to extract config file from ramdisk. I think this boot disk is mangled.");
2390 }
2391 sprintf(command, "umount %s", mountpt);
2392 run_program_and_log_output(command, 5);
2393 unlink(ramdisk_fname);
2394 }
2395 if (!does_file_exist(cfg_file)) {
2396 log_msg(2, "gcffa --- we don't have cfg file yet.");
2397 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2398 try_plan_B = TRUE;
2399 } else {
2400 log_msg(2, "gcffa --- calling mount_media now :)");
2401 if (!mount_media()) {
2402 log_msg(2,
2403 "gcffa --- managed to mount CD; so, no need for Plan B");
2404 try_plan_B = FALSE;
2405 } else {
2406 try_plan_B = TRUE;
2407 }
2408 if (what_number_cd_is_this() > 1) {
2409 insist_on_this_cd_number((g_current_media_number = 1));
2410 }
2411 }
2412 if (try_plan_B) {
2413 log_msg(2, "gcffa --- OK, switching to Plan B");
2414 chdir(bkpinfo->tmpdir);
2415 run_program_and_log_output("mkdir -p tmp", FALSE);
2416
2417 if (strlen(bkpinfo->media_device) == 0) {
2418 strcpy(bkpinfo->media_device, "/dev/st0");
2419 log_msg(2, "media_device is blank; assuming %s");
2420 }
2421 strcpy(tmp, bkpinfo->media_device);
2422 if (extract_cfg_file_and_mountlist_from_tape_dev
2423 (bkpinfo->media_device)) {
2424 strcpy(bkpinfo->media_device, "/dev/st0");
2425 if (extract_cfg_file_and_mountlist_from_tape_dev
2426 (bkpinfo->media_device)) {
2427 strcpy(bkpinfo->media_device, "/dev/osst0");
2428 if (extract_cfg_file_and_mountlist_from_tape_dev
2429 (bkpinfo->media_device)) {
2430 strcpy(bkpinfo->media_device, "/dev/ht0");
2431 if (extract_cfg_file_and_mountlist_from_tape_dev
2432 (bkpinfo->media_device)) {
2433 log_msg(3,
2434 "I tried lots of devices but none worked.");
2435 strcpy(bkpinfo->media_device, tmp);
2436 }
2437 }
2438 }
2439 }
2440
2441 if (!does_file_exist("tmp/mondo-restore.cfg")) {
2442 log_to_screen("Cannot find config info on tape/CD/floppy");
2443 return (1);
2444 }
2445 } else {
2446 /* That boot imae doesn't always exist where the following method always works
2447 log_msg(2,
2448 "gcffa --- looking at mounted CD for mindi-boot.2880.img");
2449 sprintf(command,
2450 "mount " MNT_CDROM
2451 "/images/mindi-boot.2880.img -o loop %s", mountpt);
2452 sprintf(mounted_cfgf_path, "%s/%s", mountpt, cfg_file);
2453 if (!does_file_exist(mounted_cfgf_path)) {
2454 */
2455 log_msg(2,
2456 "gcffa --- Plan B, a.k.a. untarring some file from all.tar.gz");
2457 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
2458 run_program_and_log_output(command, TRUE);
2459 if (!does_file_exist(MONDO_CFG_FILE_STUB)) {
2460 fatal_error
2461 ("Please reinsert the disk/CD and try again.");
2462 }
2463 /*
2464 }
2465 */
2466 }
2467 }
2468 if (does_file_exist(MONDO_CFG_FILE_STUB)) {
2469 log_msg(1, "gcffa --- great! We've got the config file");
2470 sprintf(tmp, "%s/%s",
2471 call_program_and_get_last_line_of_output("pwd"),
2472 MONDO_CFG_FILE_STUB);
2473 sprintf(command, "cp -f %s %s", tmp, cfg_file);
2474 iamhere(command);
2475 if (strcmp(tmp, cfg_file)
2476 && run_program_and_log_output(command, 1)) {
2477 log_msg(1,
2478 "... but an error occurred when I tried to move it to %s",
2479 cfg_file);
2480 } else {
2481 log_msg(1, "... and I moved it successfully to %s", cfg_file);
2482 }
2483 sprintf(command, "cp -f %s/%s %s",
2484 call_program_and_get_last_line_of_output("pwd"),
2485 MOUNTLIST_FNAME_STUB, mountlist_file);
2486 iamhere(command);
2487 if (strcmp(tmp, cfg_file)
2488 && run_program_and_log_output(command, 1)) {
2489 log_msg(1, "Failed to get mountlist");
2490 } else {
2491 log_msg(1, "Got mountlist too");
2492 sprintf(command, "cp -f %s %s", mountlist_file,
2493 g_mountlist_fname);
2494 if (run_program_and_log_output(command, 1)) {
2495 log_msg(1, "Failed to copy mountlist to /tmp");
2496 } else {
2497 log_msg(1, "Copied mountlist to /tmp as well OK");
2498 sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/");
2499 run_program_and_log_output(command, 1);
2500/* sprintf(command, "grep \" lvm \" %s", g_mountlist_fname);
2501 if (!run_program_and_log_output(command, 5) && !does_file_exist("/tmp/i-want-my-lvm"))
2502 {
2503 log_msg(1, "Warning. You want LVM but I don't have i-want-my-lvm. FIXME.");
2504 }
2505 else if (run_program_and_log_output(command,5) && does_file_exist("/tmp/i-want-my-lvm"))
2506 {
2507 log_msg(1, "Warning. You don't want LVM but i-want-my-lvm exists. I'll delete it. Cool.");
2508 do_my_funky_lvm_stuff(TRUE, FALSE); // ...after I stop any LVMs :)
2509 stop_raid_device("/dev/md0");
2510 stop_raid_device("/dev/md1");
2511 stop_raid_device("/dev/md2");
2512 unlink("/tmp/i-want-my-lvm");
2513 }
2514 else if (!run_program_and_log_output(command,5) && does_file_exist("/tmp/i-want-my-lvm"))
2515 {
2516 log_msg(1, "You had better pray that i-want-my-lvm patches your mountlist. FIXME.");
2517 }
2518*/
2519 }
2520 }
2521 }
2522 run_program_and_log_output("umount " MNT_CDROM, FALSE);
2523 if (!does_file_exist(cfg_file)) {
2524 iamhere(cfg_file);
2525 log_msg(1, "%s not found", cfg_file);
2526 log_to_screen
2527 ("Oh dear. Unable to recover configuration file from boot disk");
2528 return (1);
2529 }
2530
2531 log_to_screen("Recovered mondo-restore.cfg");
2532 if (!does_file_exist(MOUNTLIST_FNAME_STUB)) {
2533 log_to_screen("...but not mountlist.txt - a pity, really...");
2534 }
2535/* start SAH */
2536 else {
2537 sprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB,
2538 bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
2539 run_program_and_log_output(command, FALSE);
2540 }
2541/*--commented out by SAH
2542 sprintf( command, "cp -f %s %s/%s", cfg_file, bkpinfo->tmpdir, MONDO_CFG_FILE_STUB );
2543 run_program_and_log_output( command, FALSE );
2544 sprintf( command, "cp -f %s %s/%s", mountlist_file, bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB );
2545 run_program_and_log_output( command, FALSE );
2546*/
2547/* end SAH */
2548
2549 sprintf(command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB);
2550 run_program_and_log_output(command, FALSE);
2551 sprintf(command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB);
2552 run_program_and_log_output(command, FALSE);
2553 sprintf(command, "cp -f etc/raidtab /etc/");
2554 run_program_and_log_output(command, FALSE);
2555 sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/");
2556 run_program_and_log_output(command, FALSE);
2557 g_backup_media_type = bkpinfo->backup_media_type;
2558 paranoid_free(device);
2559 paranoid_free(command);
2560 paranoid_free(tmp);
2561 paranoid_free(cfg_file);
2562 paranoid_free(mounted_cfgf_path);
2563 paranoid_free(mountpt);
2564 paranoid_free(ramdisk_fname);
2565 paranoid_free(mountlist_file);
2566 return (retval);
2567}
2568
2569/**************************************************************************
2570 *END_GET_CFG_FILE_FROM_ARCHIVE *
2571 **************************************************************************/
2572
2573/* @} - end restoreUtilityGroup */
2574
2575
2576/***************************************************************************
2577 * F@ *
2578 * () -- Hugo Rabson *
2579 * *
2580 * Purpose: *
2581 * *
2582 * Called by: *
2583 * Params: - - *
2584 * Returns: 0=success; nonzero=failure *
2585 ***************************************************************************/
2586
2587
2588
2589void wait_until_software_raids_are_prepped(char *mdstat_file,
2590 int wait_for_percentage)
2591{
2592 struct raidlist_itself *raidlist;
2593 int unfinished_mdstat_devices = 9999, i;
2594 char *screen_message;
2595
2596 malloc_string(screen_message);
2597 raidlist = malloc(sizeof(struct raidlist_itself));
2598
2599 assert(wait_for_percentage <= 100);
2600 iamhere("wait_until_software_raids_are_prepped");
2601 while (unfinished_mdstat_devices > 0) {
2602 // FIXME: Prefix '/dev/' should really be dynamic!
2603 if (parse_mdstat(raidlist, "/dev/")) {
2604 log_to_screen("Sorry, cannot read %s", MDSTAT_FILE);
2605 log_msg(1,"Sorry, cannot read %s", MDSTAT_FILE);
2606 return;
2607 }
2608 for (unfinished_mdstat_devices = i = 0; i <= raidlist->entries; i++) {
2609 if (raidlist->el[i].progress < wait_for_percentage) {
2610 unfinished_mdstat_devices++;
2611 if (raidlist->el[i].progress == -1) // delayed while another partition inits
2612 {
2613 continue;
2614 }
2615 log_msg(1,"Sync'ing %s (i=%d)", raidlist->el[i].raid_device, i);
2616 sprintf(screen_message, "Sync'ing %s",
2617 raidlist->el[i].raid_device);
2618 open_evalcall_form(screen_message);
2619 while (raidlist->el[i].progress < wait_for_percentage) {
2620 log_msg(1,"Percentage sync'ed: %d", raidlist->el[i].progress);
2621 update_evalcall_form(raidlist->el[i].progress);
2622 sleep(2);
2623 // FIXME: Prefix '/dev/' should really be dynamic!
2624 if (parse_mdstat(raidlist, "/dev/")) {
2625 break;
2626 }
2627 }
2628 close_evalcall_form();
2629 }
2630 }
2631 }
2632 paranoid_free(screen_message);
2633 paranoid_free(raidlist);
2634}
Note: See TracBrowser for help on using the repository browser.