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

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

Fix #114

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