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

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

More conf file items handled

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