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

Last change on this file since 1202 was 1202, checked in by Bruno Cornec, 17 years ago

Typo again

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