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

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

mr_gettext.h added again + locale.h

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