source: MondoRescue/branches/3.1/mondo/src/mondorestore/mondorestore.c@ 2937

Last change on this file since 2937 was 2937, checked in by Bruno Cornec, 12 years ago

svn merge -r 2849:2935 ../3.0

  • Adds 3 binaries called potentially by udev o support USB key mount at restore time (Victor Gattegno)
  • mindi only sets the boot flag of a USB device if none is present already (should avoid flip/flop situation)
  • Fix a compatibility bug in analyze-my-lvm whete exclude lists with '|' was incorrectly analyzed (' ' still expected)
  • Precise that -J is not supported by mondorestore yet.
  • Fix a compatibility bug in mindi where exclude lists with '|' was incorrectly analyzed (' ' still expected)
  • Install an MBR on USB devices when possible
  • Improve error message in case mondorestore isn't found
  • Adds support for more virtio devices for KVM restore
  • Improve mbr.bin handling
  • Fix an issue in test of FindKernel for Xen and non Xen cases
    • Fix #492 by removing an extra useless fi
    • Move fvat nd fat modules to CDROM_MODS in order to have them in the initrd to support saving logs to a USB device e.g.
    • Fix an error when dmidecode reports comments before system name
    • Fix previous broken patch on comment management for bkphw
    • Improve msgs printed during kbd analysis
    • Fix a small remaining pb with new comment support
    • Try to again improve the mount/umount stuff in mondo -Adds mention to OEL, CentOS, ScientifLinux as RHEL clones
  • Fix a panadoid_free done on the wrong variable (solve a memory leak)
  • Solve #495 by skipping the potential (auto-read-only) when analyzin /proc/mdstat result
  • Fix some markup in man pages
  • adds the post-nuke script sample for Debian (Guillaume Pernot/Andrée Leidenfrost)
  • Avoid a useless umount when changing of afio set, let insist_on_cd check and perform if needed
  • Copy everything under .ssh of root account to allow for sshfs mount without passwd at restore time.
  • Adds support for bnx2i driver
  • Try to fix #496 by supporting the protocol in the output of the mount command (sshfs#...)
  • Uses the -d option of the mount command to avoid leaving loop devices in use. Probably provoked by the usage of a more recent busybox, but anyway that option doesn't hurt, and does nothing for non-loop devices. Should fix the problems reported on the ML with NFS and more than 8 ISO images (8 being the default number of loop devices available)
  • Attempt to fix #436 by adding some newtDrawForm where appropriate.
  • Fix bugs in the kernel detection routine of mindi (some echo were done without capturing their output, confusing the return). This should also help the Xen detection issue
  • Change the logging function to be nearer from 2.2.10, and start using some
  • Initialize some global fields with an empty string, now that newt Draws more regularly progress forms
  • Mindi progression still not good, but showing now 3% when calling mindi. Would need a specific handling for the progress bar to evolve more afterwards
  • Add compatibility with the latest SSSTK + PSP content for HP ProLiant + branding homogeneous now. We only take conrep out of the SSSTK pending a package availability. Using hpacuscripting now. Review of parameters called following test made.
  • Fix #501 by pushing BOOT_SIZE to 36864 for certain Ubuntu cases
  • Fix some remaining inconsistencis in the ProLiant HW backup. ready for usage.
  • Fix an issue on udevadm call (needs an intermediate variable)
  • Fix a remaining ProLiant tool call
  • Remove again some wrong variable initialization for Net in order to not have strange messages now we call Draw more often
  • Adds support for hwaddr (MAC addresses) at restore time, and map to the correct NIC if it's found at restore time (based on code from Stefan Heijmans)
  • Try to Fix #499 by changing init in order to never exit, and rebooting using sysrq in /proc (not portable). Maybe should move to using a real init, and a separated rcS script.
  • Fixes the shell msg error by using setsid as per Busybox FAQ
  • Fix #491 by correctly checking Xen kernel used for a dom0 env (apollo13)
  • Improves logging in Die()
  • Improve again ProLiant HW support, by adding references to the yet to come SSSTK rpm so that conrep is called at its future right place.
  • Improve mindi support for kernel 3.x
  • Fix #499 for good, by using a real init from busybox and moving our init script to etc/init.d/rcS. We also now call the reboot from busybox to exit, which indeed reset the system correctly (in a VM at least which wasn't the case before). Reauires a new mindi-busybox as well.
  • Attempt to solve #503 by handling /lib64 separately for udev and only if not a link (to /lib) for Ubuntu 64
  • Improve again previous tests for bug #503
  • Improve -d option description for NFS
  • Allow http download for ftp content
  • New italian mirror
  • Fix #505 by documenting environment variables
    • Fix a bug where on OBDR mode compression was turned off to create the OBDR content but not back on (report from the mailing list)
  • solve http://trac.mondorescue.org/ticket/520 by Victor Gattegno
  • Fix #524 as option -U needs a size also
  • Removes useless gendf option
  • Fix #511 now stabgrub is called also after conf file modifications
  • Adds support for SUID binaries
  • remove a useless xenkernelname variable from mindi
  • Should fix #512 by clearing old scratchdir before changing to a new
  • Simplify the function engaging SCSI for Smart Array controllers, and support as many controller as we have
  • Add some binaries used on SLES 10 by udev
  • Fix a syntax issue in newt-specific.c
  • Fix a memory free bug where a used variable was freed to early
  • Fix a memory free bug where a used variable was misused in asprintf/free
  • Fix #498 by using an external program (hpsa_obdr_mode) which can set the mode of the tape to CD-ROM or Sequential at will.

That program will have to be downloaded from http://cciss.sf.net

  • Adds support for the route command in mindi-busybox
  • Force block size back to 32768 in OBDR mode after skipping the 2 tape marks, to read the additional rootfs data corerctly - Fix #498 for good it seems
  • Adds support for a new pata_atiixp driver
  • Fix #525 and improve printing when no /etc/raidtab, but still md devices
  • Exclude /run similarly to /sys and /proc
  • Fix a bug in mindi when having multiple swap partiions with same starting string (/dev/dm-1 and /dev/dm-16). We now add a space in the grep to avoid mischoice.
  • Fix grub installation if we had to go in the hack part which wasn't using the correct variables to make decisions !
  • Remove all mention of mondorescue.com from code
  • Fix some website typo on the download page and precise that we now develop on Mageia
  • Exclude sysfs devpts and tmpfs partitions found in RHEL 6.2 from analyze by mindi (made error messages)
  • Force activation of first partition which should not be optional as everything is destroyed before
  • Fix a bug in analyze-my-lvm where LVs were created in random order (the one of lvscan) instead of using the dm-xxx order, which creates issues at restore time between the mapping created then and the one we had at backup time which could be inconssistent

-mondoarchive now exists if the mt command is missing when needed

  • Proper fix for analyze-my-lvm
  • Fix #500 and #473 by adding support of old metadata format for mdadm if using grub < 0.9x or lilo on a md boot device (to be tested)
  • Really never inject or eject when the -e option is passed or device is inappropriate (USB, Net, ...)
  • Fix #577 by having factor back as a float (not a long ! it's a decimal value) and making the appropriate cast.
  • Fix #578 by improving the regexp used for CD/DVD detection with -scanbus option
  • Adds more verbosity when LVM creation fails.
  • Fix #579 by checking with pipes on both sides of the string
  • debugfs should be excluded from the device considered for fstab analysis
  • Property svn:keywords set to Id
File size: 93.1 KB
Line 
1/***************************************************************************
2$Id: mondorestore.c 2937 2012-01-28 00:51:28Z bruno $
3restores mondoarchive data
4The main file for mondorestore.
5***************************************************************************/
6
7/**************************************************************************
8 * #include statements *
9 **************************************************************************/
10#include <pthread.h>
11#include "my-stuff.h"
12#include "mr_mem.h"
13#include "../common/mondostructures.h"
14#include "../common/libmondo.h"
15#include "mr-externs.h"
16#include "mondo-restore.h"
17#include "mondorestore.h"
18#include "mondo-rstr-compare-EXT.h"
19#include "mondo-rstr-tools-EXT.h"
20
21extern void twenty_seconds_til_yikes(void);
22
23/* Let mr_cleanup pojnt to finish for the moment */
24void (*mr_cleanup)(int) = finish;
25
26/* Reference to global bkpinfo */
27struct s_bkpinfo *bkpinfo;
28
29
30/* For use in other programs (ex. XMondo) */
31#ifdef MONDORESTORE_MODULE
32#define main __mondorestore_main
33#define g_ISO_restore_mode __mondorestore_g_ISO_restore_mode
34#endif
35
36//static char cvsid[] = "$Id: mondorestore.c 2937 2012-01-28 00:51:28Z bruno $";
37
38/**************************************************************************
39 * Globals *
40 **************************************************************************/
41/*
42extern char *g_tmpfs_mountpt; // declared in libmondo-tools.c
43*/
44extern bool g_text_mode;
45extern FILE *g_fprep;
46extern double g_kernel_version;
47extern int g_partition_table_locked_up;
48extern int g_noof_rows;
49
50extern int partition_everything(struct mountlist_itself *mountlist);
51extern int handle_incoming_parameters(int argc, char *argv[]);
52extern int mount_media();
53
54/**
55 * @name Restore-Time Globals
56 * @ingroup globalGroup
57 * @{
58 */
59
60/**
61 * If TRUE, then we're restoring from ISOs or an NFS server.
62 * If FALSE, then we're restoring from some kind of real media (tape, CD, etc.)
63 */
64bool g_ISO_restore_mode = FALSE; /* are we in Iso Mode? */
65
66/**
67 * If TRUE, then we have had a successful "nuke" restore.
68 */
69bool g_I_have_just_nuked = FALSE;
70
71/**
72 * The device to mount to get at the ISO images. Ignored unless @p g_ISO_restore_mode.
73 */
74char *g_isodir_device;
75
76/**
77 * The format of @p g_isodir_device. Ignored unless @p g_ISO_restore_mode.
78 */
79char *g_isodir_format;
80
81/**
82 * The location of 'filelist.full', containing all files (<em>including biggiefiles</em>) on
83 * the current archive set.
84 */
85char *g_filelist_full;
86
87/**
88 * The location of a file containing a list of the devices that were archived
89 * as images, not as individual files.
90 */
91char *g_filelist_imagedevs;
92
93/**
94 * The location of a file containing a list of imagedevs to actually restore.
95 * @see g_filelist_imagedevs
96 */
97char *g_imagedevs_restthese;
98
99/**
100 * Mondo's home directory during backup. Unused in mondorestore; included
101 * to avoid link errors.
102 */
103char *g_mondo_home;
104
105extern char *g_getfacl;
106extern char *g_getfattr;
107
108/* @} - end of "Restore-Time Globals" in globalGroup */
109
110
111
112extern int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived,
113 char direction);
114
115
116
117/**************************************************************************
118 * COMPAQ ProLiant Stuff: needs some special help *
119**************************************************************************/
120
121/**
122 * The message to display if we detect that the user is using a Compaq ProLiant.
123 */
124#define COMPAQ_PROLIANTS_SUCK "Partition and format your disk using Compaq's disaster recovery CD. After you've done that, please reboot with your Mondo media in Interactive Mode."
125
126
127
128
129/**
130 * Allow the user to modify the mountlist before we partition & format their drives.
131 * @param bkpinfo The backup information structure. @c disaster_recovery is the only field used.
132 * @param mountlist The mountlist to let the user modify.
133 * @param raidlist The raidlist that goes with @p mountlist.
134 * @return 0 for success, nonzero for failure.
135 * @ingroup restoreGuiGroup
136 */
137int let_user_edit_the_mountlist(struct mountlist_itself *mountlist,
138 struct raidlist_itself *raidlist)
139{
140 int retval = 0, res = 0;
141
142 log_msg(2, "let_user_edit_the_mountlist() --- starting");
143
144 assert(bkpinfo != NULL);
145 assert(mountlist != NULL);
146 assert(raidlist != NULL);
147 if (!does_file_exist(MINDI_CACHE"/mountlist.txt")) {
148 log_to_screen(MINDI_CACHE"/mountlist.txt doesn't exist");
149 return (1);
150 }
151
152 retval = load_mountlist(mountlist, MINDI_CACHE"/mountlist.txt");
153 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
154 if (retval) {
155 log_to_screen
156 ("Warning - load_raidtab_into_raidlist returned an error");
157 }
158 res = edit_mountlist(MINDI_CACHE"/mountlist.txt", mountlist, raidlist);
159 if (res) {
160 return (1);
161 }
162
163 save_mountlist_to_disk(mountlist, MINDI_CACHE"/mountlist.txt");
164 save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
165
166 log_to_screen("I have finished editing the mountlist for you.");
167
168 return (retval);
169}
170
171
172
173
174
175/**
176 * Determine whether @p mountlist contains a Compaq diagnostic partition.
177 * @param mountlist The mountlist to examine.
178 * @return TRUE if there's a Compaq diagnostic partition; FALSE if not.
179 * @ingroup restoreUtilityGroup
180 */
181bool
182partition_table_contains_Compaq_diagnostic_partition(struct
183 mountlist_itself *
184 mountlist)
185{
186 int i;
187
188 assert(mountlist != NULL);
189
190 for (i = 0; i < mountlist->entries; i++) {
191 if (strstr(mountlist->el[i].format, "ompaq")) {
192 log_msg(2, "mountlist[%d] (%s) is %s (Compaq alert!)",
193 i, mountlist->el[i].device, mountlist->el[i].format);
194
195 return (TRUE);
196 }
197 }
198 return (FALSE);
199}
200
201/**************************************************************************
202 *END_PARTITION_TABLE_CONTAINS_COMPAQ_DIAGNOSTIC_PARTITION *
203 **************************************************************************/
204
205
206/**
207 * Allow the user to abort the backup if we find that there is a Compaq diagnostic partition.
208 * @note This function does not actually check for the presence of a Compaq partition.
209 * @ingroup restoreUtilityGroup
210 */
211void offer_to_abort_because_Compaq_ProLiants_suck(void)
212{
213 popup_and_OK(COMPAQ_PROLIANTS_SUCK);
214 if (ask_me_yes_or_no
215 ("Would you like to reboot and use your Compaq CD to prep your hard drive?"))
216 {
217 fatal_error
218 ("Aborting. Please reboot and prep your hard drive with your Compaq CD.");
219 }
220}
221
222/**************************************************************************
223 *END_OFFER_TO_ABORT_BECAUSE_COMPAQ_PROLIANTS_SUCK *
224 **************************************************************************/
225
226
227
228/**
229 * Call interactive_mode(), nuke_mode(), or compare_mode() depending on the user's choice.
230 * @param bkpinfo The backup information structure. Most fields are used.
231 * @param mountlist The mountlist containing information about the user's partitions.
232 * @param raidlist The raidlist to go with @p mountlist.
233 * @return The return code from the mode function called.
234 * @ingroup restoreGroup
235 */
236int
237catchall_mode(struct mountlist_itself *mountlist,
238 struct raidlist_itself *raidlist)
239{
240 char c;
241 char *tmp = NULL;
242 int retval = 0;
243
244 log_it("inside catchall");
245 assert(bkpinfo != NULL);
246 assert(mountlist != NULL);
247 assert(raidlist != NULL);
248 log_it("pre wrm");
249 c = which_restore_mode();
250 log_it("post wrm");
251 if (c == 'I' || c == 'C') {
252 interactively_obtain_media_parameters_from_user(FALSE);
253 } else if (c == 'N') {
254 // Auto mode nothing special to do
255 } else {
256 popup_and_OK("No restoring or comparing will take place today.");
257 if (is_this_device_mounted("/mnt/cdrom")) {
258 run_program_and_log_output("umount -d /mnt/cdrom", FALSE);
259 }
260 if (g_ISO_restore_mode) {
261 mr_asprintf(tmp, "umount -d %s", bkpinfo->isodir);
262 run_program_and_log_output(tmp, FALSE);
263 mr_free(tmp);
264 }
265 paranoid_MR_finish(0);
266 }
267
268 log_it("post int");
269
270 if (bkpinfo->backup_media_type == iso) {
271 if (iso_fiddly_bits((c == 'N') ? TRUE : FALSE)) {
272 log_msg(2,
273 "catchall_mode --- iso_fiddly_bits returned w/ error");
274 return (1);
275 } else {
276 log_msg(2, "catchall_mode --- iso_fiddly_bits ok");
277 }
278 }
279
280 if (c == 'I') {
281 log_msg(2, "IM selected");
282 retval += interactive_mode(mountlist, raidlist);
283 } else if (c == 'N') {
284 log_msg(2, "NM selected");
285 retval += nuke_mode(mountlist, raidlist);
286 } else if (c == 'C') {
287 log_msg(2, "CM selected");
288 retval += compare_mode(mountlist, raidlist);
289 }
290 return (retval);
291}
292
293/**************************************************************************
294 *END_CATCHALL_MODE *
295 **************************************************************************/
296
297/**************************************************************************
298 *END_ EXTRACT_CONFIG_FILE_FROM_RAMDISK *
299 **************************************************************************/
300
301
302/**
303 * Locate an executable in the directory structure rooted at @p restg.
304 * @param out_path Where to put the executable.
305 * @param fname The basename of the executable.
306 * @param restg The directory structure to look in.
307 * @note If it could not be found in @p restg then @p fname is put in @p out_path.
308 * @ingroup restoreUtilityGroup
309 */
310void
311find_pathname_of_executable_preferably_in_RESTORING(char *out_path,
312 char *fname,
313 char *restg)
314{
315 assert(out_path != NULL);
316 assert_string_is_neither_NULL_nor_zerolength(fname);
317
318 sprintf(out_path, "%s/sbin/%s", restg, fname);
319 if (does_file_exist(out_path)) {
320 sprintf(out_path, "%s/usr/sbin/%s", restg, fname);
321 if (does_file_exist(out_path)) {
322 sprintf(out_path, "%s/bin/%s", restg, fname);
323 if (does_file_exist(out_path)) {
324 sprintf(out_path, "%s/usr/bin/%s", restg, fname);
325 if (does_file_exist(out_path)) {
326 strcpy(out_path, fname);
327 }
328 }
329 }
330 }
331}
332
333/**************************************************************************
334 *END_FIND_PATHNAME_OF_EXECUTABLE_PREFERABLY_IN_RESTORING *
335 **************************************************************************/
336
337static void clean_blkid() {
338
339 char *tmp1 = NULL;
340
341 if (bkpinfo->restore_path) {
342 /* Clean up blkid cache file if they exist */
343 mr_asprintf(tmp1,"%s/etc/blkid.tab",bkpinfo->restore_path);
344 (void)unlink(tmp1);
345 paranoid_free(tmp1);
346 mr_asprintf(tmp1,"%s/etc/blkid.tab.old",bkpinfo->restore_path);
347 (void)unlink(tmp1);
348 paranoid_free(tmp1);
349 }
350}
351
352
353static void clean_multipathconf() {
354
355 char *tmp1 = NULL;
356 char *editor = NULL;
357
358 if (bkpinfo->restore_path) {
359 /* Clean up multiconf cache file if they exist */
360 mr_asprintf(tmp1,"%s/var/lib/multipath/bindings",bkpinfo->restore_path);
361 (void)unlink(tmp1);
362 paranoid_free(tmp1);
363 }
364
365 /* Edit multipath.conf if needed to adapt wwid */
366 mr_asprintf(tmp1,"%s/etc/multipath.conf", MNT_RESTORING);
367 if (does_file_exist(tmp1)) {
368 log_msg(2, "We may need to clean /etc/multipath.conf");
369 } else {
370 paranoid_free(tmp1);
371 return;
372 }
373 paranoid_free(tmp1);
374
375 if (bkpinfo->restore_mode != nuke) {
376 mr_asprintf(editor, "%s", find_my_editor());
377 mr_asprintf(tmp1,"chroot %s %s /etc/multipath.conf", MNT_RESTORING, editor);
378 popup_and_OK("You will now edit multipath.conf");
379 if (!g_text_mode) {
380 newtSuspend();
381 }
382 paranoid_system(tmp1);
383 if (!g_text_mode) {
384 newtResume();
385 }
386 paranoid_free(tmp1);
387 paranoid_free(editor);
388 } else {
389 log_to_screen("Non-interactive mode: no way to give you the keyboard so that you edit your multipath.conf. Hope it's OK");
390 log_msg(1,"Non-interactive mode: no way to give you the keyboard so that you edit your multipath.conf. Hope it's OK");
391 }
392}
393
394
395
396
397/**
398 * @addtogroup restoreGroup
399 * @{
400 */
401/**
402 * Restore the user's data, in a disaster recovery situation, prompting the
403 * user about whether or not to do every step.
404 * The user can edit the mountlist, choose files to restore, etc.
405 * @param bkpinfo The backup information structure. Most fields are used.
406 * @param mountlist The mountlist containing information about the user's partitions.
407 * @param raidlist The raidlist to go with @p mountlist.
408 * @return 0 for success, or the number of errors encountered.
409 */
410int interactive_mode(struct mountlist_itself *mountlist, struct raidlist_itself *raidlist)
411{
412 int retval = 0;
413 int res;
414 int ptn_errs = 0;
415 int fmt_errs = 0;
416
417 bool done;
418 bool restore_all;
419
420 /** needs malloc **********/
421 char *tmp;
422 char *p = NULL;
423 char *tmp1 = NULL;
424 char *fstab_fname = NULL;
425 char *old_restpath = NULL;
426
427 struct s_node *filelist;
428
429 /* try to partition and format */
430
431 log_msg(2, "interactive_mode --- starting (great, assertions OK)");
432
433 malloc_string(tmp);
434 assert(bkpinfo != NULL);
435 assert(mountlist != NULL);
436 assert(raidlist != NULL);
437
438 log_msg(2, "interactive_mode --- assertions OK");
439
440 if (g_text_mode) {
441 if (!ask_me_yes_or_no("Interactive Mode + textonly = experimental! Proceed anyway?")) {
442 fatal_error("Wise move.");
443 }
444 }
445
446 log_it("About to load config file");
447 read_cfg_file_into_bkpinfo(MINDI_CACHE"/mondorestore.cfg");
448 log_it("Done loading config file; resizing ML");
449
450 tmp1 = call_program_and_get_last_line_of_output("cat " CMDLINE,TRUE);
451 if (strstr(tmp1, "noresize")) {
452 log_msg(1, "Not resizing mountlist.");
453 } else {
454 resize_mountlist_proportionately_to_suit_new_drives(mountlist);
455 }
456 mr_free(tmp1);
457
458 for (done = FALSE; !done;) {
459 log_it("About to edit mountlist");
460 if (g_text_mode) {
461 save_mountlist_to_disk(mountlist, MINDI_CACHE"/mountlist.txt");
462 mr_asprintf(tmp1, "%s %s", find_my_editor(), MINDI_CACHE"/mountlist.txt");
463 res = system(tmp1);
464 mr_free(tmp1);
465 load_mountlist(mountlist, MINDI_CACHE"/mountlist.txt");
466 } else {
467 res = edit_mountlist(MINDI_CACHE"/mountlist.txt", mountlist, raidlist);
468 }
469 log_it("Finished editing mountlist");
470 if (res) {
471 paranoid_MR_finish(1);
472 }
473 log_msg(2, "Proceeding...");
474 save_mountlist_to_disk(mountlist, MINDI_CACHE"/mountlist.txt");
475 save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
476 mvaddstr_and_log_it(1, 30, "Restoring Interactively");
477 if (bkpinfo->differential) {
478 log_to_screen("Because this is a differential backup, disk");
479 log_to_screen
480 (" partitioning and formatting will not take place.");
481 done = TRUE;
482 } else {
483 if (ask_me_yes_or_no
484 ("Do you want to erase and partition your hard drives?")) {
485 if (partition_table_contains_Compaq_diagnostic_partition
486 (mountlist)) {
487 offer_to_abort_because_Compaq_ProLiants_suck();
488 done = TRUE;
489 } else {
490 twenty_seconds_til_yikes();
491 g_fprep = fopen("/tmp/prep.sh", "w");
492 ptn_errs = partition_everything(mountlist);
493 if (ptn_errs) {
494 log_to_screen
495 ("Warning. Errors occurred during disk partitioning.");
496 }
497
498 fmt_errs = format_everything(mountlist, FALSE, raidlist);
499 if (!fmt_errs) {
500 log_to_screen
501 ("Errors during disk partitioning were handled OK.");
502 log_to_screen
503 ("Partitions were formatted OK despite those errors.");
504 ptn_errs = 0;
505 }
506 if (!ptn_errs && !fmt_errs) {
507 done = TRUE;
508 }
509 }
510 paranoid_fclose(g_fprep);
511 } else {
512 mvaddstr_and_log_it(g_currentY++, 0,
513 "User opted not to partition the devices");
514 if (ask_me_yes_or_no
515 ("Do you want to format your hard drives?")) {
516 fmt_errs = format_everything(mountlist, TRUE, raidlist);
517 if (!fmt_errs) {
518 done = TRUE;
519 }
520 } else {
521 ptn_errs = fmt_errs = 0;
522 done = TRUE;
523 }
524 }
525 if (fmt_errs) {
526 mvaddstr_and_log_it(g_currentY++,
527 0,
528 "Errors occurred. Please repartition and format drives manually.");
529 done = FALSE;
530 }
531 if (ptn_errs & !fmt_errs) {
532 mvaddstr_and_log_it(g_currentY++,
533 0,
534 "Errors occurred during partitioning. Formatting, however, went OK.");
535 done = TRUE;
536 }
537 if (!done) {
538 if (!ask_me_yes_or_no("Re-edit the mountlist?")) {
539 retval++;
540 goto end_of_func;
541 }
542 }
543 }
544 }
545
546 /* mount */
547 if (mount_all_devices(mountlist, TRUE)) {
548 unmount_all_devices(mountlist);
549 retval++;
550 goto end_of_func;
551 }
552 /* restore */
553 if ((restore_all = ask_me_yes_or_no("Do you want me to restore all of your data?"))) {
554 log_msg(1, "Restoring all data");
555 retval += restore_everything(NULL);
556 } else if ((restore_all = ask_me_yes_or_no("Do you want me to restore _some_ of your data?"))) {
557 mr_asprintf(old_restpath, "%s", bkpinfo->restore_path);
558 for (done = FALSE; !done;) {
559 unlink("/tmp/filelist.full");
560 filelist = process_filelist_and_biggielist();
561 /* Now you have /tmp/tmpfs/filelist.restore-these and /tmp/tmpfs/biggielist.restore-these;
562 the former is a list of regular files; the latter, biggiefiles and imagedevs.
563 */
564 if (filelist) {
565 gotos_suck:
566 strcpy(tmp, old_restpath);
567 // (NB: %s is where your filesystem is mounted now, by default)", MNT_RESTORING);
568 p = popup_and_get_string("Restore path", "Restore files to where?", tmp);
569 if (p != NULL) {
570 strcpy(tmp, p);
571 if (!strcmp(tmp, "/")) {
572 if (!ask_me_yes_or_no("Are you sure?")) {
573 goto gotos_suck;
574 }
575 tmp[0] = '\0'; // so we restore to [blank]/file/name :)
576 }
577 mr_free(bkpinfo->restore_path);
578 mr_asprintf(bkpinfo->restore_path, "%s", tmp);
579 log_msg(1, "Restoring subset");
580 retval += restore_everything(filelist);
581 } else {
582 mr_free(bkpinfo->restore_path);
583 mr_asprintf(bkpinfo->restore_path, "%s", old_restpath);
584 }
585 free_filelist(filelist);
586 mr_free(p);
587
588 if (!ask_me_yes_or_no("Restore another subset of your backup?")) {
589 done = TRUE;
590 }
591 } else {
592 done = TRUE;
593 }
594 }
595 mr_free(old_restpath);
596 } else {
597 mvaddstr_and_log_it(g_currentY++, 0, "User opted not to restore any data. ");
598 }
599 if (retval) {
600 mvaddstr_and_log_it(g_currentY++, 0, "Errors occurred during the restore phase. ");
601 }
602
603 clean_multipathconf();
604 if (ask_me_yes_or_no("Initialize the boot loader?")) {
605 run_boot_loader(TRUE);
606 } else {
607 mvaddstr_and_log_it(g_currentY++,
608 0,
609 "User opted not to initialize the boot loader.");
610 }
611
612 clean_blkid();
613 protect_against_braindead_sysadmins();
614 retval += unmount_all_devices(mountlist);
615
616 /* if (restore_some || restore_all || */
617 if (ask_me_yes_or_no
618 ("Label/Identify your ext2/ext3/ext4 partitions if necessary?")) {
619 mvaddstr_and_log_it(g_currentY, 0,
620 "Using tune2fs to identify your ext2,3,4 partitions");
621 if (does_file_exist("/tmp/fstab.new")) {
622 mr_asprintf(fstab_fname, "/tmp/fstab.new");
623 } else {
624 mr_asprintf(fstab_fname, "/tmp/fstab");
625 }
626 mr_asprintf(tmp1, "label-partitions-as-necessary %s < %s >> %s 2>> %s", MINDI_CACHE"/mountlist.txt", fstab_fname, MONDO_LOGFILE, MONDO_LOGFILE);
627 mr_free(fstab_fname);
628
629 res = system(tmp1);
630 mr_free(tmp1);
631 if (res) {
632 log_to_screen
633 ("label-partitions-as-necessary returned an error");
634 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
635 } else {
636 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
637 }
638 retval += res;
639 }
640
641 log_it("About to leave interactive_mode()");
642 if (retval) {
643 mvaddstr_and_log_it(g_currentY++,
644 0,
645 "Warning - errors occurred during the restore phase.");
646 }
647 end_of_func:
648 paranoid_free(tmp);
649 log_it("Leaving interactive_mode()");
650 return (retval);
651}
652
653/**************************************************************************
654 *END_INTERACTIVE_MODE *
655 **************************************************************************/
656
657
658
659/**
660 * Run an arbitrary restore mode (prompt the user), but from ISO images
661 * instead of real media.
662 * @param mountlist The mountlist containing information about the user's partitions.
663 * @param raidlist The raidlist that goes with @p mountlist.
664 * @param nuke_me_please If TRUE, we plan to run Nuke Mode.
665 * @return 0 for success, or the number of errors encountered.
666 */
667int
668iso_mode(struct mountlist_itself *mountlist,
669 struct raidlist_itself *raidlist, bool nuke_me_please)
670{
671 char c;
672 int retval = 0;
673
674 assert(mountlist != NULL);
675 assert(raidlist != NULL);
676 if (iso_fiddly_bits(nuke_me_please)) {
677 log_msg(1, "iso_mode --- returning w/ error");
678 return (1);
679 } else {
680 c = which_restore_mode();
681 if (c == 'I' || c == 'N' || c == 'C') {
682 interactively_obtain_media_parameters_from_user(FALSE);
683 }
684 if (c == 'I') {
685 retval += interactive_mode(mountlist, raidlist);
686 } else if (c == 'N') {
687 retval += nuke_mode(mountlist, raidlist);
688 } else if (c == 'C') {
689 retval += compare_mode(mountlist, raidlist);
690 } else {
691 log_to_screen("OK, I shan't restore/compare any files.");
692 }
693 }
694 if (is_this_device_mounted(MNT_CDROM)) {
695 paranoid_system("umount -d " MNT_CDROM);
696 }
697// if (! already_mounted)
698// {
699 if (system("umount -d /tmp/isodir 2> /dev/null")) {
700 log_to_screen
701 ("WARNING - unable to unmount device where the ISO files are stored.");
702 }
703// }
704 return (retval);
705}
706
707/**************************************************************************
708 *END_ISO_MODE *
709 **************************************************************************/
710
711
712/* MONDO - saving your a$$ since Feb 18th, 2000 */
713
714
715
716
717/**
718 * Restore the user's data automatically (no prompts), after a twenty-second
719 * warning period.
720 * @param bkpinfo The backup information structure. Most fields are used.
721 * @param mountlist The mountlist containing information about the user's partitions.
722 * @param raidlist The raidlist that goes with @p mountlist.
723 * @return 0 for success, or the number of errors encountered.
724 * @warning <b><i>THIS WILL ERASE ALL EXISTING DATA!</i></b>
725 */
726int
727nuke_mode(struct mountlist_itself *mountlist,
728 struct raidlist_itself *raidlist)
729{
730 int retval = 0;
731 int res = 0;
732 bool boot_loader_installed = FALSE;
733 char *tmp = NULL;
734 char *tmp1 = NULL;
735 char *flaws_str = NULL;
736
737 assert(bkpinfo != NULL);
738 assert(mountlist != NULL);
739 assert(raidlist != NULL);
740
741 log_msg(2, "nuke_mode --- starting");
742 load_mountlist(mountlist, MINDI_CACHE"/mountlist.txt"); // in case read_cfg_file_into_bkpinfo updated the mountlist
743
744 tmp = call_program_and_get_last_line_of_output("cat " CMDLINE,TRUE);
745 if (strstr(tmp, "noresize")) {
746 log_msg(2, "Not resizing mountlist.");
747 } else {
748 resize_mountlist_proportionately_to_suit_new_drives(mountlist);
749 }
750 mr_free(tmp);
751
752 flaws_str = evaluate_mountlist(mountlist);
753 if (flaws_str != NULL) {
754 mr_asprintf(tmp, "Mountlist analyzed. Result: \"%s\" Switch to Interactive Mode?", flaws_str);
755 mr_free(flaws_str);
756 res = ask_me_yes_or_no(tmp);
757 mr_free(tmp);
758 if (res) {
759 retval = interactive_mode(mountlist, raidlist);
760 goto after_the_nuke;
761 } else {
762 fatal_error("Nuke Mode aborted. ");
763 }
764 }
765
766 save_mountlist_to_disk(mountlist, MINDI_CACHE"/mountlist.txt");
767 mvaddstr_and_log_it(1, 30, "Restoring Automatically");
768 if (bkpinfo->differential) {
769 log_to_screen("Because this is a differential backup, disk");
770 log_to_screen("partitioning and formatting will not take place.");
771 res = 0;
772 } else {
773 if (partition_table_contains_Compaq_diagnostic_partition
774 (mountlist)) {
775 offer_to_abort_because_Compaq_ProLiants_suck();
776 } else {
777 twenty_seconds_til_yikes();
778 g_fprep = fopen("/tmp/prep.sh", "w");
779 tmp = call_program_and_get_last_line_of_output("cat " CMDLINE,TRUE);
780 if (strstr(tmp, "nopart")) {
781 log_msg(2, "Not partitioning drives due to 'nopart' option.");
782 res = 0;
783 } else {
784 res = partition_everything(mountlist);
785 if (res) {
786 log_to_screen("Warning. Errors occurred during partitioning.");
787 res = 0;
788 }
789 }
790 mr_free(tmp);
791
792 retval += res;
793 if (!res) {
794 log_to_screen("Preparing to format your disk(s)");
795 sleep(1);
796 sync();
797 log_to_screen("Please wait. This may take a few minutes.");
798 res += format_everything(mountlist, FALSE, raidlist);
799 }
800 paranoid_fclose(g_fprep);
801 }
802 }
803 retval += res;
804 if (res) {
805 mvaddstr_and_log_it(g_currentY++,
806 0,
807 "Failed to partition and/or format your hard drives.");
808
809 if (ask_me_yes_or_no("Try in interactive mode instead?")) {
810 retval = interactive_mode(mountlist, raidlist);
811 goto after_the_nuke;
812 } else
813 if (!ask_me_yes_or_no
814 ("Would you like to try to proceed anyway?")) {
815 return (retval);
816 }
817 }
818 retval = mount_all_devices(mountlist, TRUE);
819 if (retval) {
820 unmount_all_devices(mountlist);
821 log_to_screen
822 ("Unable to mount all partitions. Sorry, I cannot proceed.");
823 return (retval);
824 }
825 log_it("Restoring everything");
826 retval += restore_everything(NULL);
827 clean_multipathconf();
828 if (!run_boot_loader(FALSE)) {
829 log_msg(1,
830 "Great! Boot loader was installed. No need for msg at end.");
831 boot_loader_installed = TRUE;
832 }
833 clean_blkid();
834 protect_against_braindead_sysadmins();
835 retval += unmount_all_devices(mountlist);
836 mvaddstr_and_log_it(g_currentY,
837 0,
838 "Using tune2fs to identify your ext2,3 partitions");
839
840 mr_asprintf(tmp, "label-partitions-as-necessary %s < /tmp/fstab >> %s 2>> %s", MINDI_CACHE"/mountlist.txt", MONDO_LOGFILE, MONDO_LOGFILE);
841 res = run_program_and_log_output(tmp, TRUE);
842 mr_free(tmp);
843 if (res) {
844 log_to_screen("label-partitions-as-necessary returned an error");
845 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
846 } else {
847 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
848 }
849 retval += res;
850
851 after_the_nuke:
852 tmp1 = call_program_and_get_last_line_of_output("cat " CMDLINE,TRUE);
853 if (retval) {
854 log_to_screen("Errors occurred during the nuke phase.");
855 } else if (strstr(tmp1, "RESTORE")) {
856 log_to_screen("PC was restored successfully. Thank you for using Mondo Rescue.");
857 log_to_screen("Please visit our website at http://www.mondorescue.org for more information.");
858 } else {
859 mr_asprintf(tmp,"%s","Mondo has restored your system.\n\nPlease wait for the command prompt. Then remove the backup media and reboot.\n\nPlease visit our website at http://www.mondorescue.org for more information.");
860 popup_and_OK(tmp);
861 mr_free(tmp);
862 log_to_screen("Mondo has restored your system. Please wait for the command prompt.");
863 log_to_screen("Then remove the backup media and reboot.");
864 log_to_screen("Please visit our website at http://www.mondorescue.org for more information.");
865 }
866 mr_free(tmp1);
867
868 g_I_have_just_nuked = TRUE;
869 return (retval);
870}
871
872/**************************************************************************
873 *END_NUKE_MODE *
874 **************************************************************************/
875
876
877
878/**
879 * Restore the user's data (or a subset of it) to the live filesystem.
880 * This should not be called if we're booted from CD!
881 * @param bkpinfo The backup information structure. Most fields are used.
882 * @return 0 for success, or the number of errors encountered.
883 */
884int restore_to_live_filesystem()
885{
886 int retval = 0;
887
888 char *old_restpath = NULL;
889 char *p = NULL;
890
891 struct mountlist_itself *mountlist = NULL;
892 struct raidlist_itself *raidlist = NULL;
893 struct s_node *filelist = NULL;
894
895 log_msg(1, "restore_to_live_filesystem() - starting");
896 assert(bkpinfo != NULL);
897 mountlist = malloc(sizeof(struct mountlist_itself));
898 raidlist = malloc(sizeof(struct raidlist_itself));
899 if (!mountlist || !raidlist) {
900 fatal_error("Cannot malloc() mountlist and/or raidlist");
901 }
902
903 mr_free(bkpinfo->restore_path);
904 mr_asprintf(bkpinfo->restore_path, "/");
905 if (bkpinfo->backup_media_type != netfs) {
906 popup_and_OK
907 ("Please insert tape/CD/USB Key, then hit 'OK' to continue.");
908 sleep(1);
909 interactively_obtain_media_parameters_from_user(FALSE);
910 }
911 if (!bkpinfo->media_device) {
912 log_msg(2, "WARNING: failed to find media dev");
913 } else {
914 log_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device);
915 }
916
917
918 log_msg(2, "bkpinfo->isodir = %s", bkpinfo->isodir);
919
920 open_evalcall_form("Thinking...");
921 read_cfg_file_into_bkpinfo(MINDI_CACHE"/mondorestore.cfg");
922 load_mountlist(mountlist, MINDI_CACHE"/mountlist.txt"); // in case read_cfg_file_into_bkpinfo
923
924 close_evalcall_form();
925 retval = load_mountlist(mountlist, MINDI_CACHE"/mountlist.txt");
926 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
927
928 if ((bkpinfo->backup_media_type != netfs) && (filelist = process_filelist_and_biggielist())) {
929 save_filelist(filelist, "/tmp/selected-files.txt");
930 mr_asprintf(old_restpath, "%s", bkpinfo->restore_path);
931 p = popup_and_get_string("Restore path", "Restore files to where? )", bkpinfo->restore_path);
932 if (p != NULL) {
933 mr_free(bkpinfo->restore_path);
934 bkpinfo->restore_path = p;
935
936 log_it("Restoring everything");
937 retval += restore_everything(filelist);
938 }
939 free_filelist(filelist);
940 mr_free(bkpinfo->restore_path);
941 bkpinfo->restore_path = old_restpath;
942 } else {
943 if (filelist != NULL) {
944 retval += restore_everything(NULL);
945 }
946 }
947 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
948 log_msg(2,
949 "Tape : I don't need to unmount or eject the CD-ROM.");
950 } else {
951 run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
952 if (!bkpinfo->please_dont_eject) {
953 eject_device(bkpinfo->media_device);
954 }
955 }
956 run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
957 if (!bkpinfo->please_dont_eject) {
958 eject_device(bkpinfo->media_device);
959 }
960 free(mountlist);
961 free(raidlist);
962 return (retval);
963}
964
965/**************************************************************************
966 *END_RESTORE_TO_LIVE_FILESYSTEM *
967 **************************************************************************/
968
969/* @} - end of restoreGroup */
970
971
972#include <utime.h>
973/**
974 * @addtogroup LLrestoreGroup
975 * @{
976 */
977/**
978 * Restore biggiefile @p bigfileno from the currently mounted CD.
979 * @param bkpinfo The backup information structure. Fields used:
980 * - @c bkpinfo->backup_media_type
981 * - @c bkpinfo->restore_path
982 * @param bigfileno The biggiefile number (starting from 0) to restore.
983 * @param filelist The node structure containing the list of files to restore.
984 * If the biggiefile is not in this list, it will be skipped (return value will
985 * still indicate success).
986 * @return 0 for success (or skip), nonzero for failure.
987 */
988int
989restore_a_biggiefile_from_CD(long bigfileno,
990 struct s_node *filelist,
991 char *pathname_of_last_file_restored)
992{
993 FILE *fin;
994 FILE *fout;
995 FILE *fbzip2;
996
997 /** malloc ***/
998 char *checksum = NULL;
999 char *outfile_fname = NULL;
1000 char *tmp = NULL;
1001 char *bzip2_command = NULL;
1002 char *suffix = NULL;
1003 char *sz_devfile = NULL;
1004 char *bigblk;
1005 char *mds = NULL;
1006 int retval = 0;
1007 int finished = FALSE;
1008 long sliceno;
1009 long siz;
1010 char *ntfsprog_fifo = NULL;
1011 char *file_to_openout = NULL;
1012 struct s_filename_and_lstat_info biggiestruct;
1013 struct utimbuf the_utime_buf, *ubuf;
1014 bool use_ntfsprog_hack = FALSE;
1015 pid_t pid;
1016 int res = 0;
1017 int old_loglevel;
1018 struct s_node *node;
1019
1020 old_loglevel = g_loglevel;
1021 ubuf = &the_utime_buf;
1022 assert(bkpinfo != NULL);
1023
1024 pathname_of_last_file_restored[0] = '\0';
1025 if (!(bigblk = malloc(TAPE_BLOCK_SIZE))) {
1026 fatal_error("Cannot malloc bigblk");
1027 }
1028
1029 if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) {
1030 log_to_screen("Cannot even open bigfile's info file");
1031 return (1);
1032 }
1033
1034 memset((void *) &biggiestruct, 0, sizeof(biggiestruct));
1035 if (fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin) <
1036 sizeof(biggiestruct)) {
1037 log_msg(2, "Warning - unable to get biggiestruct of bigfile #%d",
1038 bigfileno + 1);
1039 }
1040 paranoid_fclose(fin);
1041
1042 mr_asprintf(checksum, "%s", biggiestruct.checksum);
1043 if (!checksum[0]) {
1044 log_msg(3, "Warning - bigfile %ld does not have a checksum", bigfileno + 1);
1045 }
1046 mr_free(checksum);
1047
1048 if (!strncmp(biggiestruct.filename, "/dev/", 5)) // Whether NTFS or not :)
1049 {
1050 mr_asprintf(outfile_fname, "%s", biggiestruct.filename);
1051 } else {
1052 mr_asprintf(outfile_fname, "%s/%s", bkpinfo->restore_path, biggiestruct.filename);
1053 }
1054
1055 /* skip file if we have a selective restore subset & it doesn't match */
1056 if (filelist != NULL) {
1057 node = find_string_at_node(filelist, biggiestruct.filename);
1058 if (!node) {
1059 log_msg(0, "Skipping %s (name isn't in filelist)", biggiestruct.filename);
1060 pathname_of_last_file_restored[0] = '\0';
1061 return (0);
1062 } else if (!(node->selected)) {
1063 log_msg(1, "Skipping %s (name isn't in biggielist subset)", biggiestruct.filename);
1064 pathname_of_last_file_restored[0] = '\0';
1065 return (0);
1066 }
1067 }
1068
1069 /* otherwise, continue */
1070 log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename);
1071 if (biggiestruct.use_ntfsprog) {
1072 if (strncmp(biggiestruct.filename, "/dev/", 5)) {
1073 log_msg(1, "I was in error when I set biggiestruct.use_ntfsprog to TRUE.");
1074 log_msg(1, "%s isn't even in /dev", biggiestruct.filename);
1075 biggiestruct.use_ntfsprog = FALSE;
1076 }
1077 }
1078
1079 if (biggiestruct.use_ntfsprog) // if it's an NTFS device
1080 {
1081 g_loglevel = 4;
1082 use_ntfsprog_hack = TRUE;
1083 log_msg(2, "Calling ntfsclone in background because %s is an NTFS /dev entry", outfile_fname);
1084 mr_asprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768), (int) (random() % 32768));
1085 mkfifo(sz_devfile, 0x770);
1086 mr_asprintf(ntfsprog_fifo, "%s", sz_devfile);
1087 mr_free(sz_devfile);
1088 file_to_openout = ntfsprog_fifo;
1089 switch (pid = fork()) {
1090 case -1:
1091 fatal_error("Fork failure");
1092 case 0:
1093 log_msg(3, "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)", biggiestruct.filename, ntfsprog_fifo);
1094 res = feed_outfrom_ntfsprog(biggiestruct.filename, ntfsprog_fifo);
1095 mr_free(ntfsprog_fifo);
1096 exit(res);
1097 break;
1098 default:
1099 log_msg(3, "feed_into_ntfsprog() called in background --- pid=%ld", (long int) (pid));
1100 }
1101 mr_free(ntfsprog_fifo);
1102 } else {
1103 use_ntfsprog_hack = FALSE;
1104 file_to_openout = outfile_fname;
1105 if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way
1106 {
1107 make_hole_for_file(outfile_fname);
1108 }
1109 }
1110
1111 log_msg(2, "Reassembling big file %ld (%s)", bigfileno + 1, outfile_fname);
1112
1113 /*
1114 last slice is zero-length and uncompressed; when we find it, we stop.
1115 We DON'T wait until there are no more slices; if we did that,
1116 We might stop at end of CD, not at last slice (which is 0-len and uncompd)
1117 */
1118
1119 strncpy(pathname_of_last_file_restored, biggiestruct.filename, MAX_STR_LEN - 1);
1120 pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
1121
1122 log_msg(3, "file_to_openout = %s", file_to_openout);
1123 if (!(fout = fopen(file_to_openout, "w"))) {
1124 log_to_screen("Cannot openout outfile_fname - hard disk full?");
1125 return (1);
1126 }
1127 log_msg(3, "Opened out to %s", outfile_fname); // CD/DVD --> mondorestore --> ntfsclone --> hard disk itself
1128
1129 for (sliceno = 1, finished = FALSE; !finished;) {
1130 if (!does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "")) &&
1131 !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzo")) &&
1132 !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "gz")) &&
1133 !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzma")) &&
1134 !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
1135 log_msg(3, "Cannot find a data slice or terminator slice on CD %d", g_current_media_number);
1136 g_current_media_number++;
1137 mds = media_descriptor_string(bkpinfo->backup_media_type);
1138 log_msg(2, "Asking for %s #%d so that I may read slice #%ld\n", mds, g_current_media_number, sliceno);
1139 mr_free(mds);
1140
1141 log_to_screen("Restoring from %s #%d", mds, g_current_media_number);
1142
1143 insist_on_this_cd_number(g_current_media_number);
1144 log_to_screen("Continuing to restore.");
1145 } else {
1146 mr_asprintf(tmp, "%s", slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""));
1147 if (does_file_exist(tmp) && length_of_file(tmp) == 0) {
1148 log_msg(2, "End of bigfile # %ld (slice %ld is the terminator)", bigfileno + 1, sliceno);
1149 finished = TRUE;
1150 mr_free(tmp);
1151 continue;
1152 } else {
1153 if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) {
1154 mr_asprintf(bzip2_command, "lzop");
1155 mr_asprintf(suffix, "lzo");
1156 } else
1157 if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "gz"))) {
1158 mr_asprintf(bzip2_command, "gzip");
1159 mr_asprintf(suffix, "gz");
1160 } else
1161 if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzma"))) {
1162 mr_asprintf(bzip2_command, "lzma");
1163 mr_asprintf(suffix, "lzma");
1164 } else
1165 if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
1166 mr_asprintf(bzip2_command, "bzip2");
1167 mr_asprintf(suffix, "bz2");
1168 } else
1169 if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""))) {
1170 mr_asprintf(bzip2_command, "");
1171 mr_asprintf(suffix, "");
1172 } else {
1173 log_to_screen("OK, that's pretty fsck0red...");
1174 mr_free(tmp);
1175 return (1);
1176 }
1177 }
1178 mr_free(tmp);
1179 if (bzip2_command != NULL) {
1180 mr_strcat(bzip2_command, " -dc %s 2>> %s", slice_fname(bigfileno, sliceno, ARCHIVES_PATH, suffix), MONDO_LOGFILE);
1181 } else {
1182 mr_asprintf(bzip2_command, "cat %s 2>> %s", slice_fname(bigfileno, sliceno, ARCHIVES_PATH, suffix), MONDO_LOGFILE);
1183 }
1184 mr_free(suffix);
1185
1186 mds = media_descriptor_string(bkpinfo->backup_media_type);
1187 mr_asprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld ", mds, g_current_media_number, bigfileno + 1, sliceno);
1188 mr_free(mds);
1189 log_msg(2, tmp);
1190
1191 if (!g_text_mode) {
1192 newtDrawRootText(0, g_noof_rows - 2, tmp);
1193 newtRefresh();
1194 strip_spaces(tmp);
1195 update_progress_form(tmp);
1196 }
1197 mr_free(tmp);
1198
1199 if (!(fbzip2 = popen(bzip2_command, "r"))) {
1200 fatal_error("Can't run popen command");
1201 }
1202 mr_free(bzip2_command);
1203
1204 while (!feof(fbzip2)) {
1205 siz = fread(bigblk, 1, TAPE_BLOCK_SIZE, fbzip2);
1206 if (siz > 0) {
1207 siz = fwrite(bigblk, 1, siz, fout);
1208 }
1209 }
1210 paranoid_pclose(fbzip2);
1211
1212
1213 sliceno++;
1214 g_current_progress++;
1215 }
1216 }
1217 paranoid_fclose(fout);
1218 g_loglevel = old_loglevel;
1219
1220 if (use_ntfsprog_hack) {
1221 log_msg(3, "Waiting for ntfsclone to finish");
1222 mr_asprintf(tmp, " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
1223 while (system(tmp) == 0) {
1224 sleep(1);
1225 }
1226 mr_free(tmp);
1227 log_it("OK, ntfsclone has really finished");
1228 }
1229
1230 if (strcmp(outfile_fname, "/dev/null")) {
1231 chown(outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid);
1232 chmod(outfile_fname, biggiestruct.properties.st_mode);
1233 ubuf->actime = biggiestruct.properties.st_atime;
1234 ubuf->modtime = biggiestruct.properties.st_mtime;
1235 utime(outfile_fname, ubuf);
1236 }
1237 mr_free(outfile_fname);
1238 paranoid_free(bigblk);
1239
1240 return (retval);
1241}
1242
1243/**************************************************************************
1244 *END_ RESTORE_A_BIGGIEFILE_FROM_CD *
1245 **************************************************************************/
1246
1247
1248
1249/**
1250 * Restore a biggiefile from the currently opened stream.
1251 * @param bkpinfo The backup information structure. Fields used:
1252 * - @c bkpinfo->restore_path
1253 * - @c bkpinfo->zip_exe
1254 * @param orig_bf_fname The original filename of the biggiefile.
1255 * @param biggiefile_number The number of the biggiefile (starting from 0).
1256 * @param orig_checksum Unused.
1257 * @param biggiefile_size Unused.
1258 * @param filelist The node structure containing the list of files to be restored.
1259 * If @p orig_bf_fname is not in the list, it will be ignored.
1260 * @return 0 for success (or skip), nonzero for failure.
1261 * @bug orig_checksum and biggiefile_size are unused (except to check that they are non-NULL).
1262 */
1263int restore_a_biggiefile_from_stream(char *orig_bf_fname, long biggiefile_number, char *orig_checksum, //UNUSED
1264 long long biggiefile_size, //UNUSED
1265 struct s_node *filelist,
1266 int use_ntfsprog,
1267 char *pathname_of_last_file_restored)
1268{
1269 FILE *pout;
1270 FILE *fin;
1271
1272 /** mallocs ********/
1273 char *tmp = NULL;
1274 char *tmp1 = NULL;
1275 char *command = NULL;
1276 char *outfile_fname = NULL;
1277 char *sz_devfile = NULL;
1278 char *ntfsprog_fifo = NULL;
1279 char *file_to_openout = NULL;
1280
1281 struct s_node *node;
1282
1283 int old_loglevel;
1284 long current_slice_number = 0;
1285 int retval = 0;
1286 int res = 0;
1287 int ctrl_chr = '\0';
1288 long long slice_siz;
1289 bool dummy_restore = FALSE;
1290 bool use_ntfsprog_hack = FALSE;
1291 pid_t pid;
1292 struct s_filename_and_lstat_info biggiestruct;
1293 struct utimbuf the_utime_buf, *ubuf;
1294 ubuf = &the_utime_buf;
1295
1296 malloc_string(tmp);
1297 old_loglevel = g_loglevel;
1298 assert(bkpinfo != NULL);
1299 assert(orig_bf_fname != NULL);
1300 assert(orig_checksum != NULL);
1301
1302 pathname_of_last_file_restored[0] = '\0';
1303 if (use_ntfsprog == BLK_START_A_PIHBIGGIE) {
1304 use_ntfsprog = 1;
1305 log_msg(1, "%s --- pih=YES", orig_bf_fname);
1306 } else if (use_ntfsprog == BLK_START_A_NORMBIGGIE) {
1307 use_ntfsprog = 0;
1308 log_msg(1, "%s --- pih=NO", orig_bf_fname);
1309 } else {
1310 use_ntfsprog = 0;
1311 log_msg(1, "%s --- pih=NO (weird marker though)", orig_bf_fname);
1312 }
1313
1314 strncpy(pathname_of_last_file_restored, orig_bf_fname,
1315 MAX_STR_LEN - 1);
1316 pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
1317
1318 /* open out to biggiefile to be restored (or /dev/null if biggiefile is not to be restored) */
1319
1320 if (filelist != NULL) {
1321 node = find_string_at_node(filelist, orig_bf_fname);
1322 if (!node) {
1323 dummy_restore = TRUE;
1324 log_msg(1,
1325 "Skipping big file %ld (%s) - not in biggielist subset",
1326 biggiefile_number + 1, orig_bf_fname);
1327 pathname_of_last_file_restored[0] = '\0';
1328 } else if (!(node->selected)) {
1329 dummy_restore = TRUE;
1330 log_msg(1, "Skipping %s (name isn't in biggielist subset)",
1331 orig_bf_fname);
1332 pathname_of_last_file_restored[0] = '\0';
1333 }
1334 }
1335
1336 if (use_ntfsprog) {
1337 if (strncmp(orig_bf_fname, "/dev/", 5)) {
1338 log_msg(1,
1339 "I was in error when I set use_ntfsprog to TRUE.");
1340 log_msg(1, "%s isn't even in /dev", orig_bf_fname);
1341 use_ntfsprog = FALSE;
1342 }
1343 }
1344
1345 if (use_ntfsprog) {
1346 g_loglevel = 4;
1347 mr_asprintf(outfile_fname, "%s", orig_bf_fname);
1348 use_ntfsprog_hack = TRUE;
1349 log_msg(2, "Calling ntfsclone in background because %s is a /dev entry", outfile_fname);
1350 mr_asprintf(sz_devfile, "%s/%d.%d.000", bkpinfo->tmpdir, (int) (random() % 32768), (int) (random() % 32768));
1351 mkfifo(sz_devfile, 0x770);
1352 mr_asprintf(ntfsprog_fifo, "%s", sz_devfile);
1353 mr_free(sz_devfile);
1354
1355 file_to_openout = ntfsprog_fifo;
1356 switch (pid = fork()) {
1357 case -1:
1358 fatal_error("Fork failure");
1359 case 0:
1360 log_msg(3, "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)", outfile_fname, ntfsprog_fifo);
1361 res = feed_outfrom_ntfsprog(outfile_fname, ntfsprog_fifo);
1362 mr_free(ntfsprog_fifo);
1363 exit(res);
1364 break;
1365 default:
1366 log_msg(3, "feed_into_ntfsprog() called in background --- pid=%ld", (long int) (pid));
1367 }
1368 mr_free(ntfsprog_fifo);
1369 } else {
1370 if (!strncmp(orig_bf_fname, "/dev/", 5)) {
1371 // non-NTFS partition
1372 mr_asprintf(outfile_fname, "%s", orig_bf_fname);
1373 } else {
1374 // biggiefile
1375 mr_asprintf(outfile_fname, "%s/%s", bkpinfo->restore_path, orig_bf_fname);
1376 }
1377 use_ntfsprog_hack = FALSE;
1378 file_to_openout = outfile_fname;
1379 if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way
1380 {
1381 make_hole_for_file(outfile_fname);
1382 }
1383 log_msg(2, "Reassembling big file %ld (%s)", biggiefile_number + 1, orig_bf_fname);
1384 }
1385
1386 if (dummy_restore) {
1387 mr_free(outfile_fname);
1388 mr_asprintf(outfile_fname, "/dev/null");
1389 }
1390
1391 if (bkpinfo->zip_exe == NULL) {
1392 mr_asprintf(command, "cat > \"%s\"", file_to_openout);
1393 } else {
1394 mr_asprintf(command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe, file_to_openout, MONDO_LOGFILE);
1395 if (strcmp(bkpinfo->zip_exe, "gzip") == 0) {
1396 /* Ignore SIGPIPE for gzip as it causes errors on big files
1397 * Cf: http://trac.mondorescue.org/ticket/244 */
1398 signal(SIGPIPE,SIG_IGN);
1399 }
1400 }
1401 log_msg(3, "Pipe command = '%s'", command);
1402
1403 /* restore biggiefile, one slice at a time */
1404 if (!(pout = popen(command, "w"))) {
1405 fatal_error("Cannot pipe out");
1406 }
1407 mr_free(command);
1408
1409 for (res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
1410 ctrl_chr != BLK_STOP_A_BIGGIE;
1411 res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr)) {
1412 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
1413 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
1414 }
1415 log_msg(2, "Working on file #%ld, slice #%ld ", biggiefile_number + 1, current_slice_number);
1416 if (!g_text_mode) {
1417 newtDrawRootText(0, g_noof_rows - 2, tmp);
1418 newtRefresh();
1419 }
1420 strip_spaces(tmp);
1421 update_progress_form(tmp);
1422 if (current_slice_number == 0) {
1423 res =
1424 read_file_from_stream_to_file("/tmp/biggie-blah.txt",
1425 slice_siz);
1426 if (!(fin = fopen("/tmp/biggie-blah.txt", "r"))) {
1427 log_OS_error("blah blah");
1428 } else {
1429 if (fread
1430 ((void *) &biggiestruct, 1, sizeof(biggiestruct),
1431 fin) < sizeof(biggiestruct)) {
1432 log_msg(2,
1433 "Warning - unable to get biggiestruct of bigfile #%d",
1434 biggiefile_number + 1);
1435 }
1436 paranoid_fclose(fin);
1437 }
1438 } else {
1439 res =
1440 read_file_from_stream_to_stream(pout, slice_siz);
1441 }
1442 retval += res;
1443 res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
1444 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
1445 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
1446 }
1447 current_slice_number++;
1448 g_current_progress++;
1449 }
1450 paranoid_pclose(pout);
1451
1452 if (bkpinfo->zip_exe != NULL) {
1453 if (strcmp(bkpinfo->zip_exe, "gzip") == 0) {
1454 /* Re-enable SIGPIPE for gzip */
1455 signal(SIGPIPE, terminate_daemon);
1456 }
1457 }
1458
1459 log_msg(1, "pathname_of_last_file_restored is now %s",
1460 pathname_of_last_file_restored);
1461
1462 if (use_ntfsprog_hack) {
1463 log_msg(3, "Waiting for ntfsclone to finish");
1464 mr_asprintf(tmp1, " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
1465 while (system(tmp1) == 0) {
1466 sleep(1);
1467 }
1468 mr_free(tmp1);
1469 log_msg(3, "OK, ntfsclone has really finished");
1470 }
1471
1472 log_msg(3, "biggiestruct.filename = %s", biggiestruct.filename);
1473 log_msg(3, "biggiestruct.checksum = %s", biggiestruct.checksum);
1474 if (strcmp(outfile_fname, "/dev/null")) {
1475 chmod(outfile_fname, biggiestruct.properties.st_mode);
1476 chown(outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid);
1477 ubuf->actime = biggiestruct.properties.st_atime;
1478 ubuf->modtime = biggiestruct.properties.st_mtime;
1479 utime(outfile_fname, ubuf);
1480 }
1481 mr_free(outfile_fname);
1482
1483 paranoid_free(tmp);
1484 g_loglevel = old_loglevel;
1485 return (retval);
1486}
1487
1488/**************************************************************************
1489 *END_RESTORE_A_BIGGIEFILE_FROM_STREAM *
1490 **************************************************************************/
1491
1492
1493
1494/**
1495 * Restore @p tarball_fname from CD.
1496 * @param tarball_fname The filename of the tarball to restore (in /mnt/cdrom).
1497 * This will be used unmodified.
1498 * @param current_tarball_number The number (starting from 0) of the fileset
1499 * we're restoring now.
1500 * @param filelist The node structure containing the list of files to be
1501 * restored. If no file in the afioball is in this list, afio will still be
1502 * called, but nothing will be written.
1503 * @return 0 for success, nonzero for failure.
1504 */
1505int
1506restore_a_tarball_from_CD(char *tarball_fname,
1507 long current_tarball_number,
1508 struct s_node *filelist)
1509{
1510 int retval = 0;
1511 int res;
1512 char *p;
1513
1514 /** malloc **/
1515 char *command = NULL;
1516 char *tmp = NULL;
1517 char *filelist_name = NULL;
1518 char *filelist_subset_fname = NULL;
1519 char *executable = NULL;
1520 char *temp_log = NULL;
1521 long matches = 0;
1522 bool use_star;
1523 char *xattr_fname = NULL;
1524 char *acl_fname = NULL;
1525
1526 assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
1527
1528 log_msg(5, "Entering");
1529 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
1530 mr_asprintf(command, "mkdir -p %s/tmp", MNT_RESTORING);
1531 run_program_and_log_output(command, 9);
1532 paranoid_free(command);
1533
1534 mr_asprintf(filelist_name, MNT_CDROM "/archives/filelist.%ld", current_tarball_number);
1535 if (length_of_file(filelist_name) <= 2) {
1536 log_msg(2, "There are _zero_ files in filelist '%s'", filelist_name);
1537 log_msg(2, "This is a bit silly (ask dev-team to fix mondo_makefilelist, please)");
1538 log_msg(2, "but it's non-critical. It's cosmetic. Don't worry about it.");
1539 retval = 0;
1540 mr_free(filelist_name);
1541 log_msg(5, "Leaving");
1542 return(0);
1543 }
1544 if (count_lines_in_file(filelist_name) <= 0 || length_of_file(tarball_fname) <= 0) {
1545 log_msg(3, "length_of_file(%s) = %llu", tarball_fname, length_of_file(tarball_fname));
1546 log_msg(3, "count_lines_in_file(%s) = %llu", tarball_fname, count_lines_in_file(tarball_fname));
1547 log_to_screen("Unable to restore fileset #%ld (CD I/O error)", current_tarball_number);
1548 mr_free(filelist_name);
1549 log_msg(5, "Leaving");
1550 return(1);
1551 }
1552
1553 if (filelist) {
1554 mr_asprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp", current_tarball_number);
1555 if ((matches =
1556 save_filelist_entries_in_common(filelist_name, filelist,
1557 filelist_subset_fname,
1558 use_star)) <= 0) {
1559 log_msg(1, "Skipping fileset %ld", current_tarball_number);
1560 } else {
1561 log_msg(3, "Saved fileset %ld's subset to %s", current_tarball_number, filelist_subset_fname);
1562 }
1563 log_to_screen("Tarball #%ld --- %ld matches", current_tarball_number, matches);
1564 }
1565 mr_free(filelist_name);
1566
1567 if (filelist == NULL || matches > 0) {
1568 if (g_getfattr) {
1569 mr_asprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives", current_tarball_number);
1570 }
1571 if (g_getfacl) {
1572 mr_asprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives", current_tarball_number);
1573 }
1574 if (strstr(tarball_fname, ".bz2")) {
1575 mr_asprintf(executable, "bzip2");
1576 } else if (strstr(tarball_fname, ".lzma")) {
1577 mr_asprintf(executable, "lzma");
1578 } else if (strstr(tarball_fname, ".gz")) {
1579 mr_asprintf(executable, "gzip");
1580 } else if (strstr(tarball_fname, ".lzo")) {
1581 mr_asprintf(executable, "lzop");
1582 }
1583 if (executable) {
1584 mr_asprintf(tmp, "which %s > /dev/null 2> /dev/null", executable);
1585 res = run_program_and_log_output(tmp, FALSE);
1586 mr_free(tmp);
1587
1588 if (res) {
1589 log_to_screen("(compare_a_tarball) Compression program %s not found - oh no!", executable);
1590 paranoid_MR_finish(1);
1591 }
1592 tmp = executable;
1593 mr_asprintf(executable, "-P %s -Z", tmp);
1594 mr_free(tmp);
1595 }
1596#ifdef __FreeBSD__
1597#define BUFSIZE 512
1598#else
1599#define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE
1600#endif
1601
1602 if (use_star) {
1603 mr_asprintf(command, "star -x -force-remove -U " STAR_ACL_SZ " errctl= file=%s", tarball_fname);
1604 if (strstr(tarball_fname, ".bz2")) {
1605 mr_strcat(command, " -bz");
1606 }
1607 } else {
1608 if (! executable) {
1609 log_msg(2, "Mo executable, this shouldn't happen !");
1610 } else {
1611 if (filelist_subset_fname != NULL) {
1612 mr_asprintf(command, "afio -i -M 8m -b %ld -c %ld %s -w '%s' %s", TAPE_BLOCK_SIZE, BUFSIZE, executable, filelist_subset_fname, tarball_fname);
1613 } else {
1614 mr_asprintf(command, "afio -i -b %ld -c %ld -M 8m %s %s", TAPE_BLOCK_SIZE, BUFSIZE, executable, tarball_fname);
1615 }
1616 }
1617 }
1618 mr_free(executable);
1619
1620#undef BUFSIZE
1621 mr_asprintf(temp_log, "/tmp/%d.%d", (int) (random() % 32768), (int) (random() % 32768));
1622
1623 mr_strcat(command, " 2>> %s >> %s", temp_log, temp_log);
1624 log_msg(1, "command = '%s'", command);
1625 unlink(temp_log);
1626 res = system(command);
1627 if (res) {
1628 p = strstr(command, "-acl ");
1629 if (p) {
1630 p[0] = p[1] = p[2] = p[3] = ' ';
1631 log_msg(1, "new command = '%s'", command);
1632 res = system(command);
1633 }
1634 }
1635 paranoid_free(command);
1636
1637 if (res && length_of_file(temp_log) < 5) {
1638 res = 0;
1639 }
1640
1641 if (g_getfattr) {
1642 log_msg(1, "Setting fattr list %s", xattr_fname);
1643 if (length_of_file(xattr_fname) > 0) {
1644 res = set_fattr_list(filelist_subset_fname, xattr_fname);
1645 if (res) {
1646 log_to_screen("Errors occurred while setting extended attributes");
1647 } else {
1648 log_msg(1, "I set xattr OK");
1649 }
1650 retval += res;
1651 }
1652 }
1653 if (g_getfacl) {
1654 log_msg(1, "Setting acl list %s", acl_fname);
1655 if (length_of_file(acl_fname) > 0) {
1656 res = set_acl_list(filelist_subset_fname, acl_fname);
1657 if (res) {
1658 log_to_screen
1659 ("Errors occurred while setting access control lists");
1660 } else {
1661 log_msg(1, "I set ACL OK");
1662 }
1663 retval += res;
1664 }
1665 }
1666 if (retval) {
1667 mr_asprintf(command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
1668 system(command);
1669 paranoid_free(command);
1670
1671 log_msg(2, "Errors occurred while processing fileset #%d",
1672 current_tarball_number);
1673 } else {
1674 log_msg(2, "Fileset #%d processed OK", current_tarball_number);
1675 }
1676 unlink(temp_log);
1677 mr_free(temp_log);
1678 }
1679 if (does_file_exist("/PAUSE")) {
1680 popup_and_OK
1681 ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
1682 }
1683 unlink(filelist_subset_fname);
1684 mr_free(filelist_subset_fname);
1685 if (g_getfattr) {
1686 unlink(xattr_fname);
1687 mr_free(xattr_fname);
1688 }
1689 if (g_getfacl) {
1690 unlink(acl_fname);
1691 mr_free(acl_fname);
1692 }
1693
1694 log_msg(5, "Leaving");
1695 return (retval);
1696}
1697
1698/**************************************************************************
1699 *END_RESTORE_A_TARBALL_FROM_CD *
1700 **************************************************************************/
1701
1702
1703/**
1704 * Restore a tarball from the currently opened stream.
1705 * @param bkpinfo The backup information structure. Fields used:
1706 * - @c bkpinfo->backup_media_type
1707 * - @c bkpinfo->media_device
1708 * - @c bkpinfo->zip_exe
1709 * @param tarball_fname The filename of the afioball to restore.
1710 * @param current_tarball_number The number (starting from 0) of the fileset
1711 * we're restoring now.
1712 * @param filelist The node structure containing the list of files to be
1713 * restored. If no file in the afioball is in this list, afio will still be
1714 * called, but nothing will be written.
1715 * @param size The size (in @b bytes) of the afioball.
1716 * @return 0 for success, nonzero for failure.
1717 */
1718int
1719restore_a_tarball_from_stream(char *tarball_fname,
1720 long current_tarball_number,
1721 struct s_node *filelist,
1722 long long size, char *xattr_fname,
1723 char *acl_fname)
1724{
1725 int retval = 0;
1726 int res = 0;
1727
1728 /** malloc add ***/
1729 char *mds = NULL;
1730 char *command = NULL;
1731 char *afio_fname = NULL;
1732 char *filelist_fname = NULL;
1733 char *filelist_subset_fname = NULL;
1734 char *executable = NULL;
1735 long matches = 0;
1736 bool restore_this_fileset = FALSE;
1737 bool use_star;
1738
1739 assert(bkpinfo != NULL);
1740 assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
1741
1742 /* to do it with a file... */
1743 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
1744 mds = media_descriptor_string(bkpinfo->backup_media_type);
1745 log_msg(2, "Restoring from fileset #%ld (%ld KB) on %s #%d",
1746 current_tarball_number, (long) size >> 10, mds, g_current_media_number);
1747 mr_free(mds);
1748
1749 run_program_and_log_output("mkdir -p " MNT_RESTORING "/tmp", FALSE);
1750
1751 /****************************************************************************
1752 * Use RAMDISK's /tmp; saves time; oh wait, it's too small *
1753 * Well, pipe from tape to afio, then; oh wait, can't do that either: bug *
1754 * in afio or someting; oh darn.. OK, use tmpfs :-) *
1755 ****************************************************************************/
1756 mr_asprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld", current_tarball_number);
1757 mr_asprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir, current_tarball_number);
1758 mr_asprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp", bkpinfo->tmpdir, current_tarball_number);
1759
1760 res = read_file_from_stream_to_file(afio_fname, size);
1761 if (strstr(tarball_fname, ".star")) {
1762 bkpinfo->use_star = TRUE;
1763 }
1764 if (res) {
1765 log_msg(1, "Warning - error reading afioball from tape");
1766 }
1767 if (bkpinfo->compression_level == 0) {
1768 mr_asprintf(executable, "%s", "");
1769 } else {
1770 if (bkpinfo->use_star) {
1771 mr_asprintf(executable, "%s", " -bz");
1772 } else {
1773 mr_asprintf(executable, "-P %s -Z", bkpinfo->zip_exe);
1774 }
1775 }
1776
1777 if (!filelist) // if unconditional restore then restore entire fileset
1778 {
1779 restore_this_fileset = TRUE;
1780 } else // If restoring selectively then get TOC from tarball
1781 {
1782 if (strstr(tarball_fname, ".star.")) {
1783 use_star = TRUE;
1784 mr_asprintf(command, "star -t file=%s %s", afio_fname, executable);
1785 } else {
1786 use_star = FALSE;
1787 mr_asprintf(command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE, executable, afio_fname);
1788 }
1789 mr_strcat(command, " > %s 2>> %s", filelist_fname, MONDO_LOGFILE);
1790 log_msg(1, "command = %s", command);
1791 if (system(command)) {
1792 log_msg(4, "Warning - error occurred while retrieving TOC");
1793 }
1794 mr_free(command);
1795
1796 if ((matches =
1797 save_filelist_entries_in_common(filelist_fname, filelist,
1798 filelist_subset_fname,
1799 use_star))
1800 <= 0 || length_of_file(filelist_subset_fname) < 2) {
1801 if (length_of_file(filelist_subset_fname) < 2) {
1802 log_msg(1, "No matches found in fileset %ld",
1803 current_tarball_number);
1804 }
1805 log_msg(2, "Skipping fileset %ld", current_tarball_number);
1806 restore_this_fileset = FALSE;
1807 } else {
1808 log_msg(5, "%ld matches. Saved fileset %ld's subset to %s",
1809 matches, current_tarball_number,
1810 filelist_subset_fname);
1811 restore_this_fileset = TRUE;
1812 }
1813 }
1814
1815// Concoct the call to star/afio to restore files
1816 if (strstr(tarball_fname, ".star.")) {
1817 // star
1818 mr_asprintf(command, "star -x file=%s %s", afio_fname, executable);
1819 if (filelist) {
1820 mr_strcat(command, " list=%s", filelist_subset_fname);
1821 }
1822 } else {
1823 // afio
1824 mr_asprintf(command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE, executable);
1825 if (filelist) {
1826 mr_strcat(command, " -w %s", filelist_subset_fname);
1827 }
1828 mr_strcat(command, " %s", afio_fname);
1829 }
1830 mr_strcat(command, " 2>> %s", MONDO_LOGFILE);
1831 mr_free(executable);
1832
1833// Call if IF there are files to restore (selectively/unconditionally)
1834 if (restore_this_fileset) {
1835 log_msg(1, "Calling command='%s'", command);
1836 paranoid_system(command);
1837
1838 if (g_getfattr) {
1839 log_it("Restoring xattr stuff");
1840 res = set_fattr_list(filelist_subset_fname, xattr_fname);
1841 if (res) {
1842 log_msg(1, "Errors occurred while setting xattr");
1843 } else {
1844 log_msg(1, "I set xattr OK");
1845 }
1846 retval += res;
1847 }
1848
1849 if (g_getfacl) {
1850 log_it("Restoring acl stuff");
1851 res = set_acl_list(filelist_subset_fname, acl_fname);
1852 if (res) {
1853 log_msg(1, "Errors occurred while setting ACL");
1854 } else {
1855 log_msg(1, "I set ACL OK");
1856 }
1857 retval += res;
1858 }
1859
1860 } else {
1861 log_msg(1, "NOT CALLING '%s'", command);
1862 }
1863 mr_free(command);
1864
1865 if (does_file_exist("/PAUSE") && current_tarball_number >= 50) {
1866 log_to_screen("Paused after set %ld", current_tarball_number);
1867 popup_and_OK("Pausing. Press ENTER to continue.");
1868 }
1869
1870 unlink(filelist_subset_fname);
1871 mr_free(filelist_subset_fname);
1872 unlink(filelist_fname);
1873 mr_free(filelist_fname);
1874 unlink(afio_fname);
1875 mr_free(afio_fname);
1876
1877 return (retval);
1878}
1879
1880/**************************************************************************
1881 *END_RESTORE_A_TARBALL_FROM_STREAM *
1882 **************************************************************************/
1883
1884
1885
1886
1887/**
1888 * Restore all biggiefiles from all media in this CD backup.
1889 * The CD with the last afioball should be currently mounted.
1890 * @param bkpinfo The backup information structure. @c backup_media_type is the
1891 * only field used in this function.
1892 * @param filelist The node structure containing the list of files to be
1893 * restored. If a prospective biggiefile is not in this list, it will be ignored.
1894 * @return 0 for success, nonzero for failure.
1895 */
1896int restore_all_biggiefiles_from_CD(struct s_node *filelist) {
1897
1898 int retval = 0;
1899 int res = 0;
1900 long noof_biggiefiles, bigfileno = 0, total_slices;
1901 /** malloc **/
1902 char *tmp1 = NULL;
1903 char *mds = NULL;
1904 bool just_changed_cds = FALSE;
1905 char *xattr_fname = NULL;
1906 char *acl_fname = NULL;
1907 char *biggies_whose_EXATs_we_should_set = NULL; // EXtended ATtributes
1908 char *pathname_of_last_biggie_restored;
1909 FILE *fbw = NULL;
1910
1911 malloc_string(pathname_of_last_biggie_restored);
1912 assert(bkpinfo != NULL);
1913
1914 mr_asprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
1915 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
1916 log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set);
1917 }
1918
1919 tmp1 = read_cfg_var(MINDI_CACHE"/mondorestore.cfg", "total-slices");
1920 total_slices = atol(tmp1);
1921 mr_free(tmp1);
1922
1923 mr_asprintf(tmp1, "Reassembling large files ");
1924 mvaddstr_and_log_it(g_currentY, 0, tmp1);
1925 mr_free(tmp1);
1926
1927 if (length_of_file(BIGGIELIST) < 6) {
1928 log_msg(1, "OK, no biggielist; not restoring biggiefiles");
1929 return (0);
1930 }
1931 noof_biggiefiles = count_lines_in_file(BIGGIELIST);
1932 if (noof_biggiefiles <= 0) {
1933 log_msg(2, "OK, no biggiefiles in biggielist; not restoring biggiefiles");
1934 return (0);
1935 }
1936 log_msg(2, "OK, there are %ld biggiefiles in the archives", noof_biggiefiles);
1937
1938 open_progress_form("Reassembling large files",
1939 "I am now reassembling all the large files.",
1940 "Please wait. This may take some time.",
1941 "", total_slices);
1942 for (bigfileno = 0 ; bigfileno < noof_biggiefiles ;) {
1943 log_msg(2, "Thinking about restoring bigfile %ld", bigfileno + 1);
1944 if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) {
1945 log_msg(3, "...but its first slice isn't on this CD. Perhaps this was a selective restore?");
1946 mds = media_descriptor_string(bkpinfo->backup_media_type);
1947 log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d", bigfileno + 1, mds, g_current_media_number);
1948 log_msg(3, "Slicename would have been %s",
1949 slice_fname(bigfileno, 0, ARCHIVES_PATH, ""));
1950 // I'm not positive 'just_changed_cds' is even necessary...
1951 if (just_changed_cds) {
1952 just_changed_cds = FALSE;
1953 log_msg(3, "I'll continue to scan this CD for bigfiles to be restored.");
1954 } else if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) {
1955 insist_on_this_cd_number(++g_current_media_number);
1956 log_to_screen("Restoring from %s #%d", mds, g_current_media_number);
1957 just_changed_cds = TRUE;
1958 } else {
1959 /* That big file doesn't exist, but the followings may */
1960 /* So we need to continue looping */
1961 log_msg(2, "There was no bigfile #%ld. That's OK.", bigfileno + 1);
1962 log_msg(2, "I'm going to stop restoring bigfiles now.");
1963 retval++;
1964 bigfileno++;
1965 }
1966 mr_free(mds);
1967 } else {
1968 just_changed_cds = FALSE;
1969 mr_asprintf(tmp1, "Restoring big file %ld", bigfileno + 1);
1970 update_progress_form(tmp1);
1971 mr_free(tmp1);
1972 res = restore_a_biggiefile_from_CD(bigfileno, filelist, pathname_of_last_biggie_restored);
1973 log_it("%s",pathname_of_last_biggie_restored);
1974 if (fbw && pathname_of_last_biggie_restored[0]) {
1975 fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
1976 }
1977 retval += res;
1978 bigfileno++;
1979
1980 }
1981 }
1982
1983 if (fbw) {
1984 fclose(fbw);
1985 if (g_getfattr) {
1986 mr_asprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
1987 if (length_of_file(xattr_fname) > 0) {
1988 set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
1989 }
1990 mr_free(xattr_fname);
1991 }
1992 if (g_getfacl) {
1993 mr_asprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
1994 if (length_of_file(acl_fname) > 0) {
1995 set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
1996 }
1997 mr_free(acl_fname);
1998 }
1999 }
2000 mr_free(biggies_whose_EXATs_we_should_set);
2001
2002 if (does_file_exist("/PAUSE")) {
2003 popup_and_OK("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
2004 }
2005 close_progress_form();
2006 if (retval) {
2007 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2008 } else {
2009 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2010 }
2011 paranoid_free(pathname_of_last_biggie_restored);
2012 return (retval);
2013}
2014
2015/**************************************************************************
2016 *END_RESTORE_ALL_BIGGIFILES_FROM_CD *
2017 **************************************************************************/
2018
2019
2020
2021/**
2022 * Restore all afioballs from all CDs in the backup.
2023 * The first CD should be inserted (if not, it will be asked for).
2024 * @param bkpinfo The backup information structure. @c backup_media_type is the
2025 * only field used in @e this function.
2026 * @param filelist The node structure containing the list of files to be
2027 * restored. If no file in some particular afioball is in this list, afio will
2028 * still be called for that fileset, but nothing will be written.
2029 * @return 0 for success, or the number of filesets that failed.
2030 */
2031int
2032restore_all_tarballs_from_CD(struct s_node *filelist)
2033{
2034 int retval = 0;
2035 int res;
2036 int attempts;
2037 long current_tarball_number = 0;
2038 long max_val;
2039 /**malloc ***/
2040 char *mds = NULL;
2041 char *tmp1 = NULL;
2042 char *tarball_fname = NULL;
2043 char *progress_str = NULL;
2044
2045 assert(bkpinfo != NULL);
2046
2047 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
2048 log_msg(2, "Insisting on 1st media, so that I can have a look at LAST-FILELIST-NUMBER");
2049 if (g_current_media_number != 1) {
2050 log_msg(3, "OK, that's jacked up.");
2051 g_current_media_number = 1;
2052 }
2053 insist_on_this_cd_number(g_current_media_number);
2054 tmp1 = read_cfg_var(MINDI_CACHE"/mondorestore.cfg", "last-filelist-number");
2055 max_val = atol(tmp1) + 1;
2056 mr_free(tmp1);
2057
2058 mds = media_descriptor_string(bkpinfo->backup_media_type);
2059 mr_asprintf(progress_str, "Restoring from %s #%d", mds, g_current_media_number);
2060
2061 log_to_screen(progress_str);
2062 open_progress_form("Restoring from archives",
2063 "Restoring data from the archives.",
2064 "Please wait. This may take some time.",
2065 progress_str, max_val);
2066 for (;;) {
2067 insist_on_this_cd_number(g_current_media_number);
2068 update_progress_form(progress_str);
2069 mr_free(progress_str);
2070
2071 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2", current_tarball_number);
2072 if (!does_file_exist(tarball_fname)) {
2073 mr_free(tarball_fname);
2074 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.gz", current_tarball_number);
2075 }
2076 if (!does_file_exist(tarball_fname)) {
2077 mr_free(tarball_fname);
2078 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzma", current_tarball_number);
2079 }
2080 if (!does_file_exist(tarball_fname)) {
2081 mr_free(tarball_fname);
2082 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo", current_tarball_number);
2083 }
2084 if (!does_file_exist(tarball_fname)) {
2085 mr_free(tarball_fname);
2086 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.", current_tarball_number);
2087 }
2088 if (!does_file_exist(tarball_fname)) {
2089 mr_free(tarball_fname);
2090 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.bz2", current_tarball_number);
2091 }
2092 if (!does_file_exist(tarball_fname)) {
2093 mr_free(tarball_fname);
2094 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.", current_tarball_number);
2095 }
2096 if (!does_file_exist(tarball_fname)) {
2097 if (current_tarball_number == 0) {
2098 log_to_screen
2099 ("No tarballs. Strange. Maybe you only backed up freakin' big files?");
2100 mr_free(tarball_fname);
2101 return (0);
2102 }
2103 if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")
2104 || system("find " MNT_CDROM
2105 "/archives/slice* > /dev/null 2> /dev/null") ==
2106 0) {
2107 break;
2108 }
2109 g_current_media_number++;
2110 mr_asprintf(progress_str, "Restoring from %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number);
2111 log_to_screen(progress_str);
2112 } else {
2113 mr_asprintf(progress_str, "Restoring from fileset #%ld on %s #%d", current_tarball_number, mds, g_current_media_number);
2114 for (res = 999, attempts = 0; attempts < 3 && res != 0; attempts++) {
2115 res = restore_a_tarball_from_CD(tarball_fname, current_tarball_number, filelist);
2116 }
2117 mr_asprintf(tmp1, "%s #%d, fileset #%ld - restore ", mds, g_current_media_number, current_tarball_number);
2118 if (res) {
2119 mr_strcat(tmp1, "reported errors");
2120 } else if (attempts > 1) {
2121 mr_strcat(tmp1, "succeeded");
2122 } else {
2123 mr_strcat(tmp1, "succeeded");
2124 }
2125 if (attempts > 1) {
2126 mr_strcat(tmp1, " (%d attempts) - review logs", attempts);
2127 }
2128 if (attempts > 1) {
2129 log_to_screen(tmp1);
2130 }
2131 mr_free(tmp1);
2132
2133 retval += res;
2134 current_tarball_number++;
2135 g_current_progress++;
2136 }
2137 mr_free(tarball_fname);
2138
2139 /* Now we need to umount the current media to have the next mounted by insist_on_this_cd_number */
2140 /* run_program_and_log_output("umount " MNT_CDROM, FALSE); */
2141 }
2142 mr_free(mds);
2143 mr_free(progress_str);
2144
2145 close_progress_form();
2146 if (retval) {
2147 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2148 } else {
2149 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2150 }
2151
2152 return (retval);
2153}
2154
2155/**************************************************************************
2156 *END_RESTORE_ALL_TARBALLS_FROM_CD *
2157 **************************************************************************/
2158
2159
2160
2161/**
2162 * Restore all biggiefiles from the currently opened stream.
2163 * @param bkpinfo The backup information structure. Passed to other functions.
2164 * @param filelist The node structure containing the list of files to be
2165 * restored. If a prospective biggiefile is not in the list, it will be ignored.
2166 * @return 0 for success, or the number of biggiefiles that failed.
2167 */
2168int
2169restore_all_biggiefiles_from_stream(struct s_node *filelist)
2170{
2171 long noof_biggiefiles;
2172 long current_bigfile_number = 0;
2173 long total_slices;
2174
2175 int retval = 0;
2176 int res = 0;
2177 int ctrl_chr;
2178
2179 /** malloc add ****/
2180 char *tmp1 = NULL;
2181 char *biggie_fname;
2182 char *biggie_cksum;
2183 char *xattr_fname = NULL;
2184 char *acl_fname = NULL;
2185 char *p;
2186 char *pathname_of_last_biggie_restored;
2187 char *biggies_whose_EXATs_we_should_set = NULL; // EXtended ATtributes
2188 long long biggie_size;
2189 FILE *fbw = NULL;
2190
2191 malloc_string(biggie_fname);
2192 malloc_string(biggie_cksum);
2193 malloc_string(pathname_of_last_biggie_restored);
2194 assert(bkpinfo != NULL);
2195
2196 tmp1 = read_cfg_var(MINDI_CACHE"/mondorestore.cfg", "total-slices");
2197 total_slices = atol(tmp1);
2198 mr_free(tmp1);
2199
2200 if (g_getfattr) {
2201 mr_asprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
2202 }
2203 if (g_getfacl) {
2204 mr_asprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
2205 }
2206 mr_asprintf(tmp1, "Reassembling large files ");
2207 mvaddstr_and_log_it(g_currentY, 0, tmp1);
2208 mr_free(tmp1);
2209
2210 mr_asprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
2211 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
2212 log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set);
2213 }
2214
2215 // get xattr and acl files if they're there
2216 res = read_header_block_from_stream(&biggie_size, biggie_fname, &ctrl_chr);
2217 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
2218 res =
2219 read_EXAT_files_from_tape(&biggie_size, biggie_fname, &ctrl_chr, xattr_fname, acl_fname);
2220 }
2221
2222 noof_biggiefiles = atol(biggie_fname);
2223 log_msg(2, "OK, there are %ld biggiefiles in the archives", noof_biggiefiles);
2224 open_progress_form("Reassembling large files",
2225 "I am now reassembling all the large files.",
2226 "Please wait. This may take some time.",
2227 "", total_slices);
2228
2229 for (res =
2230 read_header_block_from_stream(&biggie_size, biggie_fname,
2231 &ctrl_chr);
2232 ctrl_chr != BLK_STOP_BIGGIEFILES;
2233 res =
2234 read_header_block_from_stream(&biggie_size, biggie_fname,
2235 &ctrl_chr)) {
2236 if (ctrl_chr != BLK_START_A_NORMBIGGIE
2237 && ctrl_chr != BLK_START_A_PIHBIGGIE) {
2238 wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr);
2239 }
2240 p = strrchr(biggie_fname, '/');
2241 if (!p) {
2242 p = biggie_fname;
2243 } else {
2244 p++;
2245 }
2246 mr_asprintf(tmp1, "Restoring big file %ld (%lld K)", current_bigfile_number + 1, biggie_size / 1024);
2247 update_progress_form(tmp1);
2248 mr_free(tmp1);
2249 res = restore_a_biggiefile_from_stream(biggie_fname,
2250 current_bigfile_number,
2251 biggie_cksum,
2252 biggie_size,
2253 filelist, ctrl_chr,
2254 pathname_of_last_biggie_restored);
2255 log_msg(1, "I believe I have restored %s",
2256 pathname_of_last_biggie_restored);
2257 if (fbw && pathname_of_last_biggie_restored[0]) {
2258 fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
2259 }
2260 retval += res;
2261 current_bigfile_number++;
2262
2263 }
2264 if (current_bigfile_number != noof_biggiefiles
2265 && noof_biggiefiles != 0) {
2266 log_msg(1, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n", current_bigfile_number, noof_biggiefiles);
2267 } else {
2268 log_msg(1, "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.", noof_biggiefiles, current_bigfile_number);
2269 }
2270
2271 if (fbw) {
2272 fclose(fbw);
2273 if (length_of_file(biggies_whose_EXATs_we_should_set) > 2) {
2274 log_it("Setting biggie-EXATs");
2275 if (g_getfattr) {
2276 if (length_of_file(xattr_fname) > 0) {
2277 log_msg(1, "set_fattr_List(%s,%s)", biggies_whose_EXATs_we_should_set, xattr_fname);
2278 set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
2279 }
2280 }
2281 if (g_getfacl) {
2282 if (length_of_file(acl_fname) > 0) {
2283 log_msg(1, "set_acl_list(%s,%s)", biggies_whose_EXATs_we_should_set, acl_fname);
2284 set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
2285 }
2286 }
2287 } else {
2288 log_it("No biggiefiles selected. So, no biggie-EXATs to set.");
2289 }
2290 }
2291 mr_free(xattr_fname);
2292 mr_free(acl_fname);
2293 mr_free(biggies_whose_EXATs_we_should_set);
2294
2295 if (does_file_exist("/PAUSE")) {
2296 popup_and_OK
2297 ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
2298 }
2299
2300 close_progress_form();
2301 if (retval) {
2302 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2303 } else {
2304 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2305 }
2306 paranoid_free(pathname_of_last_biggie_restored);
2307 paranoid_free(biggie_fname);
2308 paranoid_free(biggie_cksum);
2309 return (retval);
2310}
2311
2312/**************************************************************************
2313 *END_RESTORE_ALL_BIGGIEFILES_FROM_STREAM *
2314 **************************************************************************/
2315
2316
2317
2318
2319
2320
2321/**
2322 * Restore all afioballs from the currently opened tape stream.
2323 * @param bkpinfo The backup information structure. Fields used:
2324 * - @c bkpinfo->backup_media_type
2325 * - @c bkpinfo->restore_path
2326 * @param filelist The node structure containing the list of files to be
2327 * restored. If no file in an afioball is in this list, afio will still be
2328 * called for that fileset, but nothing will be written.
2329 * @return 0 for success, or the number of filesets that failed.
2330 */
2331int restore_all_tarballs_from_stream(struct s_node *filelist)
2332{
2333 int retval = 0;
2334 int res;
2335 long current_afioball_number = 0;
2336 int ctrl_chr;
2337 long max_val /*, total_noof_files */ ;
2338
2339 /** malloc **/
2340 char *tmp = NULL;
2341 char *mds = NULL;
2342 char *progress_str = NULL;
2343 char *tmp_fname;
2344 char *xattr_fname = NULL;
2345 char *acl_fname = NULL;
2346
2347 long long tmp_size;
2348
2349 malloc_string(tmp_fname);
2350 assert(bkpinfo != NULL);
2351 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
2352 tmp = read_cfg_var(MINDI_CACHE"/mondorestore.cfg", "last-filelist-number");
2353 max_val = atol(tmp) + 1;
2354 mr_free(tmp);
2355
2356 chdir(bkpinfo->restore_path); /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */
2357
2358 run_program_and_log_output("pwd", 5);
2359
2360 mr_asprintf(progress_str, "Restoring from media #%d", g_current_media_number);
2361 log_to_screen(progress_str);
2362 open_progress_form("Restoring from archives",
2363 "Restoring data from the archives.",
2364 "Please wait. This may take some time.",
2365 progress_str, max_val);
2366
2367 log_msg(3, "hey");
2368
2369 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2370 if (res) {
2371 log_msg(2, "Warning - error reading afioball from tape");
2372 }
2373 retval += res;
2374 if (ctrl_chr != BLK_START_AFIOBALLS) {
2375 wrong_marker(BLK_START_AFIOBALLS, ctrl_chr);
2376 }
2377 log_msg(2, "ho");
2378 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2379 while (ctrl_chr != BLK_STOP_AFIOBALLS) {
2380 update_progress_form(progress_str);
2381 if (g_getfattr) {
2382 mr_asprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number);
2383 unlink(xattr_fname);
2384 }
2385 if (g_getfacl) {
2386 mr_asprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number);
2387 unlink(acl_fname);
2388 }
2389 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
2390 log_it("Reading EXAT files from tape");
2391 res = read_EXAT_files_from_tape(&tmp_size, tmp_fname, &ctrl_chr, xattr_fname, acl_fname);
2392 }
2393 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
2394 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
2395 }
2396 log_msg(4, "Restoring from fileset #%ld (name=%s, size=%ld K)", current_afioball_number, tmp_fname, (long) tmp_size >> 10);
2397 res = restore_a_tarball_from_stream(tmp_fname, current_afioball_number, filelist, tmp_size, xattr_fname, acl_fname);
2398 retval += res;
2399 if (res) {
2400 log_to_screen("Fileset %ld - errors occurred", current_afioball_number);
2401 }
2402 res =
2403 read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2404 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
2405 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
2406 }
2407
2408 current_afioball_number++;
2409 g_current_progress++;
2410 mds = media_descriptor_string(bkpinfo->backup_media_type),
2411
2412 mr_free(progress_str);
2413 mr_asprintf(progress_str, "Restoring from fileset #%ld on %s #%d", current_afioball_number, mds, g_current_media_number);
2414 mr_free(mds);
2415 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2416 if (g_getfattr) {
2417 unlink(xattr_fname);
2418 }
2419 if (g_getfacl) {
2420 unlink(acl_fname);
2421 }
2422 } // next
2423 mr_free(progress_str);
2424 if (g_getfattr) {
2425 mr_free(xattr_fname);
2426 }
2427 if (g_getfacl) {
2428 mr_free(acl_fname);
2429 }
2430
2431 log_msg(1, "All done with afioballs");
2432 close_progress_form();
2433 if (retval) {
2434 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2435 } else {
2436 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2437 }
2438 paranoid_free(tmp_fname);
2439 return (retval);
2440}
2441
2442/**************************************************************************
2443 *END_ RESTORE_ALL_TARBALLS_FROM_STREAM *
2444 **************************************************************************/
2445
2446/* @} - end of LLrestoreGroup */
2447
2448
2449/**
2450 * Restore all files in @p filelist.
2451 * @param bkpinfo The backup information structure. Most fields are used.
2452 * @param filelist The node structure containing the list of files to be
2453 * restored.
2454 * @return 0 for success, or the number of afioballs and biggiefiles that failed.
2455 * @ingroup restoreGroup
2456 */
2457int restore_everything(struct s_node *filelist)
2458{
2459 int resA;
2460 int resB;
2461
2462 /** mallco ***/
2463 char *cwd;
2464 char *newpath;
2465 char *tmp = NULL;
2466 assert(bkpinfo != NULL);
2467
2468 malloc_string(cwd);
2469 malloc_string(newpath);
2470 log_msg(2, "restore_everything() --- starting");
2471 g_current_media_number = 1;
2472 getcwd(cwd, MAX_STR_LEN - 1);
2473 mr_asprintf(tmp, "mkdir -p %s", bkpinfo->restore_path);
2474 run_program_and_log_output(tmp, FALSE);
2475 mr_free(tmp);
2476
2477 log_msg(1, "Changing dir to %s", bkpinfo->restore_path);
2478 chdir(bkpinfo->restore_path);
2479 getcwd(newpath, MAX_STR_LEN - 1);
2480 log_msg(1, "path is now %s", newpath);
2481 log_msg(1, "restoring everything");
2482 tmp = find_home_of_exe("petris");
2483 if (!tmp && !g_text_mode) {
2484 newtDrawRootText(0, g_noof_rows - 2,
2485 "Press ALT-<left cursor> twice to play Petris :-) ");
2486 newtRefresh();
2487 }
2488 mr_free(tmp);
2489
2490 mvaddstr_and_log_it(g_currentY, 0, "Preparing to read your archives");
2491 mount_media();
2492 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2493 mvaddstr_and_log_it(g_currentY++, 0,
2494 "Restoring OS and data from streaming media");
2495 if (bkpinfo->backup_media_type == cdstream) {
2496 openin_cdstream();
2497 } else {
2498 openin_tape();
2499 }
2500 resA = restore_all_tarballs_from_stream(filelist);
2501 resB = restore_all_biggiefiles_from_stream(filelist);
2502 if (bkpinfo->backup_media_type == cdstream) {
2503 closein_cdstream();
2504 } else {
2505 closein_tape();
2506 }
2507 } else {
2508 mvaddstr_and_log_it(g_currentY++, 0,
2509 "Restoring OS and data from CD/USB ");
2510 resA = restore_all_tarballs_from_CD(filelist);
2511 resB = restore_all_biggiefiles_from_CD(filelist);
2512 }
2513 chdir(cwd);
2514 if (resA + resB) {
2515 log_to_screen("Errors occurred while data was being restored.");
2516 }
2517 if (length_of_file("/etc/raidtab") > 0) {
2518 log_msg(2, "Copying local raidtab to restored filesystem");
2519 run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING
2520 "/etc/raidtab", FALSE);
2521 }
2522 kill_petris();
2523 log_msg(2, "restore_everything() --- leaving");
2524 paranoid_free(cwd);
2525 paranoid_free(newpath);
2526 return (resA + resB);
2527}
2528
2529/**************************************************************************
2530 *END_RESTORE_EVERYTHING *
2531 **************************************************************************/
2532
2533
2534extern void wait_until_software_raids_are_prepped(char *, int);
2535
2536
2537char which_restore_mode(void);
2538
2539
2540/**
2541 * Log a "don't panic" message to the logfile.
2542 */
2543void welcome_to_mondorestore()
2544{
2545 log_msg(0, "-------------- Mondo Restore v%s -------------", PACKAGE_VERSION);
2546 log_msg(0, "DON'T PANIC! Mondorestore logs almost everything, so please ");
2547 log_msg(0, "don't break out in a cold sweat just because you see a few ");
2548 log_msg(0, "error messages in the log. Read them; analyze them; see if ");
2549 log_msg(0, "they are significant; above all, verify your backups! Please");
2550 log_msg(0, "attach a compressed copy of this log to any e-mail you send ");
2551 log_msg(0, "to the Mondo mailing list when you are seeking technical ");
2552 log_msg(0, "support. Without it, we can't help you. - DevTeam");
2553 log_msg(0, "------------------------------------------------------------");
2554 log_msg(0, "BTW, despite (or perhaps because of) the wealth of messages,");
2555 log_msg(0, "some users are inclined to stop reading this log. If Mondo ");
2556 log_msg(0, "stopped for some reason, chances are it's detailed here. ");
2557 log_msg(0, "More than likely there's a message at the very end of this ");
2558 log_msg(0, "log that will tell you what is wrong. Please read it! ");
2559 log_msg(0, "------------------------------------------------------------");
2560}
2561
2562
2563
2564/**
2565 * Restore the user's data.
2566 * What did you think it did, anyway? :-)
2567 */
2568int main(int argc, char *argv[])
2569{
2570 FILE *fin;
2571 FILE *fout;
2572 int retval = 0;
2573 int res;
2574 char *tmp = NULL;
2575
2576 struct mountlist_itself *mountlist;
2577 struct raidlist_itself *raidlist;
2578 struct s_node *filelist;
2579 char *tmp1 = NULL;
2580 char *tmp2 = NULL;
2581 bool run_postnuke = FALSE;
2582
2583 if (getuid() != 0) {
2584 fprintf(stderr, "Please run as root.\r\n");
2585 exit(127);
2586 }
2587 bkpinfo = (struct s_bkpinfo *)mr_malloc(sizeof(struct s_bkpinfo));
2588 init_bkpinfo();
2589
2590 g_loglevel = DEFAULT_MR_LOGLEVEL;
2591
2592 /* Configure global variables */
2593 malloc_libmondo_global_strings();
2594 tmp1 = call_program_and_get_last_line_of_output("cat " CMDLINE,TRUE);
2595 if (strstr(tmp1, "textonly")) {
2596 g_text_mode = TRUE;
2597 log_msg(1, "TEXTONLY MODE");
2598 } else {
2599 g_text_mode = FALSE;
2600 } // newt :-)
2601 mr_free(tmp1);
2602
2603 /* Init GUI */
2604 setup_newt_stuff(); /* call newtInit and setup screen log */
2605
2606 tmp1 = call_program_and_get_last_line_of_output("which mondorestore",TRUE);
2607 strcpy(g_mondo_home, tmp1);
2608 mr_free(tmp1);
2609
2610 g_current_media_number = 1; // precaution
2611
2612 run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE);
2613
2614 setup_MR_global_filenames(); // malloc() and set globals, using bkpinfo->tmpdir etc.
2615 bkpinfo->backup_media_type = none; // in case boot disk was made for one backup type but user wants to restore from another backup type
2616 bkpinfo->restore_data = TRUE; // Well, yeah :-)
2617 if (am_I_in_disaster_recovery_mode()) {
2618 run_program_and_log_output("mount / -o remount,rw", 2);
2619 } // for b0rken distros
2620 g_main_pid = getpid();
2621 srandom((int) (time(NULL)));
2622 set_signals(TRUE);
2623 g_kernel_version = get_kernel_version();
2624
2625 log_msg(1, "FYI - mountlist = %s", MINDI_CACHE"/mountlist.txt");
2626 mkdir(MNT_CDROM, 0x770);
2627 make_hole_for_dir(MONDO_CACHE);
2628
2629 /* Backup original mountlist.txt */
2630 mr_asprintf(tmp, "cp -f "MINDI_CACHE"/mountlist.txt "MINDI_CACHE"/mountlist.txt.orig");
2631 run_program_and_log_output(tmp, FALSE);
2632 mr_free(tmp);
2633
2634 /* Init directories */
2635 make_hole_for_dir("/var/log");
2636 make_hole_for_dir("/tmp/tmpfs"); /* just in case... */
2637 run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
2638
2639 run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE);
2640
2641 welcome_to_mondorestore();
2642 if (bkpinfo->disaster_recovery) {
2643 log_msg(1, "I am in disaster recovery mode");
2644 } else {
2645 log_msg(1, "I am in normal, live mode");
2646 }
2647
2648 log_it("what time is it");
2649
2650 mountlist = (struct mountlist_itself *)mr_malloc(sizeof(struct mountlist_itself));
2651 raidlist = (struct raidlist_itself *)mr_malloc(sizeof(struct raidlist_itself));
2652
2653 /* Process command-line parameters */
2654 if (argc == 2 && strcmp(argv[1], "--edit-mountlist") == 0) {
2655#ifdef __FreeBSD__
2656 system("mv -f /tmp/raidconf.txt /etc/raidtab");
2657 if (!does_file_exist("/etc/raidtab"))
2658 system("vinum printconfig > /etc/raidtab");
2659#endif
2660 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2661 res = let_user_edit_the_mountlist(mountlist, raidlist);
2662#ifdef __FreeBSD__
2663 system("mv -f /etc/raidtab /tmp/raidconf.txt");
2664#endif
2665 paranoid_MR_finish(res);
2666 }
2667
2668 if (argc == 3 && strcmp(argv[1], "--echo-to-screen") == 0) {
2669 fout = fopen("/tmp/out.txt", "w");
2670 fput_string_one_char_at_a_time(stderr, argv[2]);
2671 finish(0);
2672 }
2673
2674 if (argc == 5 && strcmp(argv[1], "--common") == 0) {
2675 g_loglevel = 6;
2676 filelist = load_filelist(argv[2]);
2677 if (!filelist) {
2678 fatal_error("Failed to load filelist");
2679 }
2680 toggle_node_selection(filelist, FALSE);
2681 toggle_all_root_dirs_on(filelist);
2682 // BERLIOS: /usr/lib ???
2683 toggle_path_selection(filelist, "/usr/share", TRUE);
2684 save_filelist(filelist, "/tmp/out.txt");
2685 mr_asprintf(tmp1, "%s", argv[3]);
2686 mr_asprintf(tmp2, "%s", argv[4]);
2687
2688 res = save_filelist_entries_in_common(tmp1, filelist, tmp2, FALSE);
2689 mr_free(tmp1);
2690 mr_free(tmp2);
2691
2692 free_filelist(filelist);
2693 printf("res = %d", res);
2694 finish(0);
2695 }
2696
2697 if (argc == 3 && strcmp(argv[1], "--popuplist") == 0) {
2698 popup_changelist_from_file(argv[2]);
2699 paranoid_MR_finish(0);
2700 }
2701
2702 if (argc == 5 && strcmp(argv[1], "--copy") == 0) {
2703 log_msg(1, "SCORE");
2704 g_loglevel = 10;
2705 if (strstr(argv[2], "save")) {
2706 log_msg(1, "Saving from %s to %s", argv[3], argv[4]);
2707 fin = fopen(argv[3], "r");
2708 fout = fopen(argv[4], "w");
2709 copy_from_src_to_dest(fin, fout, 'w');
2710 fclose(fin);
2711 fin = fopen(argv[3], "r");
2712 copy_from_src_to_dest(fin, fout, 'w');
2713 fclose(fout);
2714 fclose(fin);
2715 } else if (strstr(argv[2], "restore")) {
2716 fout = fopen(argv[3], "w");
2717 fin = fopen(argv[4], "r");
2718 copy_from_src_to_dest(fout, fin, 'r');
2719 fclose(fin);
2720 fin = fopen(argv[4], "r");
2721 copy_from_src_to_dest(fout, fin, 'r');
2722 fclose(fout);
2723 fclose(fin);
2724 } else {
2725 fatal_error("Unknown additional param");
2726 }
2727 finish(0);
2728 }
2729
2730 if (argc == 3 && strcmp(argv[1], "--mdstat") == 0) {
2731 wait_until_software_raids_are_prepped(argv[2], 100);
2732 finish(0);
2733 }
2734
2735 if (argc == 3 && strcmp(argv[1], "--mdconv") == 0) {
2736 finish(create_raidtab_from_mdstat(argv[2]));
2737 }
2738
2739 if (argc == 2 && strcmp(argv[1], "--live-grub") == 0) {
2740 retval = run_grub(FALSE, "/dev/hda");
2741 if (retval) {
2742 log_to_screen("Failed to write Master Boot Record");
2743 }
2744 paranoid_MR_finish(0);
2745 }
2746 if (argc == 3 && strcmp(argv[1], "--paa") == 0) {
2747 g_current_media_number = atoi(argv[2]);
2748 pause_and_ask_for_cdr(5, NULL);
2749 paranoid_MR_finish(0);
2750 }
2751 if ((argc == 2 && strcmp(argv[1], "--partition-only") == 0) && (bkpinfo->disaster_recovery)) {
2752 log_msg(0, "Partitioning only.");
2753 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2754 load_mountlist(mountlist, MINDI_CACHE"/mountlist.txt");
2755 res = partition_everything(mountlist);
2756 finish(res);
2757 }
2758
2759 if ((argc == 2 && strcmp(argv[1], "--format-only") == 0) && (bkpinfo->disaster_recovery)) {
2760 log_msg(0, "Formatting only.");
2761 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2762 res = format_everything(mountlist, FALSE, raidlist);
2763 finish(res);
2764 }
2765
2766 if ((argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0) && (bkpinfo->disaster_recovery)) {
2767 log_msg(0, "Stopping LVM and RAID");
2768 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2769 load_mountlist(mountlist, MINDI_CACHE"/mountlist.txt");
2770 res = do_my_funky_lvm_stuff(TRUE, FALSE);
2771 res += stop_all_raid_devices(mountlist);
2772 finish(res);
2773 }
2774
2775 // Handle params here first
2776 handle_incoming_parameters(argc,argv);
2777
2778 if (!bkpinfo->disaster_recovery) { // live!
2779 log_msg(1, "I am in normal, live mode.");
2780 mount_boot_if_necessary(); /* for Gentoo users */
2781 log_msg(2, "Still here.");
2782 /* Adding an initialisation in order to avoid to hndle NULL pointer later */
2783 mr_free(bkpinfo->restore_path);
2784 mr_asprintf(bkpinfo->restore_path, "%s", "/tmp");
2785
2786 log_msg(2, "Calling restore_to_live_filesystem()");
2787 retval = restore_to_live_filesystem();
2788
2789 log_msg(2, "Still here. Yay.");
2790 if ((strlen(bkpinfo->tmpdir) > 0) && (strstr(bkpinfo->tmpdir,"mondo.tmp.") != NULL)) {
2791 mr_asprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir);
2792 run_program_and_log_output(tmp, FALSE);
2793 mr_free(tmp);
2794 }
2795 unmount_boot_if_necessary(); /* for Gentoo users */
2796 paranoid_MR_finish(retval);
2797 } else {
2798 /* Disaster recovery mode (must be) */
2799 log_msg(1, "I must be in disaster recovery mode.");
2800
2801 log_it("About to call load_mountlist and load_raidtab");
2802 mr_free(bkpinfo->restore_path);
2803 mr_asprintf(bkpinfo->restore_path, "%s", MNT_RESTORING);
2804 read_cfg_file_into_bkpinfo(MINDI_CACHE"/mondorestore.cfg");
2805 retval = load_mountlist(mountlist, MINDI_CACHE"/mountlist.txt");
2806 retval += load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2807 log_it("Returned from calling load_mountlist and load_raidtab successfully");
2808
2809 // BCO:To be reviewed
2810 if ((bkpinfo->restore_mode == compare) || (bkpinfo->restore_mode == nuke)) {
2811 if ((bkpinfo->backup_media_type == netfs) && bkpinfo->netfs_mount && !is_this_device_mounted(bkpinfo->netfs_mount)) {
2812 log_msg(1, "Mounting remote %s dir", bkpinfo->netfs_proto);
2813 mr_free(bkpinfo->isodir);
2814 mr_asprintf(bkpinfo->isodir, "/tmp/isodir");
2815 run_program_and_log_output("mkdir -p /tmp/isodir", 5);
2816 if (strstr(bkpinfo->netfs_proto, "sshfs")) {
2817 if (bkpinfo->netfs_user) {
2818 mr_asprintf(tmp, "sshfs -o ro %s@%s /tmp/isodir", bkpinfo->netfs_user,bkpinfo->netfs_mount);
2819 } else {
2820 mr_asprintf(tmp, "sshfs -o ro %s /tmp/isodir", bkpinfo->netfs_mount);
2821 }
2822 } else {
2823 if (bkpinfo->netfs_user) {
2824 mr_asprintf(tmp, "mount %s@%s -o nolock,ro /tmp/isodir", bkpinfo->netfs_user,bkpinfo->netfs_mount);
2825 } else {
2826 mr_asprintf(tmp, "mount %s -o nolock,ro /tmp/isodir", bkpinfo->netfs_mount);
2827 }
2828 }
2829 run_program_and_log_output(tmp, 1);
2830 mr_free(tmp);
2831 }
2832 }
2833
2834 if (retval) {
2835 log_to_screen("Warning - load_raidtab_into_raidlist returned an error");
2836 }
2837
2838 log_msg(1, "Send in the clowns.");
2839
2840
2841 if (bkpinfo->restore_mode == nuke) {
2842 log_it("nuking");
2843 retval += nuke_mode(mountlist, raidlist);
2844 } else if (bkpinfo->restore_mode == interactive) {
2845 log_it("catchall");
2846 retval += catchall_mode(mountlist, raidlist);
2847 } else if (bkpinfo->restore_mode == compare) {
2848 log_it("compare");
2849 retval += compare_mode(mountlist, raidlist);
2850 } else if (bkpinfo->restore_mode == isoonly) {
2851 log_it("iso");
2852 retval = iso_mode(mountlist, raidlist, FALSE);
2853 } else if (bkpinfo->restore_mode == mbr) {
2854 log_it("mbr");
2855 retval = mount_all_devices(mountlist, TRUE);
2856 if (!retval) {
2857 retval += run_boot_loader(FALSE);
2858 retval += unmount_all_devices(mountlist);
2859 }
2860 if (retval) {
2861 log_to_screen("Failed to write Master Boot Record");
2862 }
2863 } else if (bkpinfo->restore_mode == isonuke) {
2864 log_it("isonuke");
2865 retval = iso_mode(mountlist, raidlist, TRUE);
2866 } else {
2867 log_it("catchall (no mode specified in command-line call");
2868 retval += catchall_mode(mountlist, raidlist);
2869 }
2870 }
2871
2872 /* clean up at the end */
2873 if (retval) {
2874 if (does_file_exist(MONDO_CACHE"/changed.files")) {
2875 log_to_screen
2876 ("See "MONDO_CACHE"/changed.files for list of files that have changed.");
2877 }
2878 mvaddstr_and_log_it(g_currentY++,
2879 0,
2880 "Run complete. Errors were reported. Please review the logfile.");
2881 } else {
2882 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2883 mvaddstr_and_log_it(g_currentY++,
2884 0,
2885 "Run complete. Please remove media and reboot.");
2886 } else {
2887 sync();
2888 if (is_this_device_mounted(MNT_CDROM)) {
2889 run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
2890 }
2891
2892 if (!bkpinfo->please_dont_eject) {
2893 (void)eject_device("/dev/cdrom");
2894 }
2895 mvaddstr_and_log_it(g_currentY++,
2896 0,
2897 "Run complete. Please remove media and reboot.");
2898 }
2899 }
2900
2901// g_I_have_just_nuked is set true by nuke_mode() just before it returns
2902 if (!system("which post-nuke > /dev/null 2> /dev/null")) {
2903 log_msg(1, "post-nuke found; find out whether we should run it...");
2904 if (g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY")) {
2905 run_postnuke = TRUE;
2906 log_msg(1, "Yes, will run post-nuke because in nuke mode or file /POST-NUKE-ANYWAY exists.");
2907 } else if (ask_me_yes_or_no("post-nuke script found. Do you want to run it?")) {
2908 run_postnuke = TRUE;
2909 log_msg(1, "Yes, will run post-nuke because user interactively asked for it.");
2910 } else {
2911 run_postnuke = FALSE;
2912 log_msg(1, "No, will not run post-nuke.");
2913 }
2914 } else {
2915 log_msg(1, "No post-nuke found.");
2916 }
2917 if (run_postnuke) {
2918 log_to_screen("Running post-nuke...");
2919 if (mount_all_devices(mountlist, TRUE)) {
2920 log_to_screen
2921 ("Unable to re-mount partitions for post-nuke stuff");
2922 } else {
2923 log_msg(1, "Re-mounted partitions for post-nuke stuff");
2924 mr_asprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path, retval);
2925 log_msg(2, "Calling '%s'", tmp);
2926 if ((res = run_program_and_log_output(tmp, 0))) {
2927 log_OS_error(tmp);
2928 }
2929 mr_free(tmp);
2930 log_msg(1, "post-nuke returned w/ res=%d", res);
2931 }
2932 unmount_all_devices(mountlist);
2933 log_to_screen("I've finished post-nuking.");
2934 }
2935
2936/*
2937 log_to_screen("If you are REALLY in a hurry, hit Ctrl-Alt-Del now.");
2938 log_to_screen("Otherwise, please wait until the RAID disks are done.");
2939 wait_until_software_raids_are_prepped("/proc/mdstat", 100);
2940 log_to_screen("Thank you.");
2941*/
2942 unlink("/tmp/mondo-run-prog.tmp");
2943 set_signals(FALSE);
2944 log_to_screen("Restore log (%s) copied to /var/log on your hard disk", MONDO_LOGFILE);
2945 log_to_screen("Mondo-restore is exiting (retval=%d) ", retval);
2946
2947 mr_asprintf(tmp, "umount -d %s", bkpinfo->isodir);
2948 run_program_and_log_output(tmp, 5);
2949 mr_free(tmp);
2950
2951 paranoid_free(mountlist);
2952 paranoid_free(raidlist);
2953 if (am_I_in_disaster_recovery_mode()) {
2954 run_program_and_log_output("mount / -o remount,rw", 2);
2955 } // for b0rken distros
2956 if (strstr(bkpinfo->tmpdir,"mondo.tmp.") != NULL) {
2957 mr_asprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir);
2958 system(tmp);
2959 mr_free(tmp);
2960 }
2961 paranoid_MR_finish(retval); // frees global stuff plus bkpinfo
2962 free_libmondo_global_strings(); // it's fine to have this here :) really :)
2963
2964 unlink("/tmp/filelist.full");
2965
2966 exit(retval);
2967}
2968
2969/**************************************************************************
2970 *END_MAIN *
2971 **************************************************************************/
2972
2973
2974
2975
2976
2977/**************************************************************************
2978 *END_MONDO-RESTORE.C *
2979 **************************************************************************/
Note: See TracBrowser for help on using the repository browser.