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

Last change on this file since 1663 was 1663, checked in by Bruno Cornec, 17 years ago
  • Fix bug #197 (based on an initial patch of Scott Cummings)
  • Fix a bug where df was using locale to print messages and wasn't filtered correctly
  • mkdtemp checked in configure
  • reset_bkpinfo called as early as possible by both main program.
  • It creates a tmpdir cleanly with mkdtemp in setup_tmpdir subfunction, which takes in account TMPIR and TMP env var. Remains to see what tmpfs does and tests
  • configure.in should also be filtered.
  • Remove g_bkpinfo_DONTUSETHIS
  • remove bkpinfo also from header files
  • Render bkpinfo global (potential issue on thread, but should not be a problem as that structure is indeed static during archive)
  • Apply patch from Andree Leidenfrost, modified a bit to use bkpinfo->tmpdir instead of /tmp or MINDI_CACHE when appropriate. Fix security issues in mondo. Thanks al ot Andree for catching all those issues.
  • /tmp => /var/log for mondorestore.log in mindi
  • Update linux terminfo to fix a color issue (Andree Leidenfrost)
  • Removes useless log file (Andree Leidenfrost)
  • replace vi with find_my_editor during restore (Andree Leidenfrost)
  • sync in bg in mindi (VMWare issue to look at)
  • mindi/mindi-busybox have a different version than mondo for pb
  • PB-SUF also added to spec file
  • Fix a bug for pb build (omission of PB-SUF declaration)

(merge -r1631:1662 $SVN_M/branches/2.2.5)

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