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

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

remove g_loglevel and replaced with mr_conf->log_level

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