source: MondoRescue/branches/stable/mondo/src/mondorestore/mondorestore.c@ 1326

Last change on this file since 1326 was 1326, checked in by Bruno Cornec, 17 years ago
  • MONDO_LOGFILE is rather a char* exported by each main program (consolidation of those mecanisms in .h files with ps_*)
  • One include has been created for each binary containing only the specific declarations
  • Log files are now consistent: mondoarchive.log for mondoarchive (containing also mindi.log) and mondorestore.log for mondorestore (copied from /tmp (ram) to /var/log (disk) at the end of the restore)
  • Doc updated accordingly
  • LOGFILE in restore process is now passed in the environment and not duplicated a nymore
  • LogIt is not redifined either
  • LOGFILE should be put in environment by mondoarchive for mindi's usage but that's a step left for later.
  • label-partitions-as-necessary should now work correctly for LABEL and UUID (grep -w removed)
  • Remove useless script compare-me

(All coming from 2.2.2) (remains changes in my-stuff.h coming later on)

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