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

Last change on this file since 1548 was 1548, checked in by Bruno Cornec, 17 years ago
  • Add the possibiilty to edit in interactive mode mtab and device.map for grub
  • Remove blkid cache files after restore to avoid problems in cloning mode
  • Fix what seems to appear a huge number of bugs in hack-fstab (illustration of 1 LOC = 1 bug :-)
  • Especially improve LABEL and UUID support.
  • Should fix #185
  • Exclude_path should be 4*MAX_STR_LEN everywhere. Fixed now.
  • Increasing that value will allow to having larger exclude paths.
  • Should solve bug #137 (and maybe #3 as well)
  • Adds support for fedora 7

(merge -r 1533:1547 $SVN_M/branches/2.2.5)

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