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

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

Fix the latest pb with mr_rs_conf and compilation works

  • Property svn:keywords set to Id
File size: 99.2 KB
RevLine 
[1]1/***************************************************************************
[1080]2* restores mondoarchive data
3* $Id: mondorestore.c 1626 2007-09-08 23:36:41Z 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 1626 2007-09-08 23:36:41Z 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->slice_size = 0;
182 mr_cnf->boot_loader = NULL;
183 mr_cnf->differential = FALSE;
184 mr_cnf->compression_tool = NULL;
185 mr_cnf->ui_mode = NULL;
186 mr_cnf->automatic_restore = FALSE;
187 mr_cnf->images_dir = NULL;
188}
189
[1]190/**************************************************************************
191 * COMPAQ PROLIANT Stuff: needs some special help *
192**************************************************************************/
193
194/**
195 * The message to display if we detect that the user is using a Compaq Proliant.
196 */
[1581]197#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]198
199
200/**
201 * Allow the user to modify the mountlist before we partition & format their drives.
202 * @param bkpinfo The backup information structure. @c disaster_recovery is the only field used.
203 * @param mountlist The mountlist to let the user modify.
204 * @param raidlist The raidlist that goes with @p mountlist.
205 * @return 0 for success, nonzero for failure.
206 * @ingroup restoreGuiGroup
207 */
[128]208int let_user_edit_the_mountlist(struct s_bkpinfo *bkpinfo,
209 struct mountlist_itself *mountlist,
210 struct raidlist_itself *raidlist)
[1]211{
[128]212 int retval = 0, res = 0;
[1]213
[1108]214 mr_msg(2, "let_user_edit_the_mountlist() --- starting");
[1]215
[128]216 assert(bkpinfo != NULL);
217 assert(mountlist != NULL);
218 assert(raidlist != NULL);
219 if (!bkpinfo->disaster_recovery) {
220 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
[1108]221 mr_msg(2, "I guess you're testing edit_mountlist()");
[1]222 }
[128]223 if (!does_file_exist(g_mountlist_fname)) {
224 log_to_screen(g_mountlist_fname);
[1199]225 log_to_screen(_("does not exist"));
[128]226 return (1);
227 }
[1]228
[128]229 retval = load_mountlist(mountlist, g_mountlist_fname);
230 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
231 if (retval) {
232 log_to_screen
[1199]233 (_("Warning - load_raidtab_into_raidlist returned an error"));
[128]234 }
235 res = edit_mountlist(g_mountlist_fname, mountlist, raidlist);
236 if (res) {
237 return (1);
238 }
[1]239
[128]240 save_mountlist_to_disk(mountlist, g_mountlist_fname);
241 save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
[1]242
[1199]243 log_to_screen(_("I have finished editing the mountlist for you."));
[1]244
[128]245 return (retval);
246}
[1]247
248
249/**
250 * Determine whether @p mountlist contains a Compaq diagnostic partition.
251 * @param mountlist The mountlist to examine.
252 * @return TRUE if there's a Compaq diagnostic partition; FALSE if not.
253 * @ingroup restoreUtilityGroup
254 */
[128]255bool
256partition_table_contains_Compaq_diagnostic_partition(struct
257 mountlist_itself *
258 mountlist)
[1]259{
[128]260 int i;
[1]261
[128]262 assert(mountlist != NULL);
[1]263
[128]264 for (i = 0; i < mountlist->entries; i++) {
265 if (strstr(mountlist->el[i].format, "ompaq")) {
[1108]266 mr_msg(2, "mountlist[%d] (%s) is %s (Compaq alert!)",
[128]267 i, mountlist->el[i].device, mountlist->el[i].format);
268
269 return (TRUE);
270 }
[1]271 }
[128]272 return (FALSE);
[1]273}
[128]274
[1]275/**************************************************************************
276 *END_PARTITION_TABLE_CONTAINS_COMPAQ_DIAGNOSTIC_PARTITION *
277 **************************************************************************/
278
279
280/**
281 * Allow the user to abort the backup if we find that there is a Compaq diagnostic partition.
282 * @note This function does not actually check for the presence of a Compaq partition.
283 * @ingroup restoreUtilityGroup
284 */
[128]285void offer_to_abort_because_Compaq_Proliants_suck(void)
[1]286{
[128]287 popup_and_OK(COMPAQ_PROLIANTS_SUCK);
288 if (ask_me_yes_or_no
[1203]289 (_("Would you like to reboot and use your Compaq CD to prep your hard drive?")))
[128]290 {
[1203]291 fatal_error(_("Aborting. Please reboot and prep your hard drive with your Compaq CD."));
[128]292 }
[1]293}
[128]294
[1]295/**************************************************************************
296 *END_OFFER_TO_ABORT_BECAUSE_COMPAQ_PROLIANTS_SUCK *
297 **************************************************************************/
298
299
300/**
301 * Call interactive_mode(), nuke_mode(), or compare_mode() depending on the user's choice.
302 * @param bkpinfo The backup information structure. Most fields are used.
303 * @param mountlist The mountlist containing information about the user's partitions.
304 * @param raidlist The raidlist to go with @p mountlist.
305 * @return The return code from the mode function called.
306 * @ingroup restoreGroup
307 */
[128]308int
309catchall_mode(struct s_bkpinfo *bkpinfo,
310 struct mountlist_itself *mountlist,
311 struct raidlist_itself *raidlist)
[1]312{
[128]313 char c, *tmp;
314 int retval = 0;
[1]315
[128]316 iamhere("inside catchall");
317 assert(bkpinfo != NULL);
318 assert(mountlist != NULL);
319 assert(raidlist != NULL);
320 iamhere("pre wrm");
321 c = which_restore_mode();
322 iamhere("post wrm");
323 if (c == 'I' || c == 'N' || c == 'C') {
324 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
325 } else {
[1203]326 popup_and_OK(_("No restoring or comparing will take place today."));
[128]327 if (is_this_device_mounted("/mnt/cdrom")) {
328 run_program_and_log_output("umount /mnt/cdrom", FALSE);
329 }
330 if (g_ISO_restore_mode) {
[1199]331 mr_asprintf(&tmp, "umount %s", bkpinfo->isodir);
[128]332 run_program_and_log_output(tmp, FALSE);
[1199]333 mr_free(tmp);
[128]334 }
335 paranoid_MR_finish(0);
[1]336 }
337
[128]338 iamhere("post int");
[1]339
[128]340 if (bkpinfo->backup_media_type == iso) {
341 if (iso_fiddly_bits(bkpinfo, (c == 'N') ? TRUE : FALSE)) {
[1108]342 mr_msg(2,
[128]343 "catchall_mode --- iso_fiddly_bits returned w/ error");
344 return (1);
345 } else {
[1108]346 mr_msg(2, "catchall_mode --- iso_fiddly_bits ok");
[128]347 }
348 }
[1]349
[128]350 if (c == 'I') {
[1108]351 mr_msg(2, "IM selected");
[128]352 retval += interactive_mode(bkpinfo, mountlist, raidlist);
353 } else if (c == 'N') {
[1108]354 mr_msg(2, "NM selected");
[128]355 retval += nuke_mode(bkpinfo, mountlist, raidlist);
356 } else if (c == 'C') {
[1108]357 mr_msg(2, "CM selected");
[128]358 retval += compare_mode(bkpinfo, mountlist, raidlist);
359 }
360 return (retval);
[1]361}
[128]362
[1]363/**************************************************************************
364 *END_CATCHALL_MODE *
365 **************************************************************************/
366
367/**************************************************************************
368 *END_ EXTRACT_CONFIG_FILE_FROM_RAMDISK *
369 **************************************************************************/
370
[1548]371static void clean_blkid(struct s_bkpinfo *bkpinfo) {
[1]372
[1548]373 char *tmp1 = NULL;
374
375 /* Clean up blkid cache file if they exist */
376 mr_asprintf(&tmp1,"%s/etc/blkid.tab",bkpinfo->restore_path);
377 (void)unlink(tmp1);
378 mr_free(tmp1);
379 mr_asprintf(&tmp1,"%s/etc/blkid.tab.old",bkpinfo->restore_path);
380 (void)unlink(tmp1);
381 mr_free(tmp1);
382}
383
384
[1]385/**
386 * @addtogroup restoreGroup
387 * @{
388 */
389/**
390 * Restore the user's data, in a disaster recovery situation, prompting the
391 * user about whether or not to do every step.
392 * The user can edit the mountlist, choose files to restore, etc.
393 * @param bkpinfo The backup information structure. Most fields are used.
394 * @param mountlist The mountlist containing information about the user's partitions.
395 * @param raidlist The raidlist to go with @p mountlist.
396 * @return 0 for success, or the number of errors encountered.
397 */
[128]398int
399interactive_mode(struct s_bkpinfo *bkpinfo,
400 struct mountlist_itself *mountlist,
401 struct raidlist_itself *raidlist)
[1]402{
[128]403 int retval = 0;
404 int res;
405 int ptn_errs = 0;
406 int fmt_errs = 0;
[1]407
[128]408 bool done;
409 bool restore_all;
[1]410
[1199]411 char *tmp = NULL;
412 char *tmp1 = NULL;
413 char *fstab_fname = NULL;
414 char *old_restpath = NULL;
[1]415
[1199]416 struct s_node *filelist = NULL;
[1]417
[128]418 /* try to partition and format */
[1]419
[1108]420 mr_msg(2, "interactive_mode --- starting (great, assertions OK)");
[1]421
[128]422 assert(bkpinfo != NULL);
423 assert(mountlist != NULL);
424 assert(raidlist != NULL);
[1]425
[1108]426 mr_msg(2, "interactive_mode --- assertions OK");
[1]427
[128]428 if (g_text_mode) {
429 if (!ask_me_yes_or_no
[1203]430 (_("Interactive Mode + textonly = experimental! Proceed anyway?")))
[128]431 {
432 fatal_error("Wise move.");
433 }
434 }
435
436 iamhere("About to load config file");
437 get_cfg_file_from_archive_or_bust(bkpinfo);
438 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
439 iamhere("Done loading config file; resizing ML");
[1454]440 strcpy(tmp, bkpinfo->prefix);
441 if (popup_and_get_string
442 ("Prefix", "Prefix of your ISO images ?", tmp, MAX_STR_LEN / 4)) {
443 strcpy(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';
[1080]1042 bigblk = mr_malloc(TAPE_BLOCK_SIZE);
[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)) {
1253 siz = fread(bigblk, 1, TAPE_BLOCK_SIZE, fbzip2);
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;
[1]1571
[128]1572 assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
1573
[1108]1574 mr_msg(5, "Entering");
[128]1575 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
[1199]1576 mr_asprintf(&command, "mkdir -p %s/tmp", MNT_RESTORING);
[128]1577 run_program_and_log_output(command, 9);
[1199]1578 mr_free(command);
[1]1579
[1199]1580 mr_asprintf(&filelist_name, MNT_CDROM "/archives/filelist.%ld",
[128]1581 current_tarball_number);
1582 if (length_of_file(filelist_name) <= 2) {
[1108]1583 mr_msg(2, "There are _zero_ files in filelist '%s'",
[128]1584 filelist_name);
[1108]1585 mr_msg(2,
[676]1586 "This is a bit silly (ask dev-team to fix mondo_makefilelist, please)");
[1108]1587 mr_msg(2,
[128]1588 "but it's non-critical. It's cosmetic. Don't worry about it.");
1589 retval = 0;
[1199]1590 mr_msg(5, "Leaving");
1591 mr_free(filelist_name);
1592 return (retval);
[1]1593 }
[128]1594 if (count_lines_in_file(filelist_name) <= 0
1595 || length_of_file(tarball_fname) <= 0) {
[1108]1596 mr_msg(3, "length_of_file(%s) = %llu", tarball_fname,
[128]1597 length_of_file(tarball_fname));
[1199]1598 log_to_screen(_("Unable to restore fileset #%ld (CD I/O error)"),
[128]1599 current_tarball_number);
1600 retval = 1;
[1199]1601 mr_msg(5, "Leaving");
1602 mr_free(filelist_name);
1603 return (retval);
[1]1604 }
1605
[128]1606 if (filelist) {
[1199]1607 mr_asprintf(&filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp",
[128]1608 current_tarball_number);
1609 if ((matches =
1610 save_filelist_entries_in_common(filelist_name, filelist,
1611 filelist_subset_fname,
1612 use_star))
1613 <= 0) {
[1199]1614 mr_msg(1, "Skipping fileset %ld", current_tarball_number);
[128]1615 } else {
[1108]1616 mr_msg(3, "Saved fileset %ld's subset to %s",
[128]1617 current_tarball_number, filelist_subset_fname);
1618 }
[1199]1619 log_to_screen("Tarball #%ld --- %ld matches",
[128]1620 current_tarball_number, matches);
1621 }
[1199]1622 mr_free(filelist_name);
[128]1623
1624 if (filelist == NULL || matches > 0) {
[948]1625 if (g_getfattr) {
[1199]1626 mr_asprintf(&xattr_fname, XATTR_LIST_FNAME_RAW_SZ,
[128]1627 MNT_CDROM "/archives", current_tarball_number);
[948]1628 }
1629 if (g_getfacl) {
[1199]1630 mr_asprintf(&acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives",
[128]1631 current_tarball_number);
[948]1632 }
[128]1633 if (strstr(tarball_fname, ".bz2")) {
[1199]1634 mr_asprintf(&executable, "-P bzip2 -Z");
[998]1635 } else if (strstr(tarball_fname, ".gz")) {
[1199]1636 mr_asprintf(&executable, "-P gzip -Z");
[128]1637 } else if (strstr(tarball_fname, ".lzo")) {
[1199]1638 mr_asprintf(&executable, "-P lzop -Z");
[128]1639 }
[1199]1640
1641 if (executable == NULL) {
1642 mr_asprintf(&tmp, "which %s > /dev/null 2> /dev/null", executable);
[128]1643 if (run_program_and_log_output(tmp, FALSE)) {
1644 log_to_screen
[1203]1645 (_("(compare_a_tarball) Compression program not found - oh no!"));
[1199]1646 mr_free(tmp);
1647 mr_free(executable);
1648 mr_free(acl_fname);
1649 mr_free(xattr_fname);
1650 mr_free(filelist_subset_fname);
[128]1651 paranoid_MR_finish(1);
1652 }
[1199]1653 mr_free(tmp);
[128]1654 }
[1]1655#ifdef __FreeBSD__
1656#define BUFSIZE 512
1657#else
1658#define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE
1659#endif
1660
[128]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",
[128]1672 TAPE_BLOCK_SIZE,
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",
1678 TAPE_BLOCK_SIZE,
1679 BUFSIZE, executable, tarball_fname);
1680 }
1681 }
[1199]1682 mr_free(executable);
1683
[128]1684#undef BUFSIZE
[1199]1685 mr_asprintf(&temp_log, "/tmp/%d.%d", (int) (random() % 32768),
1686 (int) (random() % 32768));
1687
1688 mr_strcat(command, " 2>> %s >> %s", temp_log, temp_log);
[1108]1689 mr_msg(1, "command = '%s'", command);
[128]1690 unlink(temp_log);
1691 res = system(command);
1692 if (res) {
1693 p = strstr(command, "-acl ");
1694 if (p) {
1695 p[0] = p[1] = p[2] = p[3] = ' ';
[1108]1696 mr_msg(1, "new command = '%s'", command);
[128]1697 res = system(command);
1698 }
1699 }
[1199]1700 mr_free(command);
1701
[128]1702 if (res && length_of_file(temp_log) < 5) {
1703 res = 0;
1704 }
1705
[948]1706 if (g_getfattr) {
[1108]1707 mr_msg(1, "Setting fattr list %s", xattr_fname);
[948]1708 if (length_of_file(xattr_fname) > 0) {
1709 res = set_fattr_list(filelist_subset_fname, xattr_fname);
1710 if (res) {
1711 log_to_screen
1712 ("Errors occurred while setting extended attributes");
1713 } else {
[1108]1714 mr_msg(1, "I set xattr OK");
[948]1715 }
1716 retval += res;
[128]1717 }
1718 }
[948]1719 if (g_getfacl) {
[1108]1720 mr_msg(1, "Setting acl list %s", acl_fname);
[948]1721 if (length_of_file(acl_fname) > 0) {
1722 res = set_acl_list(filelist_subset_fname, acl_fname);
1723 if (res) {
1724 log_to_screen
1725 ("Errors occurred while setting access control lists");
1726 } else {
[1108]1727 mr_msg(1, "I set ACL OK");
[948]1728 }
1729 retval += res;
[128]1730 }
1731 }
1732 if (retval) {
[1199]1733 mr_asprintf(&command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
[128]1734 system(command);
[1199]1735 mr_free(command);
[1108]1736 mr_msg(2, "Errors occurred while processing fileset #%d",
[128]1737 current_tarball_number);
1738 } else {
[1108]1739 mr_msg(2, "Fileset #%d processed OK", current_tarball_number);
[128]1740 }
[1199]1741 unlink(xattr_fname);
1742 mr_free(xattr_fname);
1743 unlink(acl_fname);
1744 mr_free(acl_fname);
1745 unlink(temp_log);
1746 mr_free(temp_log);
[1]1747 }
[128]1748 if (does_file_exist("/PAUSE")) {
1749 popup_and_OK
[1203]1750 (_("Press ENTER to go on. Delete /PAUSE to stop these pauses."));
[1]1751 }
[128]1752 unlink(filelist_subset_fname);
[1080]1753 mr_free(filelist_subset_fname);
[1108]1754 mr_msg(5, "Leaving");
[128]1755 return (retval);
[1]1756}
1757
1758/**************************************************************************
1759 *END_RESTORE_A_TARBALL_FROM_CD *
1760 **************************************************************************/
1761
1762
1763/**
1764 * Restore a tarball from the currently opened stream.
1765 * @param bkpinfo The backup information structure. Fields used:
1766 * - @c bkpinfo->backup_media_type
1767 * - @c bkpinfo->media_device
1768 * - @c bkpinfo->zip_exe
1769 * @param tarball_fname The filename of the afioball to restore.
1770 * @param current_tarball_number The number (starting from 0) of the fileset
1771 * we're restoring now.
1772 * @param filelist The node structure containing the list of files to be
1773 * restored. If no file in the afioball is in this list, afio will still be
1774 * called, but nothing will be written.
1775 * @param size The size (in @b bytes) of the afioball.
1776 * @return 0 for success, nonzero for failure.
1777 */
1778int
1779restore_a_tarball_from_stream(struct s_bkpinfo *bkpinfo,
[128]1780 char *tarball_fname,
1781 long current_tarball_number,
1782 struct s_node *filelist,
1783 long long size, char *xattr_fname,
1784 char *acl_fname)
[1]1785{
[128]1786 int retval = 0;
1787 int res = 0;
[1]1788
1789 /** malloc add ***/
[1199]1790 char *command = NULL;
1791 char *afio_fname = NULL;
1792 char *filelist_fname = NULL;
1793 char *filelist_subset_fname = NULL;
1794 char *executable = NULL;
[128]1795 long matches = 0;
1796 bool restore_this_fileset = FALSE;
[1199]1797 bool use_star = FALSE;
[1]1798
[128]1799 assert(bkpinfo != NULL);
1800 assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
1801 /* to do it with a file... */
1802 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
[1199]1803 mr_msg(2, "Restoring from fileset #%ld (%ld KB) on %s #%d",
[128]1804 current_tarball_number, (long) size >> 10,
[1199]1805 bkpinfo->backup_media_string,
[128]1806 g_current_media_number);
1807 run_program_and_log_output("mkdir -p " MNT_RESTORING "/tmp", FALSE);
1808
[1]1809 /****************************************************************************
1810 * Use RAMDISK's /tmp; saves time; oh wait, it's too small *
1811 * Well, pipe from tape to afio, then; oh wait, can't do that either: bug *
1812 * in afio or someting; oh darn.. OK, use tmpfs :-) *
1813 ****************************************************************************/
[1199]1814 mr_asprintf(&afio_fname, "/tmp/tmpfs/archive.tmp.%ld",
[128]1815 current_tarball_number);
[1199]1816 mr_asprintf(&filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir,
[128]1817 current_tarball_number);
[1199]1818 mr_asprintf(&filelist_subset_fname, "%s/filelist-subset-%ld.tmp",
[128]1819 bkpinfo->tmpdir, current_tarball_number);
1820 res = read_file_from_stream_to_file(bkpinfo, afio_fname, size);
1821 if (strstr(tarball_fname, ".star")) {
1822 bkpinfo->use_star = TRUE;
[1]1823 }
[128]1824 if (res) {
[1108]1825 mr_msg(1, "Warning - error reading afioball from tape");
[1]1826 }
[1199]1827 if (bkpinfo->compression_level != 0) {
[128]1828 if (bkpinfo->use_star) {
[1199]1829 mr_asprintf(&executable, " -bz");
[128]1830 } else {
[1199]1831 mr_asprintf(&executable, "-P %s -Z", bkpinfo->zip_exe);
[128]1832 }
[1]1833 }
1834
[128]1835 if (!filelist) // if unconditional restore then restore entire fileset
1836 {
1837 restore_this_fileset = TRUE;
1838 } else // If restoring selectively then get TOC from tarball
1839 {
1840 if (strstr(tarball_fname, ".star.")) {
1841 use_star = TRUE;
[1199]1842 mr_asprintf(&command, "star -t file=%s %s", afio_fname, executable);
[128]1843 } else {
1844 use_star = FALSE;
[1199]1845 mr_asprintf(&command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE,
[128]1846 executable, afio_fname);
1847 }
[1199]1848 mr_strcat(command, " > %s 2>> %s", filelist_fname, MONDO_LOGFILE);
[1108]1849 mr_msg(1, "command = %s", command);
[128]1850 if (system(command)) {
[1108]1851 mr_msg(4, "Warning - error occurred while retrieving TOC");
[128]1852 }
[1199]1853 mr_free(command);
1854
[128]1855 if ((matches =
1856 save_filelist_entries_in_common(filelist_fname, filelist,
1857 filelist_subset_fname,
1858 use_star))
1859 <= 0 || length_of_file(filelist_subset_fname) < 2) {
1860 if (length_of_file(filelist_subset_fname) < 2) {
[1108]1861 mr_msg(1, "No matches found in fileset %ld",
[128]1862 current_tarball_number);
1863 }
[1199]1864 mr_msg(2, "Skipping fileset %ld", current_tarball_number);
[128]1865 restore_this_fileset = FALSE;
1866 } else {
[1108]1867 mr_msg(5, "%ld matches. Saved fileset %ld's subset to %s",
[128]1868 matches, current_tarball_number,
1869 filelist_subset_fname);
1870 restore_this_fileset = TRUE;
1871 }
1872 }
[1199]1873 unlink(filelist_fname);
1874 mr_free(filelist_fname);
[128]1875
[1]1876// Concoct the call to star/afio to restore files
[1199]1877 if (strstr(tarball_fname, ".star.")) {
1878 // star
[128]1879 if (filelist) {
[1199]1880 mr_asprintf(&command, "star -x file=%s %s list=%s 2>> %s", afio_fname, executable, filelist_subset_fname, MONDO_LOGFILE);
1881 } else {
1882 mr_asprintf(&command, "star -x file=%s %s 2>> %s", afio_fname, executable, MONDO_LOGFILE);
[128]1883 }
[1199]1884 } else {
1885 // afio
[128]1886 if (filelist) {
[1199]1887 mr_asprintf(&command, "afio -i -M 8m -b %ld %s -w %s %s 2>> %s", TAPE_BLOCK_SIZE, executable, filelist_subset_fname, afio_fname, MONDO_LOGFILE);
1888 } else {
1889 mr_asprintf(&command, "afio -i -M 8m -b %ld %s %s 2>> %s", TAPE_BLOCK_SIZE, executable, afio_fname, MONDO_LOGFILE);
[128]1890 }
1891 }
[1199]1892 mr_free(executable);
[1]1893
[1199]1894 // Call if IF there are files to restore (selectively/unconditionally)
[128]1895 if (restore_this_fileset) {
[1108]1896 mr_msg(1, "Calling command='%s'", command);
[128]1897 paranoid_system(command);
[1]1898
[948]1899 if (g_getfattr) {
1900 iamhere("Restoring xattr stuff");
1901 res = set_fattr_list(filelist_subset_fname, xattr_fname);
1902 if (res) {
[1108]1903 mr_msg(1, "Errors occurred while setting xattr");
[948]1904 } else {
[1108]1905 mr_msg(1, "I set xattr OK");
[948]1906 }
1907 retval += res;
[128]1908 }
[1]1909
[948]1910 if (g_getfacl) {
1911 iamhere("Restoring acl stuff");
1912 res = set_acl_list(filelist_subset_fname, acl_fname);
1913 if (res) {
[1108]1914 mr_msg(1, "Errors occurred while setting ACL");
[948]1915 } else {
[1108]1916 mr_msg(1, "I set ACL OK");
[948]1917 }
1918 retval += res;
[128]1919 }
1920
1921 } else {
[1108]1922 mr_msg(1, "NOT CALLING '%s'", command);
[128]1923 }
[1199]1924 mr_free(command);
[128]1925
1926 if (does_file_exist("/PAUSE") && current_tarball_number >= 50) {
[1199]1927 log_to_screen(_("Paused after set %ld"), current_tarball_number);
1928 popup_and_OK(_("Pausing. Press ENTER to continue."));
[128]1929 }
1930
1931 unlink(filelist_subset_fname);
1932 unlink(afio_fname);
1933
[1080]1934 mr_free(filelist_subset_fname);
1935 mr_free(afio_fname);
[128]1936 return (retval);
[1]1937}
[128]1938
[1]1939/**************************************************************************
1940 *END_RESTORE_A_TARBALL_FROM_STREAM *
1941 **************************************************************************/
1942
1943
1944/**
1945 * Restore all biggiefiles from all media in this CD backup.
1946 * The CD with the last afioball should be currently mounted.
1947 * @param bkpinfo The backup information structure. @c backup_media_type is the
1948 * only field used in this function.
1949 * @param filelist The node structure containing the list of files to be
1950 * restored. If a prospective biggiefile is not in this list, it will be ignored.
1951 * @return 0 for success, nonzero for failure.
1952 */
1953int
[128]1954restore_all_biggiefiles_from_CD(struct s_bkpinfo *bkpinfo,
1955 struct s_node *filelist)
[1]1956{
[128]1957 int retval = 0;
[1199]1958 int res = 0;
1959 long noof_biggiefiles = 0L, bigfileno = 0L, total_slices = 0L;
1960 char *tmp = NULL;
1961 char *tmp1 = NULL;
1962 bool just_changed_cds = FALSE, finished = FALSE;
1963 char *xattr_fname = NULL;
1964 char *acl_fname = NULL;
1965 char *biggies_whose_EXATs_we_should_set = NULL; // EXtended ATtributes
1966 char *pathname_of_last_biggie_restored = NULL;
[128]1967 FILE *fbw = NULL;
[1]1968
[1199]1969 malloc_string(tmp1);
[128]1970 malloc_string(pathname_of_last_biggie_restored);
1971 assert(bkpinfo != NULL);
1972
[1199]1973 mr_asprintf(&biggies_whose_EXATs_we_should_set,
[128]1974 "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
1975 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
[1108]1976 mr_msg(1, "Warning - cannot openout %s",
[128]1977 biggies_whose_EXATs_we_should_set);
[1]1978 }
1979
[1199]1980 read_cfg_var(g_mondo_cfg_file, "total-slices", tmp1);
1981 total_slices = atol(tmp1);
1982 mr_free(tmp1);
1983
1984 mr_asprintf(&tmp, _("Reassembling large files "));
[128]1985 mvaddstr_and_log_it(g_currentY, 0, tmp);
[1199]1986 mr_free(tmp);
1987
[128]1988 if (length_of_file(BIGGIELIST) < 6) {
[1108]1989 mr_msg(1, "OK, no biggielist; not restoring biggiefiles");
[128]1990 return (0);
[1]1991 }
[128]1992 noof_biggiefiles = count_lines_in_file(BIGGIELIST);
1993 if (noof_biggiefiles <= 0) {
[1108]1994 mr_msg(2,
[128]1995 "OK, no biggiefiles in biggielist; not restoring biggiefiles");
1996 return (0);
1997 }
[1199]1998 mr_msg(2, "OK, there are %ld biggiefiles in the archives", noof_biggiefiles);
[1]1999
[1199]2000 open_progress_form(_("Reassembling large files"),
2001 _("I am now reassembling all the large files."),
2002 _("Please wait. This may take some time."),
[128]2003 "", total_slices);
2004 for (bigfileno = 0, finished = FALSE; !finished;) {
[1108]2005 mr_msg(2, "Thinking about restoring bigfile %ld", bigfileno + 1);
[128]2006 if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) {
[1108]2007 mr_msg(3,
[128]2008 "...but its first slice isn't on this CD. Perhaps this was a selective restore?");
[1108]2009 mr_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d",
[128]2010 bigfileno + 1,
[1199]2011 bkpinfo->backup_media_string,
[128]2012 g_current_media_number);
[1108]2013 mr_msg(3, "Slicename would have been %s",
[128]2014 slice_fname(bigfileno + 1, 0, ARCHIVES_PATH, ""));
2015 // I'm not positive 'just_changed_cds' is even necessary...
2016 if (just_changed_cds) {
2017 just_changed_cds = FALSE;
[1108]2018 mr_msg(3,
[128]2019 "I'll continue to scan this CD for bigfiles to be restored.");
2020 } else if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) {
2021 insist_on_this_cd_number(bkpinfo,
2022 ++g_current_media_number);
[1199]2023 log_to_screen(_("Restoring from %s #%d"),
2024 bkpinfo->backup_media_string,
[128]2025 g_current_media_number);
2026 just_changed_cds = TRUE;
2027 } else {
[1108]2028 mr_msg(2, "There was no bigfile #%ld. That's OK.",
[128]2029 bigfileno + 1);
[1108]2030 mr_msg(2, "I'm going to stop restoring bigfiles now.");
[128]2031 finished = TRUE;
2032 }
2033 } else {
2034 just_changed_cds = FALSE;
[1199]2035 mr_asprintf(&tmp, _("Restoring big file %ld"), bigfileno + 1);
[128]2036 update_progress_form(tmp);
[1199]2037 mr_free(tmp);
2038
[128]2039 res =
2040 restore_a_biggiefile_from_CD(bkpinfo, bigfileno, filelist,
2041 pathname_of_last_biggie_restored);
2042 iamhere(pathname_of_last_biggie_restored);
2043 if (fbw && pathname_of_last_biggie_restored[0]) {
2044 fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
2045 }
2046 retval += res;
2047 bigfileno++;
2048 }
[1]2049 }
[128]2050
2051 if (fbw) {
2052 fclose(fbw);
[948]2053 if (g_getfattr) {
[1199]2054 mr_asprintf(&xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
[948]2055 if (length_of_file(xattr_fname) > 0) {
2056 set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
2057 }
[128]2058 }
[948]2059 if (g_getfacl) {
[1199]2060 mr_asprintf(&acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
[948]2061 if (length_of_file(acl_fname) > 0) {
2062 set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
2063 }
[128]2064 }
[1199]2065 mr_free(acl_fname);
2066 mr_free(xattr_fname);
[1]2067 }
[1199]2068 mr_free(biggies_whose_EXATs_we_should_set);
2069
[128]2070 if (does_file_exist("/PAUSE")) {
2071 popup_and_OK
[1203]2072 (_("Press ENTER to go on. Delete /PAUSE to stop these pauses."));
[128]2073 }
2074 close_progress_form();
2075 if (retval) {
[1199]2076 mvaddstr_and_log_it(g_currentY++, 74, _("Errors."));
[128]2077 } else {
[1199]2078 mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
[128]2079 }
[1080]2080 mr_free(pathname_of_last_biggie_restored);
[128]2081 return (retval);
[1]2082}
[128]2083
[1]2084/**************************************************************************
2085 *END_RESTORE_ALL_BIGGIFILES_FROM_CD *
2086 **************************************************************************/
2087
2088
2089/**
2090 * Restore all afioballs from all CDs in the backup.
2091 * The first CD should be inserted (if not, it will be asked for).
2092 * @param bkpinfo The backup information structure. @c backup_media_type is the
2093 * only field used in @e this function.
2094 * @param filelist The node structure containing the list of files to be
2095 * restored. If no file in some particular afioball is in this list, afio will
2096 * still be called for that fileset, but nothing will be written.
2097 * @return 0 for success, or the number of filesets that failed.
2098 */
2099int
[128]2100restore_all_tarballs_from_CD(struct s_bkpinfo *bkpinfo,
2101 struct s_node *filelist)
[1]2102{
[128]2103 int retval = 0;
[1199]2104 int res = 0;
2105 int attempts = 0;
[128]2106 long current_tarball_number = 0;
[1199]2107 long max_val = 0L;
[1]2108 /**malloc ***/
[1199]2109 char *tmp = NULL;
2110 char *tmp1 = NULL;
2111 char *tarball_fname = NULL;
2112 char *progress_str = NULL;
2113 char *comment = NULL;
[1]2114
[1199]2115 malloc_string(tmp1);
[128]2116 malloc_string(tarball_fname);
2117 malloc_string(progress_str);
2118 malloc_string(comment);
[1]2119
[128]2120 assert(bkpinfo != NULL);
2121
[1199]2122 mvaddstr_and_log_it(g_currentY, 0, _("Restoring from archives"));
[1108]2123 mr_msg(2,
[128]2124 "Insisting on 1st CD, so that I can have a look at LAST-FILELIST-NUMBER");
2125 if (g_current_media_number != 1) {
[1108]2126 mr_msg(3, "OK, that's jacked up.");
[128]2127 g_current_media_number = 1;
[1]2128 }
[128]2129 insist_on_this_cd_number(bkpinfo, g_current_media_number);
[1199]2130 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp1);
2131 max_val = atol(tmp1) + 1;
2132 mr_free(tmp1);
2133
2134 mr_asprintf(&progress_str, _("Restoring from %s #%d"),
2135 bkpinfo->backup_media_string,
[128]2136 g_current_media_number);
2137 log_to_screen(progress_str);
[1199]2138 open_progress_form(_("Restoring from archives"),
2139 _("Restoring data from the archives."),
2140 _("Please wait. This may take some time."),
[128]2141 progress_str, max_val);
2142 for (;;) {
2143 insist_on_this_cd_number(bkpinfo, g_current_media_number);
2144 update_progress_form(progress_str);
[1199]2145 mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2",
[128]2146 current_tarball_number);
[1077]2147 if (!does_file_exist(tarball_fname)) {
[1199]2148 mr_free(tarball_fname);
[1374]2149 mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.afio.gz",
2150 current_tarball_number);
[1077]2151 }
[128]2152 if (!does_file_exist(tarball_fname)) {
[1199]2153 mr_free(tarball_fname);
[1374]2154 mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo",
2155 current_tarball_number);
[128]2156 }
2157 if (!does_file_exist(tarball_fname)) {
[1199]2158 mr_free(tarball_fname);
2159 mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.afio.",
[128]2160 current_tarball_number);
2161 }
2162 if (!does_file_exist(tarball_fname)) {
[1199]2163 mr_free(tarball_fname);
2164 mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.star.bz2",
[128]2165 current_tarball_number);
2166 }
2167 if (!does_file_exist(tarball_fname)) {
[1199]2168 mr_free(tarball_fname);
2169 mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.star.",
[128]2170 current_tarball_number);
2171 }
2172 if (!does_file_exist(tarball_fname)) {
[1199]2173 mr_free(tarball_fname);
[128]2174 if (current_tarball_number == 0) {
2175 log_to_screen
[1203]2176 (_("No tarballs. Strange. Maybe you only backed up freakin' big files?"));
[1199]2177 mr_free(progress_str);
[128]2178 return (0);
2179 }
2180 if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")
2181 || system("find " MNT_CDROM
2182 "/archives/slice* > /dev/null 2> /dev/null") ==
2183 0) {
[1199]2184 mr_free(tarball_fname);
2185 mr_free(progress_str);
[128]2186 break;
2187 }
2188 g_current_media_number++;
[1199]2189 mr_free(progress_str);
2190
2191 mr_asprintf(&progress_str, _("Restoring from %s #%d"),
2192 bkpinfo->backup_media_string,
[128]2193 g_current_media_number);
2194 log_to_screen(progress_str);
2195 } else {
[1199]2196 mr_free(progress_str);
2197 mr_asprintf(&progress_str,
2198 _("Restoring from fileset #%ld on %s #%d"),
[128]2199 current_tarball_number,
[1199]2200 bkpinfo->backup_media_string,
[128]2201 g_current_media_number);
2202 for (res = 999, attempts = 0; attempts < 3 && res != 0;
2203 attempts++) {
2204 res =
2205 restore_a_tarball_from_CD(tarball_fname,
2206 current_tarball_number,
[1166]2207 filelist, bkpinfo);
[128]2208 }
[1199]2209 mr_asprintf(&tmp, _("%s #%d, fileset #%ld - restore "),
[128]2210 media_descriptor_string(bkpinfo->backup_media_type),
2211 g_current_media_number, current_tarball_number);
2212 if (res) {
[1199]2213 mr_strcat(tmp, _("reported errors"));
[128]2214 } else {
[1199]2215 mr_strcat(tmp, _("succeeded"));
[128]2216 }
2217 if (attempts > 1) {
[1199]2218 mr_strcat(tmp, _(" (%d attempts) - review logs"), attempts);
[128]2219 }
2220 if (attempts > 1) {
[1199]2221 log_to_screen(tmp);
[128]2222 }
[1199]2223 mr_free(tmp);
[128]2224
2225 retval += res;
2226 current_tarball_number++;
2227 g_current_progress++;
2228 }
[1199]2229 mr_free(tarball_fname);
[1]2230 }
[1199]2231 mr_free(progress_str);
[128]2232 close_progress_form();
[1199]2233
[128]2234 if (retval) {
[1199]2235 mvaddstr_and_log_it(g_currentY++, 74, _("Errors."));
[128]2236 } else {
[1199]2237 mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
[1]2238 }
[128]2239 return (retval);
[1]2240}
2241
2242/**************************************************************************
2243 *END_RESTORE_ALL_TARBALLS_FROM_CD *
2244 **************************************************************************/
2245
2246
2247/**
2248 * Restore all biggiefiles from the currently opened stream.
2249 * @param bkpinfo The backup information structure. Passed to other functions.
2250 * @param filelist The node structure containing the list of files to be
2251 * restored. If a prospective biggiefile is not in the list, it will be ignored.
2252 * @return 0 for success, or the number of biggiefiles that failed.
2253 */
2254int
[128]2255restore_all_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo,
2256 struct s_node *filelist)
[1]2257{
[1199]2258 long noof_biggiefiles = 0L;
2259 long current_bigfile_number = 0L;
2260 long total_slices = 0L;
[1]2261
[128]2262 int retval = 0;
2263 int res = 0;
[1199]2264 int ctrl_chr = 0;
[1]2265
2266 /** malloc add ****/
[1199]2267 char *tmp = NULL;
2268 char *biggie_fname = NULL;
2269 char *biggie_cksum = NULL;
2270 char *xattr_fname = NULL;
2271 char *acl_fname = NULL;
2272 char *pathname_of_last_biggie_restored = NULL;
2273 char *biggies_whose_EXATs_we_should_set = NULL; // EXtended ATtributes
2274 long long biggie_size = (long long)0;
2275 FILE *fbw;
[1]2276
[1199]2277 assert(bkpinfo != NULL);
2278
[128]2279 malloc_string(tmp);
2280 malloc_string(biggie_fname);
2281 malloc_string(biggie_cksum);
2282 malloc_string(pathname_of_last_biggie_restored);
2283 read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
[1199]2284 total_slices = atol(tmp);
2285 mr_free(tmp);
[1]2286
[1199]2287 mr_asprintf(&tmp, "Reassembling large files ");
[948]2288 if (g_getfattr) {
[1199]2289 mr_asprintf(&xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
[948]2290 }
2291 if (g_getfacl) {
[1199]2292 mr_asprintf(&acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
[948]2293 }
[128]2294 mvaddstr_and_log_it(g_currentY, 0, tmp);
[1199]2295 mr_free(tmp);
2296
2297 mr_asprintf(&biggies_whose_EXATs_we_should_set,
[128]2298 "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
2299 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
[1108]2300 mr_msg(1, "Warning - cannot openout %s",
[128]2301 biggies_whose_EXATs_we_should_set);
2302 }
[1199]2303 // get xattr and acl files if they're there
[128]2304 res =
2305 read_header_block_from_stream(&biggie_size, biggie_fname,
2306 &ctrl_chr);
2307 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
2308 res =
2309 read_EXAT_files_from_tape(bkpinfo, &biggie_size, biggie_fname,
2310 &ctrl_chr, xattr_fname, acl_fname);
2311 }
[1]2312
[128]2313 noof_biggiefiles = atol(biggie_fname);
[1199]2314 mr_msg(2, "OK, there are %ld biggiefiles in the archives",
[128]2315 noof_biggiefiles);
[1199]2316 open_progress_form(_("Reassembling large files"),
2317 _("I am now reassembling all the large files."),
2318 _("Please wait. This may take some time."),
[128]2319 "", total_slices);
[1]2320
[128]2321 for (res =
2322 read_header_block_from_stream(&biggie_size, biggie_fname,
2323 &ctrl_chr);
2324 ctrl_chr != BLK_STOP_BIGGIEFILES;
2325 res =
2326 read_header_block_from_stream(&biggie_size, biggie_fname,
2327 &ctrl_chr)) {
2328 if (ctrl_chr != BLK_START_A_NORMBIGGIE
2329 && ctrl_chr != BLK_START_A_PIHBIGGIE) {
2330 wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr);
2331 }
[1199]2332 /* BERLIOS: useless
[128]2333 p = strrchr(biggie_fname, '/');
2334 if (!p) {
2335 p = biggie_fname;
2336 } else {
2337 p++;
2338 }
[1199]2339 */
2340 mr_asprintf(&tmp, _("Restoring big file %ld (%lld K)"),
[128]2341 current_bigfile_number + 1, biggie_size / 1024);
2342 update_progress_form(tmp);
[1199]2343 mr_free(tmp);
2344
[128]2345 res = restore_a_biggiefile_from_stream(bkpinfo, biggie_fname,
2346 current_bigfile_number,
2347 biggie_cksum,
2348 biggie_size,
2349 filelist, ctrl_chr,
2350 pathname_of_last_biggie_restored);
[1108]2351 mr_msg(1, "I believe I have restored %s",
[128]2352 pathname_of_last_biggie_restored);
2353 if (fbw && pathname_of_last_biggie_restored[0]) {
2354 fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
2355 }
[1199]2356 mr_free(pathname_of_last_biggie_restored);
2357
[128]2358 retval += res;
2359 current_bigfile_number++;
2360
[1]2361 }
[128]2362 if (current_bigfile_number != noof_biggiefiles
2363 && noof_biggiefiles != 0) {
[1199]2364 mr_msg(1, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n",
[128]2365 current_bigfile_number, noof_biggiefiles);
2366 } else {
[1199]2367 mr_msg(1, "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.",
[128]2368 noof_biggiefiles, current_bigfile_number);
[1]2369 }
2370
[128]2371 if (fbw) {
2372 fclose(fbw);
2373 if (length_of_file(biggies_whose_EXATs_we_should_set) > 2) {
2374 iamhere("Setting biggie-EXATs");
[948]2375 if (g_getfattr) {
2376 if (length_of_file(xattr_fname) > 0) {
[1108]2377 mr_msg(1, "set_fattr_List(%s,%s)",
[128]2378 biggies_whose_EXATs_we_should_set, xattr_fname);
[948]2379 set_fattr_list(biggies_whose_EXATs_we_should_set,
[128]2380 xattr_fname);
[948]2381 }
[128]2382 }
[948]2383 if (g_getfacl) {
2384 if (length_of_file(acl_fname) > 0) {
[1108]2385 mr_msg(1, "set_acl_list(%s,%s)",
[948]2386 biggies_whose_EXATs_we_should_set, acl_fname);
2387 set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
2388 }
2389 }
[128]2390 } else {
2391 iamhere
2392 ("No biggiefiles selected. So, no biggie-EXATs to set.");
2393 }
[1]2394 }
[1199]2395 mr_free(xattr_fname);
2396 mr_free(acl_fname);
2397 mr_free(biggies_whose_EXATs_we_should_set);
2398
[128]2399 if (does_file_exist("/PAUSE")) {
2400 popup_and_OK
[1203]2401 (_("Press ENTER to go on. Delete /PAUSE to stop these pauses."));
[1]2402 }
2403
[128]2404 close_progress_form();
2405 if (retval) {
[1199]2406 mvaddstr_and_log_it(g_currentY++, 74, _("Errors."));
[128]2407 } else {
[1199]2408 mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
[128]2409 }
[1080]2410 mr_free(biggie_fname);
2411 mr_free(biggie_cksum);
[128]2412 return (retval);
[1]2413}
[128]2414
[1]2415/**************************************************************************
2416 *END_RESTORE_ALL_BIGGIEFILES_FROM_STREAM *
2417 **************************************************************************/
2418
2419
2420/**
2421 * Restore all afioballs from the currently opened tape stream.
2422 * @param bkpinfo The backup information structure. Fields used:
2423 * - @c bkpinfo->backup_media_type
2424 * - @c bkpinfo->restore_path
2425 * @param filelist The node structure containing the list of files to be
2426 * restored. If no file in an afioball is in this list, afio will still be
2427 * called for that fileset, but nothing will be written.
2428 * @return 0 for success, or the number of filesets that failed.
2429 */
2430int
[128]2431restore_all_tarballs_from_stream(struct s_bkpinfo *bkpinfo,
2432 struct s_node *filelist)
[1]2433{
[128]2434 int retval = 0;
[1199]2435 int res = 0;
[128]2436 long current_afioball_number = 0;
[1199]2437 int ctrl_chr = 0;
2438 long max_val = 0L /*, total_noof_files */ ;
[1]2439
2440 /** malloc **/
[1199]2441 char *tmp = NULL;
2442 char *progress_str = NULL;
2443 char *tmp_fname = NULL;
2444 char *xattr_fname = NULL;
2445 char *acl_fname = NULL;
[1]2446
[1199]2447 long long tmp_size = 0L;
[1]2448
[1199]2449 malloc_string(tmp_fname);
[128]2450 malloc_string(tmp);
2451 assert(bkpinfo != NULL);
[1199]2452 mvaddstr_and_log_it(g_currentY, 0, _("Restoring from archives"));
[128]2453 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
2454 max_val = atol(tmp) + 1;
[1199]2455 mr_free(tmp);
[1]2456
[128]2457 chdir(bkpinfo->restore_path); /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */
[1]2458
[128]2459 run_program_and_log_output("pwd", 5);
[1]2460
[1199]2461 mr_asprintf(&progress_str, _("Restoring from media #%d"),
[128]2462 g_current_media_number);
2463 log_to_screen(progress_str);
[1199]2464 open_progress_form(_("Restoring from archives"),
2465 _("Restoring data from the archives."),
2466 _("Please wait. This may take some time."),
[128]2467 progress_str, max_val);
[1]2468
[1108]2469 mr_msg(3, "hey");
[1]2470
[128]2471 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2472 if (res) {
[1108]2473 mr_msg(2, "Warning - error reading afioball from tape");
[1]2474 }
[128]2475 retval += res;
2476 if (ctrl_chr != BLK_START_AFIOBALLS) {
2477 wrong_marker(BLK_START_AFIOBALLS, ctrl_chr);
[1]2478 }
[1108]2479 mr_msg(2, "ho");
[128]2480 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2481 while (ctrl_chr != BLK_STOP_AFIOBALLS) {
2482 update_progress_form(progress_str);
[948]2483 if (g_getfattr) {
[1199]2484 mr_asprintf(&xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir,
[128]2485 current_afioball_number);
[948]2486 unlink(xattr_fname);
2487 }
2488 if (g_getfacl) {
[1199]2489 mr_asprintf(&acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir,
[128]2490 current_afioball_number);
[948]2491 unlink(acl_fname);
2492 }
[128]2493 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
2494 iamhere("Reading EXAT files from tape");
2495 res =
2496 read_EXAT_files_from_tape(bkpinfo, &tmp_size, tmp_fname,
2497 &ctrl_chr, xattr_fname,
2498 acl_fname);
2499 }
2500 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
2501 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
2502 }
[1199]2503 /* BERLIOS: useless ?
2504 mr_asprintf(&tmp,
2505 _("Restoring from fileset #%ld (name=%s, size=%ld K)"),
[128]2506 current_afioball_number, tmp_fname, (long) tmp_size >> 10);
[1199]2507 */
[128]2508 res =
2509 restore_a_tarball_from_stream(bkpinfo, tmp_fname,
2510 current_afioball_number,
2511 filelist, tmp_size, xattr_fname,
2512 acl_fname);
2513 retval += res;
2514 if (res) {
[1199]2515 log_to_screen("Fileset %ld - errors occurred",
[128]2516 current_afioball_number);
2517 }
2518 res =
2519 read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2520 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
2521 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
2522 }
[1]2523
[128]2524 current_afioball_number++;
2525 g_current_progress++;
[1199]2526
2527 mr_free(progress_str);
2528 mr_asprintf(&progress_str, _("Restoring from fileset #%ld on %s #%d"),
[128]2529 current_afioball_number,
[1199]2530 bkpinfo->backup_media_string,
[128]2531 g_current_media_number);
2532 res =
2533 read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
[948]2534 if (g_getfattr) {
2535 unlink(xattr_fname);
2536 }
2537 if (g_getfacl) {
2538 unlink(acl_fname);
2539 }
[1199]2540 mr_free(xattr_fname);
2541 mr_free(acl_fname);
[128]2542 } // next
[1199]2543 mr_free(progress_str);
2544 mr_free(tmp_fname);
2545
[1108]2546 mr_msg(1, "All done with afioballs");
[128]2547 close_progress_form();
2548 if (retval) {
[1199]2549 mvaddstr_and_log_it(g_currentY++, 74, _("Errors."));
[128]2550 } else {
[1199]2551 mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
[128]2552 }
2553 return (retval);
[1]2554}
[128]2555
[1]2556/**************************************************************************
2557 *END_ RESTORE_ALL_TARBALLS_FROM_STREAM *
2558 **************************************************************************/
2559
2560/* @} - end of LLrestoreGroup */
2561
2562
2563/**
2564 * Restore all files in @p filelist.
2565 * @param bkpinfo The backup information structure. Most fields are used.
2566 * @param filelist The node structure containing the list of files to be
2567 * restored.
2568 * @return 0 for success, or the number of afioballs and biggiefiles that failed.
2569 * @ingroup restoreGroup
2570 */
[128]2571int restore_everything(struct s_bkpinfo *bkpinfo, struct s_node *filelist)
[1]2572{
[128]2573 int resA;
2574 int resB;
[1]2575
2576 /** mallco ***/
[1199]2577 char *cwd = NULL;
2578 char *newpath = NULL;
2579 char *tmp = NULL;
[128]2580 assert(bkpinfo != NULL);
[1]2581
[128]2582 malloc_string(cwd);
2583 malloc_string(newpath);
[1108]2584 mr_msg(2, "restore_everything() --- starting");
[128]2585 g_current_media_number = 1;
[1199]2586 /* BERLIOS: should test return value, or better change the function */
[128]2587 getcwd(cwd, MAX_STR_LEN - 1);
[1199]2588 mr_asprintf(&tmp, "mkdir -p %s", bkpinfo->restore_path);
[128]2589 run_program_and_log_output(tmp, FALSE);
[1199]2590 mr_free(tmp);
2591
[1108]2592 mr_msg(1, "Changing dir to %s", bkpinfo->restore_path);
[128]2593 chdir(bkpinfo->restore_path);
[1199]2594 /* BERLIOS: should test return value, or better change the function */
[128]2595 getcwd(newpath, MAX_STR_LEN - 1);
[1108]2596 mr_msg(1, "path is now %s", newpath);
2597 mr_msg(1, "restoring everything");
[128]2598 if (!find_home_of_exe("petris") && !g_text_mode) {
2599 newtDrawRootText(0, g_noof_rows - 2,
[1203]2600 _("Press ALT-<left cursor> twice to play Petris :-) "));
[128]2601 newtRefresh();
[1]2602 }
[1199]2603 mvaddstr_and_log_it(g_currentY, 0, _("Preparing to read your archives"));
[128]2604 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2605 mount_cdrom(bkpinfo);
2606 mvaddstr_and_log_it(g_currentY++, 0,
[1203]2607 _("Restoring OS and data from streaming media"));
[128]2608 if (bkpinfo->backup_media_type == cdstream) {
2609 openin_cdstream(bkpinfo);
2610 } else {
2611 assert_string_is_neither_NULL_nor_zerolength(bkpinfo->
2612 media_device);
2613 openin_tape(bkpinfo);
2614 }
2615 resA = restore_all_tarballs_from_stream(bkpinfo, filelist);
2616 resB = restore_all_biggiefiles_from_stream(bkpinfo, filelist);
2617 if (bkpinfo->backup_media_type == cdstream) {
2618 closein_cdstream(bkpinfo);
2619 } else {
2620 closein_tape(bkpinfo);
2621 }
2622 } else {
2623 mvaddstr_and_log_it(g_currentY++, 0,
[1199]2624 _("Restoring OS and data from CD "));
[128]2625 mount_cdrom(bkpinfo);
2626 resA = restore_all_tarballs_from_CD(bkpinfo, filelist);
2627 resB = restore_all_biggiefiles_from_CD(bkpinfo, filelist);
[1]2628 }
[128]2629 chdir(cwd);
2630 if (resA + resB) {
[1199]2631 log_to_screen(_("Errors occurred while data was being restored."));
[1]2632 }
[128]2633 if (length_of_file("/etc/raidtab") > 0) {
[1108]2634 mr_msg(2, "Copying local raidtab to restored filesystem");
[128]2635 run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING
2636 "/etc/raidtab", FALSE);
[1]2637 }
[128]2638 kill_petris();
[1108]2639 mr_msg(2, "restore_everything() --- leaving");
[1080]2640 mr_free(cwd);
2641 mr_free(newpath);
[128]2642 return (resA + resB);
[1]2643}
2644
2645/**************************************************************************
2646 *END_RESTORE_EVERYTHING *
2647 **************************************************************************/
2648
2649
2650/**
2651 * @brief Haha. You wish! (This function is not implemented :-)
2652 */
2653int
[128]2654restore_live_from_monitas_server(struct s_bkpinfo *bkpinfo,
2655 char *monitas_device,
2656 char *restore_this_directory,
2657 char *restore_here)
2658 /* NB: bkpinfo hasn't been populated yet, except for ->tmp which is "/tmp" */
[1]2659{
[128]2660 FILE *fout;
2661 int retval = 0;
2662 int i;
2663 int j;
2664 struct mountlist_itself the_mountlist;
2665 static struct raidlist_itself the_raidlist;
[1]2666 /** malloc **/
[128]2667 char tmp[MAX_STR_LEN + 1];
2668 char command[MAX_STR_LEN + 1];
2669 char datablock[256 * 1024];
2670 char datadisks_fname[MAX_STR_LEN + 1];
2671 long k;
2672 long length;
2673 long long llt;
2674 struct s_node *filelist = NULL;
2675 assert(bkpinfo != NULL);
2676 assert_string_is_neither_NULL_nor_zerolength(monitas_device);
2677 assert(restore_this_directory != NULL);
2678 assert(restore_here != NULL);
[1]2679
[128]2680 sprintf(tmp, "restore_here = '%s'", restore_here);
[1]2681
[1108]2682 mr_msg(2, tmp);
[1]2683
[1108]2684 mr_msg(2, "restore_live_from_monitas_server() - starting");
[128]2685 unlink("/tmp/mountlist.txt");
2686 unlink("/tmp/filelist.full");
2687 unlink("/tmp/biggielist.txt");
2688 if (restore_here[0] == '\0') {
2689 strcpy(bkpinfo->restore_path, MNT_RESTORING);
2690 } else {
2691 strcpy(bkpinfo->restore_path, restore_here);
2692 }
[1108]2693 mr_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
[128]2694 sprintf(tmp, "FYI - data will be restored to %s",
2695 bkpinfo->restore_path);
[1108]2696 mr_msg(3, tmp);
2697 mr_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
[128]2698 sprintf(datadisks_fname, "/tmp/mondorestore.datadisks.%d",
2699 (int) (random() % 32768));
2700 chdir(bkpinfo->tmpdir);
[1]2701
[128]2702 sprintf(command, "cat %s", monitas_device);
2703 g_tape_stream = popen(command, "r"); // for compatibility with openin_tape()
2704 if (!(fout = fopen(datadisks_fname, "w"))) {
2705 log_OS_error(datadisks_fname);
2706 return (1);
2707 }
2708 for (i = 0; i < 32; i++) {
2709 for (j = 0; j < 4; j++) {
2710 for (length = k = 0; length < 256 * 1024; length += k) {
2711 k = fread(datablock + length, 1, 256 * 1024 - length,
2712 g_tape_stream);
2713 }
2714 fwrite(datablock, 1, length, fout);
2715 g_tape_posK += length;
2716 }
2717 }
2718 paranoid_fclose(fout);
2719 sprintf(command,
2720 "tar -zxvf %s tmp/mondo-restore.cfg tmp/mountlist.txt tmp/filelist.full tmp/biggielist.txt",
2721 datadisks_fname);
2722 run_program_and_log_output(command, 4);
2723 read_header_block_from_stream(&llt, tmp, &i);
2724 read_header_block_from_stream(&llt, tmp, &i);
[1]2725
[128]2726 unlink(datadisks_fname);
2727 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
2728 retval = load_mountlist(&the_mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo strcpy(bkpinfo->media_device, monitas_device);
2729
2730
2731 load_raidtab_into_raidlist(&the_raidlist, RAIDTAB_FNAME);
2732 iamhere("FIXME");
2733 fatal_error("This will fail");
2734 sprintf(command,
[911]2735 "grep -E '^%s.*$' %s > %s",
[273]2736 restore_this_directory, g_filelist_full, g_filelist_full);
[128]2737 if (system(command)) {
2738 retval++;
2739 log_to_screen
[541]2740 ("Error(s) occurred while processing filelist and wildcard");
[128]2741 }
2742 iamhere("FIXME");
2743 fatal_error("This will fail");
2744 sprintf(command,
[911]2745 "grep -E '^%s.*$' %s > %s",
[273]2746 restore_this_directory, g_biggielist_txt, g_biggielist_txt);
[128]2747 if (system(command)) {
[1108]2748 mr_msg(1,
[128]2749 "Error(s) occurred while processing biggielist and wildcard");
2750 }
2751 sprintf(command, "touch %s", g_biggielist_txt);
2752 run_program_and_log_output(command, FALSE);
[1]2753// filelist = load_filelist(g_filelist_restthese); // FIXME --- this probably doesn't work because it doesn't include the biggiefiles
[128]2754 retval += restore_everything(bkpinfo, filelist);
2755 free_filelist(filelist);
[1108]2756 mr_msg(2, "--------End of restore_live_from_monitas_server--------");
[128]2757 return (retval);
[1]2758}
[128]2759
[1]2760/**************************************************************************
2761 *END_RESTORE_LIVE_FROM_MONITAS_SERVER *
2762 **************************************************************************/
2763
2764
2765
2766
[1251]2767extern void wait_until_software_raids_are_prepped(int);
[1]2768
2769char which_restore_mode(void);
2770
2771
2772/**
2773 * Log a "don't panic" message to the logfile.
2774 */
[1265]2775void welcome_to_mondorestore(void)
[1]2776{
[1108]2777 mr_msg(0, "-------------- Mondo Restore v%s -------------", PACKAGE_VERSION);
2778 mr_msg(0,
[128]2779 "DON'T PANIC! Mondorestore logs almost everything, so please ");
[1108]2780 mr_msg(0,
[128]2781 "don't break out in a cold sweat just because you see a few ");
[1108]2782 mr_msg(0,
[128]2783 "error messages in the log. Read them; analyze them; see if ");
[1108]2784 mr_msg(0,
[128]2785 "they are significant; above all, verify your backups! Please");
[1108]2786 mr_msg(0,
[128]2787 "attach a compressed copy of this log to any e-mail you send ");
[1108]2788 mr_msg(0,
[128]2789 "to the Mondo mailing list when you are seeking technical ");
[1108]2790 mr_msg(0,
[607]2791 "support. Without it, we can't help you. - DevTeam");
[1108]2792 mr_msg(0,
[128]2793 "------------------------------------------------------------");
[1108]2794 mr_msg(0,
[128]2795 "BTW, despite (or perhaps because of) the wealth of messages,");
[1108]2796 mr_msg(0,
[128]2797 "some users are inclined to stop reading this log. If Mondo ");
[1108]2798 mr_msg(0,
[128]2799 "stopped for some reason, chances are it's detailed here. ");
[1108]2800 mr_msg(0,
[1199]2801 "More than likely there's a message near the end of this ");
[1108]2802 mr_msg(0,
[128]2803 "log that will tell you what is wrong. Please read it! ");
[1108]2804 mr_msg(0,
[128]2805 "------------------------------------------------------------");
[1]2806}
2807
2808
2809/**
2810 * Restore the user's data.
2811 * What did you think it did, anyway? :-)
2812 */
[1556]2813int main(int argc, char *argv[])
[1]2814{
[1199]2815 FILE *fin = NULL;
2816 FILE *fout = NULL;
[128]2817 int retval = 0;
[1199]2818 int res = 0;
2819 char *tmp = NULL;
[1]2820
[1199]2821 struct mountlist_itself *mountlist = NULL;
2822 struct raidlist_itself *raidlist = NULL;
2823 struct s_bkpinfo *bkpinfo = NULL;
2824 struct s_node *filelist = NULL;
2825 char *a = NULL, *b = NULL;
[818]2826 bool run_postnuke = FALSE;
[1]2827
[1199]2828#ifdef ENABLE_NLS
2829 setlocale(LC_ALL, "");
2830 (void) textdomain("mondo");
2831#endif
2832
[1264]2833 /* Reference the right cleanup function for mr_exit */
[1269]2834 mr_cleanup = &mr_rs_cleanup;
[1264]2835
[128]2836 if (getuid() != 0) {
[1199]2837 fprintf(stderr, _("Please run as root.\n"));
[1264]2838 mr_exit(127, NULL);
[128]2839 }
[1626]2840 /* Conf file management */
2841 mr_conf = mr_malloc(sizeof(struct mr_rs_conf));
2842 mr_rs_reset_conf(mr_conf);
[1]2843
[1625]2844 mr_conf->log_level = DEFAULT_MR_LOGLEVEL;
[128]2845
[1]2846/* Configure global variables */
2847#ifdef __FreeBSD__
[128]2848 if (strstr
2849 (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
2850 "textonly"))
[1]2851#else
[128]2852 if (strstr
2853 (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
2854 "textonly"))
[1]2855#endif
[128]2856 {
2857 g_text_mode = TRUE;
[1108]2858 mr_msg(1, "TEXTONLY MODE");
[128]2859 } else {
2860 g_text_mode = FALSE;
2861 } // newt :-)
[1166]2862 bkpinfo = mr_malloc(sizeof(struct s_bkpinfo));
[1080]2863 mountlist = mr_malloc(sizeof(struct mountlist_itself));
2864 raidlist = mr_malloc(sizeof(struct raidlist_itself));
[1]2865
[128]2866 malloc_libmondo_global_strings();
[1]2867
[128]2868 sprintf(g_tmpfs_mountpt, "/tmp/tmpfs");
2869 make_hole_for_dir(g_tmpfs_mountpt);
2870 g_current_media_number = 1; // precaution
[1]2871
[128]2872 run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE);
[1]2873
[128]2874 malloc_string(a);
2875 malloc_string(b);
2876 setup_MR_global_filenames(bkpinfo); // malloc() and set globals, using bkpinfo->tmpdir etc.
2877 reset_bkpinfo(bkpinfo);
2878 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]2879 strcpy(bkpinfo->backup_media_string,"");
[128]2880 bkpinfo->restore_data = TRUE; // Well, yeah :-)
2881 if (am_I_in_disaster_recovery_mode()) {
2882 run_program_and_log_output("mount / -o remount,rw", 2);
2883 } // for b0rken distros
2884 g_main_pid = getpid();
2885 srandom((int) (time(NULL)));
2886 register_pid(getpid(), "mondo");
2887 set_signals(TRUE);
2888 g_kernel_version = get_kernel_version();
[1]2889
[1108]2890 mr_msg(1, "FYI - g_mountlist_fname = %s", g_mountlist_fname);
[128]2891 if (strlen(g_mountlist_fname) < 3) {
2892 fatal_error
2893 ("Serious error in malloc()'ing. Could be a bug in your glibc.");
2894 }
2895 mkdir(MNT_CDROM, 0x770);
2896
[1]2897/* Backup original mountlist.txt */
[1199]2898 mr_asprintf(&tmp, "%s.orig", g_mountlist_fname);
[128]2899 if (!does_file_exist(g_mountlist_fname)) {
[1108]2900 mr_msg(2,
[128]2901 "%ld: Warning - g_mountlist_fname (%s) does not exist yet",
2902 __LINE__, g_mountlist_fname);
2903 } else if (!does_file_exist(tmp)) {
[1199]2904 mr_free(tmp);
2905 mr_asprintf(&tmp, "cp -f %s %s.orig", g_mountlist_fname,
[128]2906 g_mountlist_fname);
2907 run_program_and_log_output(tmp, FALSE);
2908 }
[1199]2909 mr_free(tmp);
[1]2910
2911/* Init directories */
[128]2912 make_hole_for_dir(bkpinfo->tmpdir);
[1199]2913 mr_asprintf(&tmp, "mkdir -p %s", bkpinfo->tmpdir);
[128]2914 run_program_and_log_output(tmp, FALSE);
[1199]2915 mr_free(tmp);
2916
[128]2917 make_hole_for_dir("/var/log");
2918 make_hole_for_dir("/tmp/tmpfs"); /* just in case... */
2919 run_program_and_log_output("umount " MNT_CDROM, FALSE);
[1]2920
[128]2921 run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE);
[1]2922
[1199]2923 /* Init GUI */
[128]2924 malloc_libmondo_global_strings();
2925 setup_newt_stuff(); /* call newtInit and setup screen log */
2926 welcome_to_mondorestore();
2927 if (bkpinfo->disaster_recovery) {
[1108]2928 mr_msg(1, "I am in disaster recovery mode");
[128]2929 } else {
[1108]2930 mr_msg(1, "I am in normal, live mode");
[128]2931 }
[1]2932
[128]2933 iamhere("what time is it");
[1]2934
[1199]2935 /* Process command-line parameters */
[128]2936 if (argc == 2 && strcmp(argv[1], "--edit-mountlist") == 0) {
[1]2937#ifdef __FreeBSD__
[128]2938 system("mv -f /tmp/raidconf.txt /etc/raidtab");
2939 if (!does_file_exist("/etc/raidtab"))
2940 system("vinum printconfig > /etc/raidtab");
[1]2941#endif
[128]2942 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
2943 if (!does_file_exist(g_mountlist_fname)) {
2944 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
2945 }
2946 res = let_user_edit_the_mountlist(bkpinfo, mountlist, raidlist);
[1]2947#ifdef __FreeBSD__
[128]2948 system("mv -f /etc/raidtab /tmp/raidconf.txt");
[1]2949#endif
[128]2950 paranoid_MR_finish(res);
2951 }
[1]2952
[1625]2953 mr_conf->log_level = DEFAULT_MR_LOGLEVEL;
[128]2954 if (argc == 3 && strcmp(argv[1], "--echo-to-screen") == 0) {
2955 fout = fopen("/tmp/out.txt", "w");
2956 fput_string_one_char_at_a_time(stderr, argv[2]);
2957 finish(0);
2958 }
[1]2959
[128]2960 if (argc == 3 && strcmp(argv[1], "--gendf") == 0) {
2961 make_grub_install_scriptlet(argv[2]);
2962 finish(0);
2963 }
[1]2964
[128]2965 if (argc >= 2 && strcmp(argv[1], "--pih") == 0) {
2966 if (system("mount | grep cdrom 2> /dev/null > /dev/null")) {
2967 system("mount " MNT_CDROM);
2968 }
2969 bkpinfo->compression_level = 1;
2970 g_current_media_number = 2;
2971 strcpy(bkpinfo->restore_path, "/tmp/TESTING");
2972 bkpinfo->backup_media_type = dvd;
[1199]2973 open_progress_form(_("Reassembling /dev/hda1"),
2974 _("Shark is a bit of a silly person."),
2975 _("Please wait. This may take some time."),
[128]2976 "", 1999);
2977 system("rm -Rf /tmp/*pih*");
[1]2978
[1199]2979 malloc_string(tmp);
[128]2980 restore_a_biggiefile_from_CD(bkpinfo, 42, NULL, tmp);
[1199]2981 mr_free(tmp);
[128]2982 }
[1]2983
[128]2984 if (argc == 5 && strcmp(argv[1], "--common") == 0) {
[1625]2985 mr_conf->log_level = 6;
[128]2986 filelist = load_filelist(argv[2]);
2987 if (!filelist) {
2988 fatal_error("Failed to load filelist");
2989 }
2990 toggle_node_selection(filelist, FALSE);
2991 toggle_all_root_dirs_on(filelist);
[179]2992 // BERLIOS: /usr/lib ???
[128]2993 toggle_path_selection(filelist, "/usr/share", TRUE);
2994 save_filelist(filelist, "/tmp/out.txt");
[1199]2995 mr_asprintf(&a, argv[3]);
2996 mr_asprintf(&b, argv[4]);
[1]2997
[128]2998 res = save_filelist_entries_in_common(a, filelist, b, FALSE);
2999 free_filelist(filelist);
[1199]3000 mr_free(a);
3001 mr_free(b);
[128]3002 printf("res = %d", res);
3003 finish(0);
3004 }
[1]3005
[128]3006 if (argc == 3 && strcmp(argv[1], "--popuplist") == 0) {
3007 popup_changelist_from_file(argv[2]);
3008 paranoid_MR_finish(0);
3009 }
[1]3010
[128]3011 if (argc == 5 && strcmp(argv[1], "--copy") == 0) {
[1108]3012 mr_msg(1, "SCORE");
[1625]3013 mr_conf->log_level = 10;
[128]3014 if (strstr(argv[2], "save")) {
[1108]3015 mr_msg(1, "Saving from %s to %s", argv[3], argv[4]);
[128]3016 fin = fopen(argv[3], "r");
3017 fout = fopen(argv[4], "w");
3018 copy_from_src_to_dest(fin, fout, 'w');
3019 fclose(fin);
3020 fin = fopen(argv[3], "r");
3021 copy_from_src_to_dest(fin, fout, 'w');
3022 fclose(fout);
3023 fclose(fin);
3024 } else if (strstr(argv[2], "restore")) {
3025 fout = fopen(argv[3], "w");
3026 fin = fopen(argv[4], "r");
3027 copy_from_src_to_dest(fout, fin, 'r');
3028 fclose(fin);
3029 fin = fopen(argv[4], "r");
3030 copy_from_src_to_dest(fout, fin, 'r');
3031 fclose(fout);
3032 fclose(fin);
3033 } else {
3034 fatal_error("Unknown additional param");
3035 }
3036 finish(0);
3037 }
[1]3038
[1251]3039 if (argc == 2 && strcmp(argv[1], "--mdstat") == 0) {
3040 wait_until_software_raids_are_prepped(100);
[128]3041 finish(0);
3042 }
[1]3043
[558]3044 if (argc == 3 && strcmp(argv[1], "--mdconv") == 0) {
3045 finish(create_raidtab_from_mdstat(argv[2]));
[128]3046 }
[1]3047
[1454]3048 if (argc == 3 && strcmp(argv[1], "-p") == 0) {
3049 strcpy(bkpinfo->prefix,argv[2]);
[1555]3050 mr_msg(1,"Prefix forced to %s",bkpinfo->prefix);
[1454]3051 }
[128]3052
[1454]3053
[128]3054 if (argc == 2 && strcmp(argv[1], "--live-grub") == 0) {
3055 retval = run_grub(FALSE, "/dev/hda");
3056 if (retval) {
[1199]3057 log_to_screen(_("Failed to write Master Boot Record"));
[128]3058 }
3059 paranoid_MR_finish(0);
[1]3060 }
[128]3061 if (argc == 3 && strcmp(argv[1], "--paa") == 0) {
3062 g_current_media_number = atoi(argv[2]);
[1594]3063 pause_and_ask_for_cdr(5);
[128]3064 paranoid_MR_finish(0);
3065 } else if (!bkpinfo->disaster_recovery) { // live!
3066 if (argc != 1) {
3067 popup_and_OK
[1203]3068 (_("Live mode doesn't support command-line parameters yet."));
[128]3069 paranoid_MR_finish(1);
3070 }
[1108]3071 mr_msg(1, "I am in normal, live mode.");
3072 mr_msg(2, "FYI, MOUNTLIST_FNAME = %s", g_mountlist_fname);
[128]3073 mount_boot_if_necessary(); /* for Gentoo users */
[1108]3074 mr_msg(2, "Still here.");
[128]3075 if (argc > 1 && strcmp(argv[argc - 1], "--live-from-cd") == 0) {
3076 g_restoring_live_from_cd = TRUE;
3077 }
3078 if (argc == 5 && strcmp(argv[1], "--monitas-live") == 0) {
3079 retval =
3080 restore_live_from_monitas_server(bkpinfo,
3081 argv[2],
3082 argv[3], argv[4]);
3083 } else {
[1108]3084 mr_msg(2, "Calling restore_to_live_filesystem()");
[128]3085 retval = restore_to_live_filesystem(bkpinfo);
3086 }
[1108]3087 mr_msg(2, "Still here. Yay.");
[128]3088 if (strlen(bkpinfo->tmpdir) > 0) {
[1199]3089 mr_asprintf(&tmp, "rm -Rf %s/*", bkpinfo->tmpdir);
[128]3090 run_program_and_log_output(tmp, FALSE);
[1199]3091 mr_free(tmp);
[128]3092 }
3093 unmount_boot_if_necessary(); /* for Gentoo users */
3094 paranoid_MR_finish(retval);
3095 } else {
[804]3096 /* Disaster recovery mode (must be) */
[1108]3097 mr_msg(1, "I must be in disaster recovery mode.");
3098 mr_msg(2, "FYI, MOUNTLIST_FNAME = %s ", g_mountlist_fname);
[128]3099 if (argc == 3 && strcmp(argv[1], "--monitas-memorex") == 0) {
[1199]3100 log_to_screen(_("Uh, that hasn't been implemented yet."));
[128]3101 paranoid_MR_finish(1);
3102 }
[1]3103
[128]3104 iamhere("About to call load_mountlist and load_raidtab");
3105 strcpy(bkpinfo->restore_path, MNT_RESTORING);
3106 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
3107 retval = load_mountlist(mountlist, g_mountlist_fname);
3108 retval += load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3109 iamhere
3110 ("Returned from calling load_mountlist and load_raidtab successfully");
[1]3111
[128]3112 if (argc > 1
3113 && (strcmp(argv[1], "--compare") == 0
3114 || strcmp(argv[1], "--nuke") == 0)) {
3115 if (bkpinfo->backup_media_type == nfs
3116 && !is_this_device_mounted(bkpinfo->nfs_mount)) {
[1108]3117 mr_msg(1, "Mounting nfs dir");
[128]3118 sprintf(bkpinfo->isodir, "/tmp/isodir");
3119 run_program_and_log_output("mkdir -p /tmp/isodir", 5);
[1199]3120 mr_asprintf(&tmp, "mount %s -t nfs -o nolock /tmp/isodir",
[128]3121 bkpinfo->nfs_mount);
3122 run_program_and_log_output(tmp, 1);
[1199]3123 mr_free(tmp);
[128]3124 }
3125 }
[1]3126
3127
[128]3128 if (retval) {
3129 log_to_screen
[1203]3130 (_("Warning - load_raidtab_into_raidlist returned an error"));
[128]3131 }
[1]3132
3133
[1108]3134 mr_msg(1, "Send in the clowns.");
[1]3135
[128]3136 if (argc == 2 && strcmp(argv[1], "--partition-only") == 0) {
[1108]3137 mr_msg(0, "Partitioning only.");
[128]3138 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3139 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3140 load_mountlist(mountlist, g_mountlist_fname);
3141 res = partition_everything(mountlist);
3142 finish(res);
3143 }
[1]3144
[128]3145 if (argc == 2 && strcmp(argv[1], "--format-only") == 0) {
[1108]3146 mr_msg(0, "Formatting only.");
[128]3147 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3148 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3149 load_mountlist(mountlist, g_mountlist_fname);
[558]3150 res = format_everything(mountlist, FALSE, raidlist);
[128]3151 finish(res);
3152 }
[1]3153
[128]3154 if (argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0) {
[1108]3155 mr_msg(0, "Stopping LVM and RAID");
[128]3156 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3157 strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3158 load_mountlist(mountlist, g_mountlist_fname);
3159 res = do_my_funky_lvm_stuff(TRUE, FALSE);
3160 res += stop_all_raid_devices(mountlist);
3161 finish(res);
3162 }
3163
3164 if (argc == 2 && strcmp(argv[1], "--nuke") == 0) {
3165 iamhere("nuking");
3166 retval += nuke_mode(bkpinfo, mountlist, raidlist);
3167 } else if (argc == 2 && strcmp(argv[1], "--interactive") == 0) {
3168 iamhere("catchall");
3169 retval += catchall_mode(bkpinfo, mountlist, raidlist);
3170 } else if (argc == 2 && strcmp(argv[1], "--compare") == 0) {
3171 iamhere("compare");
3172 retval += compare_mode(bkpinfo, mountlist, raidlist);
3173 } else if (argc == 2 && strcmp(argv[1], "--iso") == 0) {
3174 iamhere("iso");
3175 retval = iso_mode(bkpinfo, mountlist, raidlist, FALSE);
3176 } else if (argc == 2 && strcmp(argv[1], "--mbr") == 0) {
3177 iamhere("mbr");
3178 retval = mount_all_devices(mountlist, TRUE);
3179 if (!retval) {
3180 retval += run_boot_loader(FALSE);
3181 retval += unmount_all_devices(mountlist);
3182 }
3183 if (retval) {
[1199]3184 log_to_screen(_("Failed to write Master Boot Record"));
[128]3185 }
3186 } else if (argc == 2 && strcmp(argv[1], "--isonuke") == 0) {
3187 iamhere("isonuke");
3188 retval = iso_mode(bkpinfo, mountlist, raidlist, TRUE);
3189 } else if (argc != 1) {
[1202]3190 log_to_screen(_("Invalid parameters"));
[128]3191 paranoid_MR_finish(1);
3192 } else {
3193 iamhere("catchall (no mode specified in command-line call");
3194 retval += catchall_mode(bkpinfo, mountlist, raidlist);
3195 }
[1]3196 }
[128]3197
3198 /* clean up at the end */
3199 if (retval) {
3200 if (does_file_exist("/tmp/changed.files")) {
3201 log_to_screen
[1203]3202 (_("See /tmp/changed.files for list of files that have changed."));
[128]3203 }
3204 mvaddstr_and_log_it(g_currentY++,
3205 0,
[1203]3206 _("Run complete. Errors were reported. Please review the logfile."));
[128]3207 } else {
3208 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
3209 mvaddstr_and_log_it(g_currentY++,
3210 0,
[1581]3211 _("Run complete. Please remove CD/media and reboot."));
[128]3212 } else {
3213 run_program_and_log_output("sync", FALSE);
3214 if (is_this_device_mounted(MNT_CDROM)) {
3215 res =
3216 run_program_and_log_output("umount " MNT_CDROM, FALSE);
3217 } else {
3218 res = 0;
3219 }
3220
3221 if (!bkpinfo->please_dont_eject) {
3222 res = eject_device("/dev/cdrom");
3223 }
3224 mvaddstr_and_log_it(g_currentY++,
3225 0,
[1203]3226 _("Run complete. Please remove media and reboot."));
[128]3227 }
[1]3228 }
3229
[1199]3230 // g_I_have_just_nuked is set true by nuke_mode() just before it returns
[818]3231 if (!system("which post-nuke > /dev/null 2> /dev/null")) {
[1108]3232 mr_msg(1, "post-nuke found; find out whether we should run it...");
[818]3233 if (g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY")) {
3234 run_postnuke = TRUE;
[1108]3235 mr_msg(1, "Yes, will run post-nuke because in nuke mode or file /POST-NUKE-ANYWAY exists.");
[818]3236 } else if (ask_me_yes_or_no("post-nuke script found. Do you want to run it?")) {
3237 run_postnuke = TRUE;
[1108]3238 mr_msg(1, "Yes, will run post-nuke because user interactively asked for it.");
[818]3239 } else {
3240 run_postnuke = FALSE;
[1108]3241 mr_msg(1, "No, will not run post-nuke.");
[818]3242 }
3243 } else {
[1108]3244 mr_msg(1, "No post-nuke found.");
[128]3245 }
[818]3246 if (run_postnuke) {
3247 log_to_screen("Running post-nuke...");
3248 if (mount_all_devices(mountlist, TRUE)) {
3249 log_to_screen
3250 ("Unable to re-mount partitions for post-nuke stuff");
3251 } else {
[1108]3252 mr_msg(1, "Re-mounted partitions for post-nuke stuff");
[1199]3253 mr_asprintf(&tmp, "post-nuke %s %d", bkpinfo->restore_path,
[818]3254 retval);
[1108]3255 mr_msg(2, "Calling '%s'", tmp);
[818]3256 if ((res = run_program_and_log_output(tmp, 0))) {
3257 log_OS_error(tmp);
3258 }
[1199]3259 mr_free(tmp);
[1108]3260 mr_msg(1, "post-nuke returned w/ res=%d", res);
[818]3261 }
3262 unmount_all_devices(mountlist);
3263 log_to_screen("I've finished post-nuking.");
3264 }
3265
[128]3266 unlink("/tmp/mondo-run-prog.tmp");
3267 set_signals(FALSE);
[1199]3268 mr_asprintf(&tmp, "rm -Rf %s", bkpinfo->tmpdir);
[128]3269 run_program_and_log_output(tmp, FALSE);
[1199]3270 mr_free(tmp);
3271
[128]3272 log_to_screen
[1326]3273 (_("Restore log (%s) copied to /var/log on your hard disk"), MONDO_LOGFILE);
[1199]3274 log_to_screen(_("Mondo-restore is exiting (retval=%d)"), retval);
3275
3276 mr_asprintf(&tmp, "umount %s", bkpinfo->isodir);
[128]3277 run_program_and_log_output(tmp, 5);
[1199]3278 mr_free(tmp);
3279
[1080]3280 mr_free(mountlist);
3281 mr_free(raidlist);
[128]3282 if (am_I_in_disaster_recovery_mode()) {
3283 run_program_and_log_output("mount / -o remount,rw", 2);
3284 } // for b0rken distros
3285 paranoid_MR_finish(retval); // frees global stuff plus bkpinfo
3286 free_libmondo_global_strings(); // it's fine to have this here :) really :)
[1]3287
[128]3288 unlink("/tmp/filelist.full");
3289 unlink("/tmp/filelist.full.gz");
3290
[1264]3291 mr_exit(retval, NULL);
[1]3292}
3293
3294/**************************************************************************
3295 *END_MAIN *
3296 **************************************************************************/
3297
3298
3299/**************************************************************************
3300 *END_MONDO-RESTORE.C *
3301 **************************************************************************/
Note: See TracBrowser for help on using the repository browser.