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

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

Continue to use configuration file data (may not compile)

  • Property svn:keywords set to Id
File size: 99.3 KB
RevLine 
[1]1/***************************************************************************
[1080]2* restores mondoarchive data
3* $Id: mondorestore.c 1638 2007-09-19 07:32:00Z 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 1638 2007-09-19 07:32:00Z 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");
[1638]440 mr_asprintf(&tmp,bkpinfo->prefix);
[1454]441 if (popup_and_get_string
[1638]442 ("Prefix", "Prefix of your ISO images ?", tmp, MAX_STR_LEN / 4)) {
443 mr_free(bkpinfo->prefix);
444 bkpinfo->prefix = tmp;
[1556]445 mr_msg(1, "Prefix set to %s",bkpinfo->prefix);
[1454]446 }
447
[1]448#ifdef __FreeBSD__
[128]449 if (strstr
450 (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
451 "noresize"))
[1]452#else
[128]453 if (strstr
454 (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
455 "noresize"))
[1]456#endif
[128]457 {
[1108]458 mr_msg(1, "Not resizing mountlist.");
[128]459 } else {
460 resize_mountlist_proportionately_to_suit_new_drives(mountlist);
[1]461 }
[128]462 for (done = FALSE; !done;) {
463 iamhere("About to edit mountlist");
464 if (g_text_mode) {
465 save_mountlist_to_disk(mountlist, g_mountlist_fname);
[1199]466 mr_asprintf(&tmp, "%s %s", find_my_editor(), g_mountlist_fname);
[128]467 res = system(tmp);
[1199]468 mr_free(tmp);
[128]469 load_mountlist(mountlist, g_mountlist_fname);
470 } else {
471 res = edit_mountlist(g_mountlist_fname, mountlist, raidlist);
[1]472 }
[128]473 iamhere("Finished editing mountlist");
474 if (res) {
475 paranoid_MR_finish(1);
[1]476 }
[1108]477 mr_msg(2, "Proceeding...");
[128]478 save_mountlist_to_disk(mountlist, g_mountlist_fname);
479 save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
[1199]480 mvaddstr_and_log_it(1, 30, _("Restoring Interactively"));
[128]481 if (bkpinfo->differential) {
[1203]482 log_to_screen(_("Because this is a differential backup, disk"));
483 log_to_screen(_(" partitioning and formatting will not take place."));
[128]484 done = TRUE;
485 } else {
486 if (ask_me_yes_or_no
[1203]487 (_("Do you want to erase and partition your hard drives?")))
[1199]488 {
[128]489 if (partition_table_contains_Compaq_diagnostic_partition
490 (mountlist)) {
491 offer_to_abort_because_Compaq_Proliants_suck();
492 done = TRUE;
493 } else {
494 twenty_seconds_til_yikes();
495 g_fprep = fopen("/tmp/prep.sh", "w");
496 ptn_errs = partition_everything(mountlist);
497 if (ptn_errs) {
498 log_to_screen
[1203]499 (_("Warning. Errors occurred during disk partitioning."));
[128]500 }
[1]501
[558]502 fmt_errs = format_everything(mountlist, FALSE, raidlist);
[128]503 if (!fmt_errs) {
504 log_to_screen
[1203]505 (_("Errors during disk partitioning were handled OK."));
506 log_to_screen(_("Partitions were formatted OK despite those errors."));
[128]507 ptn_errs = 0;
508 }
509 if (!ptn_errs && !fmt_errs) {
510 done = TRUE;
511 }
512 }
513 paranoid_fclose(g_fprep);
514 } else {
515 mvaddstr_and_log_it(g_currentY++, 0,
[1203]516 _("User opted not to partition the devices"));
[128]517 if (ask_me_yes_or_no
[1199]518 (_("Do you want to format your hard drives?"))) {
519 fmt_errs =
520 format_everything(mountlist, TRUE, raidlist);
[128]521 if (!fmt_errs) {
522 done = TRUE;
523 }
524 } else {
525 ptn_errs = fmt_errs = 0;
526 done = TRUE;
527 }
528 }
529 if (fmt_errs) {
530 mvaddstr_and_log_it(g_currentY++,
531 0,
[1203]532 _("Errors occurred. Please repartition and format drives manually."));
[128]533 done = FALSE;
534 }
535 if (ptn_errs & !fmt_errs) {
536 mvaddstr_and_log_it(g_currentY++,
537 0,
[1203]538 _("Errors occurred during partitioning. Formatting, however, went OK."));
[128]539 done = TRUE;
540 }
541 if (!done) {
[1199]542 if (!ask_me_yes_or_no(_("Re-edit the mountlist?"))) {
[128]543 retval++;
[1199]544 iamhere("Leaving interactive_mode()");
545 return (retval);
[128]546 }
547 }
[1]548 }
549 }
550
[128]551 /* mount */
552 if (mount_all_devices(mountlist, TRUE)) {
553 unmount_all_devices(mountlist);
554 retval++;
[1199]555 iamhere("Leaving interactive_mode()");
556 return (retval);
[1]557 }
[128]558 /* restore */
559 if ((restore_all =
[1203]560 ask_me_yes_or_no(_("Do you want me to restore all of your data?"))))
[1]561 {
[1108]562 mr_msg(1, "Restoring all data");
[128]563 retval += restore_everything(bkpinfo, NULL);
[1199]564 } else if ((restore_all =
[128]565 ask_me_yes_or_no
[1199]566 (_("Do you want me to restore _some_ of your data?")))) {
567 mr_asprintf(&old_restpath,bkpinfo->restore_path);
[128]568 for (done = FALSE; !done;) {
569 unlink("/tmp/filelist.full");
570 filelist = process_filelist_and_biggielist(bkpinfo);
571 /* Now you have /tmp/tmpfs/filelist.restore-these and /tmp/tmpfs/biggielist.restore-these;
572 the former is a list of regular files; the latter, biggiefiles and imagedevs.
573 */
574 if (filelist) {
[1199]575 malloc_string(tmp1);
[128]576 gotos_suck:
[1199]577 strcpy(tmp1, old_restpath);
578 // (NB: MNT_RESTORING is where your filesystem is mounted now, by default)
[128]579 if (popup_and_get_string
[1199]580 (_("Restore path"), _("Restore files to where?"), tmp1,
[128]581 MAX_STR_LEN / 4)) {
[1199]582 if (!strcmp(tmp1, "/")) {
583 if (!ask_me_yes_or_no(_("Are you sure?"))) {
[128]584 goto gotos_suck;
585 }
[1199]586 tmp1[0] = '\0'; // so we restore to [blank]/file/name :)
[128]587 }
[1199]588 strcpy(bkpinfo->restore_path, tmp1);
[1108]589 mr_msg(1, "Restoring subset");
[128]590 retval += restore_everything(bkpinfo, filelist);
591 free_filelist(filelist);
592 } else {
593 strcpy(bkpinfo->restore_path, old_restpath);
594 free_filelist(filelist);
595 }
596 if (!ask_me_yes_or_no
[1199]597 (_("Restore another subset of your backup?"))) {
[128]598 done = TRUE;
599 }
[1199]600 mr_free(tmp1);
[128]601 } else {
602 done = TRUE;
603 }
604 }
[1199]605 mr_free(old_restpath);
[128]606 } else {
607 mvaddstr_and_log_it(g_currentY++,
608 0,
[1203]609 _("User opted not to restore any data. "));
[1]610 }
[128]611 if (retval) {
612 mvaddstr_and_log_it(g_currentY++,
613 0,
[1203]614 _("Errors occurred during the restore phase. "));
[1]615 }
616
[1199]617 if (ask_me_yes_or_no(_("Initialize the boot loader?"))) {
[128]618 run_boot_loader(TRUE);
619 } else {
620 mvaddstr_and_log_it(g_currentY++,
621 0,
[1203]622 _("User opted not to initialize the boot loader."));
[128]623 }
624
[1548]625 clean_blkid(bkpinfo);
[128]626 protect_against_braindead_sysadmins();
627 retval += unmount_all_devices(mountlist);
628 /* if (restore_some || restore_all || */
629 if (ask_me_yes_or_no
[1297]630 (_("Label/Identify your ext2 and ext3 partitions if necessary?"))) {
[128]631 mvaddstr_and_log_it(g_currentY, 0,
[1297]632 _("Using tune2fs to identify your ext2,3 partitions"));
[128]633 if (does_file_exist("/tmp/fstab.new")) {
[1199]634 mr_asprintf(&fstab_fname, "/tmp/fstab.new");
[128]635 } else {
[1199]636 mr_asprintf(&fstab_fname, "/tmp/fstab");
[128]637 }
[1199]638 mr_asprintf(&tmp,
[128]639 "label-partitions-as-necessary %s < %s >> %s 2>> %s",
640 g_mountlist_fname, fstab_fname, MONDO_LOGFILE,
641 MONDO_LOGFILE);
[1199]642 mr_free(fstab_fname);
643
[128]644 res = system(tmp);
[1199]645 mr_free(tmp);
[128]646 if (res) {
647 log_to_screen
[1199]648 (_("label-partitions-as-necessary returned an error"));
649 mvaddstr_and_log_it(g_currentY++, 74, _("Failed."));
[128]650 } else {
[1199]651 mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
[128]652 }
653 retval += res;
654 }
655
656 iamhere("About to leave interactive_mode()");
657 if (retval) {
658 mvaddstr_and_log_it(g_currentY++,
659 0,
[1203]660 _("Warning - errors occurred during the restore phase."));
[128]661 }
662 iamhere("Leaving interactive_mode()");
[1199]663 return(retval);
[1]664}
[128]665
[1]666/**************************************************************************
667 *END_INTERACTIVE_MODE *
668 **************************************************************************/
669
670
671/**
672 * Run an arbitrary restore mode (prompt the user), but from ISO images
673 * instead of real media.
674 * @param bkpinfo The backup information structure. Most fields are used.
675 * @param mountlist The mountlist containing information about the user's partitions.
676 * @param raidlist The raidlist that goes with @p mountlist.
677 * @param nuke_me_please If TRUE, we plan to run Nuke Mode.
678 * @return 0 for success, or the number of errors encountered.
679 */
[128]680int
681iso_mode(struct s_bkpinfo *bkpinfo,
682 struct mountlist_itself *mountlist,
683 struct raidlist_itself *raidlist, bool nuke_me_please)
[1]684{
[1199]685 char c = ' ';
[128]686 int retval = 0;
[1]687
[128]688 assert(bkpinfo != NULL);
689 assert(mountlist != NULL);
690 assert(raidlist != NULL);
691 if (iso_fiddly_bits(bkpinfo, nuke_me_please)) {
[1108]692 mr_msg(1, "iso_mode --- returning w/ error");
[128]693 return (1);
694 } else {
695 c = which_restore_mode();
696 if (c == 'I' || c == 'N' || c == 'C') {
697 interactively_obtain_media_parameters_from_user(bkpinfo,
698 FALSE);
699 }
700 if (c == 'I') {
701 retval += interactive_mode(bkpinfo, mountlist, raidlist);
702 } else if (c == 'N') {
703 retval += nuke_mode(bkpinfo, mountlist, raidlist);
704 } else if (c == 'C') {
705 retval += compare_mode(bkpinfo, mountlist, raidlist);
706 } else {
[1199]707 log_to_screen(_("OK, I shan't restore/compare any files."));
[128]708 }
709 }
710 if (is_this_device_mounted(MNT_CDROM)) {
711 paranoid_system("umount " MNT_CDROM);
712 }
713 if (system("umount /tmp/isodir 2> /dev/null")) {
714 log_to_screen
[1203]715 (_("WARNING - unable to unmount device where the ISO files are stored."));
[128]716 }
717 return (retval);
[1]718}
[128]719
[1]720/**************************************************************************
721 *END_ISO_MODE *
722 **************************************************************************/
[1199]723static void call_me_after_the_nuke(int retval) {
[1]724
[1199]725 char *tmp = NULL;
726 char *tmp1 = NULL;
[1]727
[1199]728 if (retval) {
729 log_to_screen(_("Errors occurred during the nuke phase."));
[1202]730 log_to_screen(_("Please visit our website at http://www.mondorescue.org for more information."));
[1199]731 } else {
732#ifdef __FreeBSD__
733 tmp1 = call_program_and_get_last_line_of_output("cat /tmp/cmdline");
734#else
735 tmp1 = call_program_and_get_last_line_of_output("cat /proc/cmdline");
736#endif
[1621]737 if (strstr(tmp1,"RESTORE") == NULL) {
[1199]738 /* -H option */
739 mr_asprintf(&tmp,
[1204]740 _(" 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]741 popup_and_OK(tmp);
742 mr_free(tmp);
743 }
[1]744
[1203]745 log_to_screen(_("Mondo has restored your system. Please remove the backup media and reboot."));
746 log_to_screen(_("Thank you for using Mondo Rescue."));
747 log_to_screen(_("Please visit our website at http://www.mondorescue.org for more information."));
[1199]748 }
749 g_I_have_just_nuked = TRUE;
750 return;
751}
[1]752
753
754/**
755 * Restore the user's data automatically (no prompts), after a twenty-second
756 * warning period.
757 * @param bkpinfo The backup information structure. Most fields are used.
758 * @param mountlist The mountlist containing information about the user's partitions.
759 * @param raidlist The raidlist that goes with @p mountlist.
760 * @return 0 for success, or the number of errors encountered.
761 * @warning <b><i>THIS WILL ERASE ALL EXISTING DATA!</i></b>
762 */
[128]763int
764nuke_mode(struct s_bkpinfo *bkpinfo,
765 struct mountlist_itself *mountlist,
766 struct raidlist_itself *raidlist)
[1]767{
[128]768 int retval = 0;
769 int res = 0;
770 bool boot_loader_installed = FALSE;
[1199]771 char *tmp = NULL;
772 char tmpA[MAX_STR_LEN], tmpB[MAX_STR_LEN],
[128]773 tmpC[MAX_STR_LEN];
[1]774
[128]775 assert(bkpinfo != NULL);
776 assert(mountlist != NULL);
777 assert(raidlist != NULL);
[1]778
[1108]779 mr_msg(2, "nuke_mode --- starting");
[1]780
[128]781 get_cfg_file_from_archive_or_bust(bkpinfo);
782 load_mountlist(mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo updated the mountlist
[1]783#ifdef __FreeBSD__
[1199]784 tmp = call_program_and_get_last_line_of_output("cat /tmp/cmdline");
[1]785#else
[1199]786 tmp = call_program_and_get_last_line_of_output("cat /proc/cmdline");
[1]787#endif
[1199]788 if (strstr(tmp,"noresize")) {
[1108]789 mr_msg(2, "Not resizing mountlist.");
[128]790 } else {
791 resize_mountlist_proportionately_to_suit_new_drives(mountlist);
[1]792 }
[128]793 if (!evaluate_mountlist(mountlist, tmpA, tmpB, tmpC)) {
[1199]794 mr_asprintf(&tmp,
[1203]795 _("Mountlist analyzed. Result: \"%s %s %s\" Switch to Interactive Mode?"),
[128]796 tmpA, tmpB, tmpC);
797 if (ask_me_yes_or_no(tmp)) {
[1199]798 mr_free(tmp);
[128]799 retval = interactive_mode(bkpinfo, mountlist, raidlist);
[1199]800 call_me_after_the_nuke(retval);
801 return(retval);
[128]802 } else {
[1199]803 mr_free(tmp);
[128]804 fatal_error("Nuke Mode aborted. ");
805 }
[1]806 }
[128]807 save_mountlist_to_disk(mountlist, g_mountlist_fname);
[1199]808 mvaddstr_and_log_it(1, 30, _("Restoring Automatically"));
[128]809 if (bkpinfo->differential) {
[1199]810 log_to_screen(_("Because this is a differential backup, disk"));
[1203]811 log_to_screen(_("partitioning and formatting will not take place."));
[128]812 res = 0;
813 } else {
814 if (partition_table_contains_Compaq_diagnostic_partition
815 (mountlist)) {
816 offer_to_abort_because_Compaq_Proliants_suck();
817 } else {
818 twenty_seconds_til_yikes();
819 g_fprep = fopen("/tmp/prep.sh", "w");
[1]820#ifdef __FreeBSD__
[1199]821 tmp = call_program_and_get_last_line_of_output("cat /tmp/cmdline");
[1]822#else
[1199]823 tmp = call_program_and_get_last_line_of_output("cat /proc/cmdline");
[1]824#endif
[1199]825 if (strstr(tmp,"nopart")) {
[1108]826 mr_msg(2,
[128]827 "Not partitioning drives due to 'nopart' option.");
828 res = 0;
829 } else {
830 res = partition_everything(mountlist);
831 if (res) {
832 log_to_screen
[1203]833 (_("Warning. Errors occurred during partitioning."));
[128]834 res = 0;
835 }
836 }
837 retval += res;
838 if (!res) {
[1199]839 log_to_screen(_("Preparing to format your disk(s)"));
[128]840 sleep(1);
[1199]841 sync();
[1203]842 log_to_screen(_("Please wait. This may take a few minutes."));
[558]843 res += format_everything(mountlist, FALSE, raidlist);
[128]844 }
845 paranoid_fclose(g_fprep);
846 }
[1]847 }
[128]848 retval += res;
849 if (res) {
850 mvaddstr_and_log_it(g_currentY++,
851 0,
[1203]852 _("Failed to partition and/or format your hard drives."));
[128]853
[1199]854 if (ask_me_yes_or_no(_("Try in interactive mode instead?"))) {
[128]855 retval = interactive_mode(bkpinfo, mountlist, raidlist);
[1199]856 call_me_after_the_nuke(retval);
857 return(retval);
[128]858 } else
859 if (!ask_me_yes_or_no
[1199]860 (_("Would you like to try to proceed anyway?"))) {
861 return(retval);
[128]862 }
[1]863 }
[128]864 retval = mount_all_devices(mountlist, TRUE);
865 if (retval) {
866 unmount_all_devices(mountlist);
867 log_to_screen
[1203]868 (_("Unable to mount all partitions. Sorry, I cannot proceed."));
[128]869 return (retval);
[1]870 }
[128]871 iamhere("Restoring everything");
872 retval += restore_everything(bkpinfo, NULL);
873 if (!run_boot_loader(FALSE)) {
[1108]874 mr_msg(1,
[128]875 "Great! Boot loader was installed. No need for msg at end.");
876 boot_loader_installed = TRUE;
877 }
[1548]878 clean_blkid(bkpinfo);
[128]879 protect_against_braindead_sysadmins();
880 retval += unmount_all_devices(mountlist);
881 mvaddstr_and_log_it(g_currentY,
882 0,
[1297]883 _("Using tune2fs to identify your ext2,3 partitions"));
[1]884
[1199]885 mr_asprintf(&tmp, "label-partitions-as-necessary %s < /tmp/fstab",
[128]886 g_mountlist_fname);
887 res = run_program_and_log_output(tmp, TRUE);
[1199]888 mr_free(tmp);
889
[128]890 if (res) {
[1203]891 log_to_screen(_("label-partitions-as-necessary returned an error"));
[1199]892 mvaddstr_and_log_it(g_currentY++, 74, _("Failed."));
[128]893 } else {
[1199]894 mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
[128]895 }
896 retval += res;
[1]897
[1199]898 call_me_after_the_nuke(retval);
[128]899 return (retval);
[1]900}
901
902/**************************************************************************
903 *END_NUKE_MODE *
904 **************************************************************************/
905
906
907/**
908 * Restore the user's data (or a subset of it) to the live filesystem.
909 * This should not be called if we're booted from CD!
910 * @param bkpinfo The backup information structure. Most fields are used.
911 * @return 0 for success, or the number of errors encountered.
912 */
[128]913int restore_to_live_filesystem(struct s_bkpinfo *bkpinfo)
[1]914{
[128]915 int retval = 0;
[1]916
[1199]917 char *old_restpath = NULL;
[1]918
[1199]919 struct mountlist_itself *mountlist = NULL;
920 struct raidlist_itself *raidlist = NULL;
921 struct s_node *filelist = NULL;
[1]922
[1108]923 mr_msg(1, "restore_to_live_filesystem() - starting");
[128]924 assert(bkpinfo != NULL);
[1199]925
[1080]926 mountlist = mr_malloc(sizeof(struct mountlist_itself));
927 raidlist = mr_malloc(sizeof(struct raidlist_itself));
[1]928
[128]929 strcpy(bkpinfo->restore_path, "/");
930 if (!g_restoring_live_from_cd) {
931 popup_and_OK
[1581]932 (_("Please insert tape/CD, then hit 'OK' to continue."));
[128]933 sleep(1);
934 }
935 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
[1594]936 if (!bkpinfo->media_device) {
[1108]937 mr_msg(2, "Warning - failed to find media dev");
[1199]938 } else {
939 mr_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device);
[128]940 }
[1]941
942
[1108]943 mr_msg(2, "bkpinfo->isodir = %s", bkpinfo->isodir);
[1]944
[1199]945 open_evalcall_form(_("Thinking..."));
[1]946
[128]947 get_cfg_file_from_archive_or_bust(bkpinfo);
948 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
949 load_mountlist(mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo
950
951 close_evalcall_form();
952 retval = load_mountlist(mountlist, g_mountlist_fname);
953 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
954 filelist = process_filelist_and_biggielist(bkpinfo);
955 if (filelist) {
956 save_filelist(filelist, "/tmp/selected-files.txt");
[1199]957 mr_asprintf(&old_restpath,bkpinfo->restore_path);
958 if (popup_and_get_string(_("Restore path"),
[1201]959 _("Restore files to where? "),
[1210]960 bkpinfo->restore_path, MAX_STR_LEN)) {
[128]961 iamhere("Restoring everything");
962 retval += restore_everything(bkpinfo, filelist);
963 }
[1199]964 free_filelist(filelist);
[128]965 strcpy(bkpinfo->restore_path, old_restpath);
[1199]966 mr_free(old_restpath);
[128]967 }
968 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
[1108]969 mr_msg(2,
[1239]970 "Tape : I don't need to unmount or eject the CD-ROM.");
971 } else {
972 run_program_and_log_output("umount " MNT_CDROM, FALSE);
973 if (!bkpinfo->please_dont_eject) {
974 eject_device(bkpinfo->media_device);
975 }
[128]976 }
977 run_program_and_log_output("umount " MNT_CDROM, FALSE);
[1594]978 if ((!bkpinfo->please_dont_eject) && (bkpinfo->media_device)) {
[128]979 eject_device(bkpinfo->media_device);
980 }
[1080]981 mr_free(mountlist);
982 mr_free(raidlist);
[128]983 return (retval);
[1]984}
985
986/**************************************************************************
987 *END_RESTORE_TO_LIVE_FILESYSTEM *
988 **************************************************************************/
989
990/* @} - end of restoreGroup */
991
992
993/**
994 * @addtogroup LLrestoreGroup
995 * @{
996 */
997/**
998 * Restore biggiefile @p bigfileno from the currently mounted CD.
999 * @param bkpinfo The backup information structure. Fields used:
1000 * - @c bkpinfo->backup_media_type
1001 * - @c bkpinfo->restore_path
1002 * @param bigfileno The biggiefile number (starting from 0) to restore.
1003 * @param filelist The node structure containing the list of files to restore.
1004 * If the biggiefile is not in this list, it will be skipped (return value will
1005 * still indicate success).
1006 * @return 0 for success (or skip), nonzero for failure.
1007 */
1008int
1009restore_a_biggiefile_from_CD(struct s_bkpinfo *bkpinfo,
[128]1010 long bigfileno,
1011 struct s_node *filelist,
1012 char *pathname_of_last_file_restored)
[1]1013{
[1199]1014 FILE *fin = NULL;
1015 FILE *fout = NULL;
1016 FILE *fbzip2 = NULL;
[128]1017
[1199]1018 char *checksum = NULL;
1019 char *outfile_fname = NULL;
1020 char *tmp = NULL;
1021 char *bzip2_command = NULL;
1022 char *suffix = NULL;
1023 char *bigblk = NULL;
[128]1024 int retval = 0;
1025 int finished = FALSE;
[1199]1026 long sliceno = 0L;
[128]1027 long siz;
[1199]1028 char *ntfsprog_fifo = NULL;
[128]1029 char *file_to_openout = NULL;
1030 struct s_filename_and_lstat_info biggiestruct;
[1199]1031 struct utimbuf the_utime_buf, *ubuf = NULL;
[296]1032 bool use_ntfsprog_hack = FALSE;
[128]1033 pid_t pid;
1034 int res = 0;
1035 int old_loglevel;
[1199]1036 struct s_node *node = NULL;
[1]1037
[1625]1038 old_loglevel = mr_conf->log_level;
[128]1039 ubuf = &the_utime_buf;
1040 assert(bkpinfo != NULL);
[1]1041
[128]1042 pathname_of_last_file_restored[0] = '\0';
[1638]1043 bigblk = mr_malloc(mr_conf->external_tape_blocksize);
[1]1044
[128]1045 if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) {
[541]1046 log_to_screen("Cannot even open bigfile's info file");
[128]1047 return (1);
1048 }
[1]1049
[128]1050 memset((void *) &biggiestruct, 0, sizeof(biggiestruct));
1051 if (fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin) <
1052 sizeof(biggiestruct)) {
[1108]1053 mr_msg(2, "Warning - unable to get biggiestruct of bigfile #%d",
[128]1054 bigfileno + 1);
1055 }
1056 paranoid_fclose(fin);
[1]1057
[1199]1058 mr_asprintf(&checksum, biggiestruct.checksum);
[1]1059
[128]1060 if (!checksum[0]) {
[1199]1061 mr_msg(3, "Warning - bigfile %ld does not have a checksum",
[128]1062 bigfileno + 1);
1063 }
[1199]1064 mr_free(checksum);
[1]1065
[128]1066 if (!strncmp(biggiestruct.filename, "/dev/", 5)) // Whether NTFS or not :)
1067 {
[1199]1068 mr_asprintf(&outfile_fname, biggiestruct.filename);
[128]1069 } else {
[1199]1070 mr_asprintf(&outfile_fname, "%s/%s", bkpinfo->restore_path,
[128]1071 biggiestruct.filename);
1072 }
[1]1073
[128]1074 /* skip file if we have a selective restore subset & it doesn't match */
1075 if (filelist != NULL) {
1076 node = find_string_at_node(filelist, biggiestruct.filename);
1077 if (!node) {
[1108]1078 mr_msg(0, "Skipping %s (name isn't in filelist)",
[128]1079 biggiestruct.filename);
1080 return (0);
1081 } else if (!(node->selected)) {
[1108]1082 mr_msg(1, "Skipping %s (name isn't in biggielist subset)",
[128]1083 biggiestruct.filename);
1084 return (0);
1085 }
[1]1086 }
[128]1087 /* otherwise, continue */
[1]1088
[1108]1089 mr_msg(1, "DEFINITELY restoring %s", biggiestruct.filename);
[296]1090 if (biggiestruct.use_ntfsprog) {
[128]1091 if (strncmp(biggiestruct.filename, "/dev/", 5)) {
[1108]1092 mr_msg(1,
[296]1093 "I was in error when I set biggiestruct.use_ntfsprog to TRUE.");
[1108]1094 mr_msg(1, "%s isn't even in /dev", biggiestruct.filename);
[296]1095 biggiestruct.use_ntfsprog = FALSE;
[128]1096 }
1097 }
1098
[296]1099 if (biggiestruct.use_ntfsprog) // if it's an NTFS device
[128]1100 {
[1625]1101 mr_conf->log_level = 4;
[296]1102 use_ntfsprog_hack = TRUE;
[1108]1103 mr_msg(2,
[296]1104 "Calling ntfsclone in background because %s is an NTFS /dev entry",
[128]1105 outfile_fname);
[1199]1106 mr_asprintf(&ntfsprog_fifo, "/tmp/%d.%d.000", (int) (random() % 32768),
[128]1107 (int) (random() % 32768));
[1199]1108 mkfifo(ntfsprog_fifo, 0x770);
1109
[296]1110 file_to_openout = ntfsprog_fifo;
[128]1111 switch (pid = fork()) {
1112 case -1:
1113 fatal_error("Fork failure");
1114 case 0:
[1108]1115 mr_msg(3,
[296]1116 "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)",
1117 biggiestruct.filename, ntfsprog_fifo);
[128]1118 res =
[296]1119 feed_outfrom_ntfsprog(biggiestruct.filename,
[1199]1120 ntfsprog_fifo);
[128]1121 exit(res);
1122 break;
1123 default:
[1108]1124 mr_msg(3,
[296]1125 "feed_into_ntfsprog() called in background --- pid=%ld",
[128]1126 (long int) (pid));
1127 }
1128 } else {
[296]1129 use_ntfsprog_hack = FALSE;
[128]1130 file_to_openout = outfile_fname;
1131 if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way
1132 {
1133 make_hole_for_file(outfile_fname);
1134 }
1135 }
[1]1136
[1199]1137 mr_msg(2, "Reassembling big file %ld (%s)", bigfileno + 1,
[128]1138 outfile_fname);
[1]1139
[128]1140 /*
1141 last slice is zero-length and uncompressed; when we find it, we stop.
1142 We DON'T wait until there are no more slices; if we did that,
1143 We might stop at end of CD, not at last slice (which is 0-len and uncompd)
1144 */
[1]1145
[128]1146 strncpy(pathname_of_last_file_restored, biggiestruct.filename,
1147 MAX_STR_LEN - 1);
1148 pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
[1]1149
[1108]1150 mr_msg(3, "file_to_openout = %s", file_to_openout);
[128]1151 if (!(fout = fopen(file_to_openout, "w"))) {
[1199]1152 log_to_screen(_("Cannot openout file_to_openout - hard disk full?"));
[128]1153 return (1);
[1]1154 }
[1199]1155
1156 mr_free(ntfsprog_fifo);
[1108]1157 mr_msg(3, "Opened out to %s", outfile_fname); // CD/DVD --> mondorestore --> ntfsclone --> hard disk itself
[1]1158
[128]1159 for (sliceno = 1, finished = FALSE; !finished;) {
1160 if (!does_file_exist
1161 (slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""))
1162 &&
1163 !does_file_exist(slice_fname
1164 (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))
1165 &&
1166 !does_file_exist(slice_fname
[1053]1167 (bigfileno, sliceno, ARCHIVES_PATH, "gz"))
1168 &&
1169 !does_file_exist(slice_fname
[128]1170 (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
[1108]1171 mr_msg(3,
[128]1172 "Cannot find a data slice or terminator slice on CD %d",
1173 g_current_media_number);
1174 g_current_media_number++;
[1199]1175 mr_msg(2, "Asking for %s #%d so that I may read slice #%ld\n",
[128]1176 media_descriptor_string(bkpinfo->backup_media_type),
1177 g_current_media_number, sliceno);
[1199]1178 log_to_screen(_("Restoring from %s #%d"),
1179 bkpinfo->backup_media_string,
[128]1180 g_current_media_number);
1181 insist_on_this_cd_number(bkpinfo, g_current_media_number);
[1199]1182 log_to_screen(_("Continuing to restore."));
[128]1183 } else {
[1199]1184 mr_asprintf(&tmp,
[128]1185 slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""));
1186 if (does_file_exist(tmp) && length_of_file(tmp) == 0) {
[1108]1187 mr_msg(2,
[128]1188 "End of bigfile # %ld (slice %ld is the terminator)",
1189 bigfileno + 1, sliceno);
1190 finished = TRUE;
[1199]1191 mr_free(tmp);
[128]1192 continue;
1193 } else {
[1199]1194 mr_free(tmp);
[128]1195 if (does_file_exist
1196 (slice_fname
1197 (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) {
[1199]1198 mr_asprintf(&bzip2_command, "lzop");
1199 mr_asprintf(&suffix, "lzo");
[128]1200 } else
1201 if (does_file_exist
1202 (slice_fname
[998]1203 (bigfileno, sliceno, ARCHIVES_PATH, "gz"))) {
[1199]1204 mr_asprintf(&bzip2_command, "gzip");
1205 mr_asprintf(&suffix, "gz");
[998]1206 } else
1207 if (does_file_exist
1208 (slice_fname
[128]1209 (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
[1199]1210 mr_asprintf(&bzip2_command, "bzip2");
1211 mr_asprintf(&suffix, "bz2");
[128]1212 } else
1213 if (does_file_exist
1214 (slice_fname
1215 (bigfileno, sliceno, ARCHIVES_PATH, ""))) {
[1199]1216 mr_asprintf(&bzip2_command, "");
1217 mr_asprintf(&suffix, "");
[128]1218 } else {
[1199]1219 log_to_screen(_("OK, that's pretty fsck0red..."));
[128]1220 return (1);
1221 }
1222 }
1223 if (bzip2_command[0] != '\0') {
[1199]1224 mr_strcat(bzip2_command,
[128]1225 " -dc %s 2>> %s",
1226 slice_fname(bigfileno, sliceno, ARCHIVES_PATH,
1227 suffix), MONDO_LOGFILE);
1228 } else {
[1199]1229 mr_free(bzip2_command);
1230 mr_asprintf(&bzip2_command, "cat %s 2>> %s",
[128]1231 slice_fname(bigfileno, sliceno, ARCHIVES_PATH,
1232 suffix), MONDO_LOGFILE);
1233 }
[1199]1234 mr_asprintf(&tmp, "Working on %s #%d, file #%ld, slice #%ld",
1235 bkpinfo->backup_media_string,
[128]1236 g_current_media_number, bigfileno + 1, sliceno);
[1108]1237 mr_msg(2, tmp);
[128]1238 if (!g_text_mode) {
1239 newtDrawRootText(0, g_noof_rows - 2, tmp);
1240 newtRefresh();
1241 update_progress_form(tmp);
1242 }
[1199]1243 mr_free(tmp);
1244
[128]1245 if (!(fbzip2 = popen(bzip2_command, "r"))) {
[1199]1246 mr_free(bzip2_command);
1247 mr_free(suffix);
[128]1248 fatal_error("Can't run popen command");
1249 }
[1199]1250 mr_free(bzip2_command);
1251 mr_free(suffix);
1252
[128]1253 while (!feof(fbzip2)) {
[1638]1254 siz = fread(bigblk, 1, mr_conf->external_tape_blocksize, fbzip2);
[128]1255 if (siz > 0) {
1256 siz = fwrite(bigblk, 1, siz, fout);
1257 }
1258 }
1259 paranoid_pclose(fbzip2);
[1]1260
[128]1261 sliceno++;
1262 g_current_progress++;
1263 }
1264 }
1265 paranoid_fclose(fout);
[1625]1266 mr_conf->log_level = old_loglevel;
[1]1267
[296]1268 if (use_ntfsprog_hack) {
[1108]1269 mr_msg(3, "Waiting for ntfsclone to finish");
[1199]1270 mr_asprintf(&tmp,
[433]1271 " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
[128]1272 while (system(tmp) == 0) {
1273 sleep(1);
1274 }
[1199]1275 mr_free(tmp);
[296]1276 log_it("OK, ntfsclone has really finished");
[128]1277 }
[1]1278
[128]1279 if (strcmp(outfile_fname, "/dev/null")) {
1280 chown(outfile_fname, biggiestruct.properties.st_uid,
1281 biggiestruct.properties.st_gid);
1282 chmod(outfile_fname, biggiestruct.properties.st_mode);
1283 ubuf->actime = biggiestruct.properties.st_atime;
1284 ubuf->modtime = biggiestruct.properties.st_mtime;
1285 utime(outfile_fname, ubuf);
1286 }
[1199]1287 mr_free(outfile_fname);
[1080]1288 mr_free(bigblk);
[1]1289
[128]1290 return (retval);
[1]1291}
1292
[1199]1293
[1]1294/**************************************************************************
1295 *END_ RESTORE_A_BIGGIEFILE_FROM_CD *
1296 **************************************************************************/
1297
1298
1299/**
1300 * Restore a biggiefile from the currently opened stream.
1301 * @param bkpinfo The backup information structure. Fields used:
1302 * - @c bkpinfo->restore_path
1303 * - @c bkpinfo->zip_exe
1304 * @param orig_bf_fname The original filename of the biggiefile.
1305 * @param biggiefile_number The number of the biggiefile (starting from 0).
1306 * @param filelist The node structure containing the list of files to be restored.
1307 * If @p orig_bf_fname is not in the list, it will be ignored.
1308 * @return 0 for success (or skip), nonzero for failure.
1309 */
[128]1310int restore_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo, char *orig_bf_fname, long biggiefile_number, char *orig_checksum, //UNUSED
1311 long long biggiefile_size, //UNUSED
1312 struct s_node *filelist,
[296]1313 int use_ntfsprog,
[128]1314 char *pathname_of_last_file_restored)
[1]1315{
[1199]1316 FILE *pout = NULL;
1317 FILE *fin = NULL;
[1]1318
1319 /** mallocs ********/
[1199]1320 char *tmp = NULL;
1321 char *tmp1 = NULL;
1322 char *command = NULL;
1323 char *outfile_fname = NULL;
1324 char *ntfsprog_fifo = NULL;
[128]1325 char *file_to_openout = NULL;
[1]1326
[1199]1327 struct s_node *node = NULL;
[1]1328
[1199]1329 int old_loglevel = 0;
[128]1330 long current_slice_number = 0;
1331 int retval = 0;
1332 int res = 0;
1333 int ctrl_chr = '\0';
[1199]1334 long long slice_siz = 0L;
[128]1335 bool dummy_restore = FALSE;
[296]1336 bool use_ntfsprog_hack = FALSE;
[128]1337 pid_t pid;
1338 struct s_filename_and_lstat_info biggiestruct;
[1199]1339 struct utimbuf the_utime_buf, *ubuf = NULL;
[128]1340 ubuf = &the_utime_buf;
[1]1341
[1625]1342 old_loglevel = mr_conf->log_level;
[128]1343 assert(bkpinfo != NULL);
1344 assert(orig_bf_fname != NULL);
1345 assert(orig_checksum != NULL);
[1]1346
[128]1347 pathname_of_last_file_restored[0] = '\0';
[296]1348 if (use_ntfsprog == BLK_START_A_PIHBIGGIE) {
1349 use_ntfsprog = 1;
[1108]1350 mr_msg(1, "%s --- pih=YES", orig_bf_fname);
[296]1351 } else if (use_ntfsprog == BLK_START_A_NORMBIGGIE) {
1352 use_ntfsprog = 0;
[1108]1353 mr_msg(1, "%s --- pih=NO", orig_bf_fname);
[128]1354 } else {
[296]1355 use_ntfsprog = 0;
[1108]1356 mr_msg(1, "%s --- pih=NO (weird marker though)", orig_bf_fname);
[128]1357 }
[1]1358
[128]1359 strncpy(pathname_of_last_file_restored, orig_bf_fname,
1360 MAX_STR_LEN - 1);
1361 pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
[1]1362
[128]1363 /* open out to biggiefile to be restored (or /dev/null if biggiefile is not to be restored) */
1364
1365 if (filelist != NULL) {
1366 node = find_string_at_node(filelist, orig_bf_fname);
1367 if (!node) {
1368 dummy_restore = TRUE;
[1108]1369 mr_msg(1,
[128]1370 "Skipping big file %ld (%s) - not in biggielist subset",
1371 biggiefile_number + 1, orig_bf_fname);
1372 pathname_of_last_file_restored[0] = '\0';
1373 } else if (!(node->selected)) {
1374 dummy_restore = TRUE;
[1108]1375 mr_msg(1, "Skipping %s (name isn't in biggielist subset)",
[128]1376 orig_bf_fname);
1377 pathname_of_last_file_restored[0] = '\0';
1378 }
[1]1379 }
1380
[296]1381 if (use_ntfsprog) {
[128]1382 if (strncmp(orig_bf_fname, "/dev/", 5)) {
[1199]1383 mr_msg(1, "I was in error when I set use_ntfsprog to TRUE.");
[1108]1384 mr_msg(1, "%s isn't even in /dev", orig_bf_fname);
[296]1385 use_ntfsprog = FALSE;
[128]1386 }
1387 }
[1]1388
[296]1389 if (use_ntfsprog) {
[1625]1390 mr_conf->log_level = 4;
[1199]1391 mr_asprintf(&outfile_fname, orig_bf_fname);
[296]1392 use_ntfsprog_hack = TRUE;
[1108]1393 mr_msg(2,
[296]1394 "Calling ntfsclone in background because %s is a /dev entry",
[128]1395 outfile_fname);
[1199]1396 mr_asprintf(&ntfsprog_fifo, "%s/%d.%d.000",
[812]1397 bkpinfo->tmpdir,
1398 (int) (random() % 32768),
[128]1399 (int) (random() % 32768));
[1199]1400 mkfifo(ntfsprog_fifo, 0x770);
1401
[296]1402 file_to_openout = ntfsprog_fifo;
[128]1403 switch (pid = fork()) {
1404 case -1:
1405 fatal_error("Fork failure");
1406 case 0:
[1108]1407 mr_msg(3,
[296]1408 "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)",
1409 outfile_fname, ntfsprog_fifo);
[1199]1410 res = feed_outfrom_ntfsprog(outfile_fname, ntfsprog_fifo);
[128]1411 exit(res);
1412 break;
1413 default:
[1108]1414 mr_msg(3,
[296]1415 "feed_into_ntfsprog() called in background --- pid=%ld",
[128]1416 (long int) (pid));
1417 }
1418 } else {
1419 if (!strncmp(orig_bf_fname, "/dev/", 5)) // non-NTFS partition
1420 {
[1199]1421 mr_asprintf(&outfile_fname, orig_bf_fname);
[128]1422 } else // biggiefile
1423 {
[1199]1424 mr_asprintf(&outfile_fname, "%s/%s", bkpinfo->restore_path,
[128]1425 orig_bf_fname);
1426 }
[296]1427 use_ntfsprog_hack = FALSE;
[128]1428 file_to_openout = outfile_fname;
1429 if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way
1430 {
1431 make_hole_for_file(outfile_fname);
1432 }
[1199]1433 mr_msg(2, "Reassembling big file %ld (%s)",
[128]1434 biggiefile_number + 1, orig_bf_fname);
[1]1435 }
[128]1436
1437 if (dummy_restore) {
[1199]1438 mr_free(outfile_fname);
1439 mr_asprintf(&outfile_fname, "/dev/null");
[1]1440 }
[128]1441
1442 if (!bkpinfo->zip_exe[0]) {
[1199]1443 mr_asprintf(&command, "cat > \"%s\"", file_to_openout);
[128]1444 } else {
[1199]1445 mr_asprintf(&command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe,
[128]1446 file_to_openout, MONDO_LOGFILE);
[1]1447 }
[1199]1448 mr_msg(3, "Pipe command = '%s'", command);
1449 mr_free(outfile_fname);
1450 mr_free(ntfsprog_fifo);
[1]1451
[128]1452 /* restore biggiefile, one slice at a time */
1453 if (!(pout = popen(command, "w"))) {
1454 fatal_error("Cannot pipe out");
1455 }
[1199]1456 mr_free(command);
1457
1458 malloc_string(tmp1);
1459 for (res = read_header_block_from_stream(&slice_siz, tmp1, &ctrl_chr);
[128]1460 ctrl_chr != BLK_STOP_A_BIGGIE;
[1199]1461 res = read_header_block_from_stream(&slice_siz, tmp1, &ctrl_chr)) {
[128]1462 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
1463 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
1464 }
[1199]1465 mr_asprintf(&tmp, "Working on file #%ld, slice #%ld ",
[128]1466 biggiefile_number + 1, current_slice_number);
[1108]1467 mr_msg(2, tmp);
[128]1468 if (!g_text_mode) {
1469 newtDrawRootText(0, g_noof_rows - 2, tmp);
1470 newtRefresh();
1471 }
[1168]1472 mr_strip_spaces(tmp);
[128]1473 update_progress_form(tmp);
[1199]1474 mr_free(tmp);
[128]1475 if (current_slice_number == 0) {
1476 res =
1477 read_file_from_stream_to_file(bkpinfo,
1478 "/tmp/biggie-blah.txt",
1479 slice_siz);
1480 if (!(fin = fopen("/tmp/biggie-blah.txt", "r"))) {
1481 log_OS_error("blah blah");
1482 } else {
1483 if (fread
1484 ((void *) &biggiestruct, 1, sizeof(biggiestruct),
1485 fin) < sizeof(biggiestruct)) {
[1108]1486 mr_msg(2,
[128]1487 "Warning - unable to get biggiestruct of bigfile #%d",
1488 biggiefile_number + 1);
1489 }
1490 paranoid_fclose(fin);
1491 }
1492 } else {
1493 res =
1494 read_file_from_stream_to_stream(bkpinfo, pout, slice_siz);
1495 }
1496 retval += res;
[1199]1497 res = read_header_block_from_stream(&slice_siz, tmp1, &ctrl_chr);
[128]1498 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
1499 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
1500 }
1501 current_slice_number++;
1502 g_current_progress++;
1503 }
[1199]1504 mr_free(tmp1);
[128]1505 paranoid_pclose(pout);
[1]1506
[1108]1507 mr_msg(1, "pathname_of_last_file_restored is now %s",
[128]1508 pathname_of_last_file_restored);
[1]1509
[296]1510 if (use_ntfsprog_hack) {
[1108]1511 mr_msg(3, "Waiting for ntfsclone to finish");
[1199]1512 mr_asprintf(&tmp,
[433]1513 " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
[128]1514 while (system(tmp) == 0) {
1515 sleep(1);
[1199]1516 }
1517 mr_free(tmp);
[1108]1518 mr_msg(3, "OK, ntfsclone has really finished");
[128]1519 }
1520
[1108]1521 mr_msg(3, "biggiestruct.filename = %s", biggiestruct.filename);
1522 mr_msg(3, "biggiestruct.checksum = %s", biggiestruct.checksum);
[128]1523 if (strcmp(outfile_fname, "/dev/null")) {
1524 chmod(outfile_fname, biggiestruct.properties.st_mode);
1525 chown(outfile_fname, biggiestruct.properties.st_uid,
1526 biggiestruct.properties.st_gid);
1527 ubuf->actime = biggiestruct.properties.st_atime;
1528 ubuf->modtime = biggiestruct.properties.st_mtime;
1529 utime(outfile_fname, ubuf);
1530 }
1531
[1625]1532 mr_conf->log_level = old_loglevel;
[128]1533 return (retval);
[1]1534}
1535
1536/**************************************************************************
1537 *END_RESTORE_A_BIGGIEFILE_FROM_STREAM *
1538 **************************************************************************/
1539
1540
1541/**
1542 * Restore @p tarball_fname from CD.
1543 * @param tarball_fname The filename of the tarball to restore (in /mnt/cdrom).
1544 * This will be used unmodified.
1545 * @param current_tarball_number The number (starting from 0) of the fileset
1546 * we're restoring now.
1547 * @param filelist The node structure containing the list of files to be
1548 * restored. If no file in the afioball is in this list, afio will still be
1549 * called, but nothing will be written.
1550 * @return 0 for success, nonzero for failure.
1551 */
1552int
1553restore_a_tarball_from_CD(char *tarball_fname,
[128]1554 long current_tarball_number,
[1170]1555 struct s_node *filelist, struct s_bkpinfo *bkpinfo)
[1]1556{
[128]1557 int retval = 0;
[1199]1558 int res = 0;
1559 char *p = NULL;
[1]1560
1561 /** malloc **/
[1199]1562 char *command = NULL;
1563 char *tmp = NULL;
1564 char *filelist_name = NULL;
1565 char *filelist_subset_fname = NULL;
1566 char *executable = NULL;
1567 char *temp_log = NULL;
[128]1568 long matches = 0;
[1199]1569 bool use_star = FALSE;
1570 char *xattr_fname = NULL;
1571 char *acl_fname = NULL;
[1638]1572#ifdef __FreeBSD__
1573 long BUFSIZE=512L;
1574#else
1575 long BUFSIZE=(1024L*1024L)/mr_conf->external_tape_blocksize;
1576#endif
[1]1577
[1638]1578
[128]1579 assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
1580
[1108]1581 mr_msg(5, "Entering");
[128]1582 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
[1199]1583 mr_asprintf(&command, "mkdir -p %s/tmp", MNT_RESTORING);
[128]1584 run_program_and_log_output(command, 9);
[1199]1585 mr_free(command);
[1]1586
[1199]1587 mr_asprintf(&filelist_name, MNT_CDROM "/archives/filelist.%ld",
[128]1588 current_tarball_number);
1589 if (length_of_file(filelist_name) <= 2) {
[1108]1590 mr_msg(2, "There are _zero_ files in filelist '%s'",
[128]1591 filelist_name);
[1108]1592 mr_msg(2,
[676]1593 "This is a bit silly (ask dev-team to fix mondo_makefilelist, please)");
[1108]1594 mr_msg(2,
[128]1595 "but it's non-critical. It's cosmetic. Don't worry about it.");
1596 retval = 0;
[1199]1597 mr_msg(5, "Leaving");
1598 mr_free(filelist_name);
1599 return (retval);
[1]1600 }
[128]1601 if (count_lines_in_file(filelist_name) <= 0
1602 || length_of_file(tarball_fname) <= 0) {
[1108]1603 mr_msg(3, "length_of_file(%s) = %llu", tarball_fname,
[128]1604 length_of_file(tarball_fname));
[1199]1605 log_to_screen(_("Unable to restore fileset #%ld (CD I/O error)"),
[128]1606 current_tarball_number);
1607 retval = 1;
[1199]1608 mr_msg(5, "Leaving");
1609 mr_free(filelist_name);
1610 return (retval);
[1]1611 }
1612
[128]1613 if (filelist) {
[1199]1614 mr_asprintf(&filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp",
[128]1615 current_tarball_number);
1616 if ((matches =
1617 save_filelist_entries_in_common(filelist_name, filelist,
1618 filelist_subset_fname,
1619 use_star))
1620 <= 0) {
[1199]1621 mr_msg(1, "Skipping fileset %ld", current_tarball_number);
[128]1622 } else {
[1108]1623 mr_msg(3, "Saved fileset %ld's subset to %s",
[128]1624 current_tarball_number, filelist_subset_fname);
1625 }
[1199]1626 log_to_screen("Tarball #%ld --- %ld matches",
[128]1627 current_tarball_number, matches);
1628 }
[1199]1629 mr_free(filelist_name);
[128]1630
1631 if (filelist == NULL || matches > 0) {
[948]1632 if (g_getfattr) {
[1199]1633 mr_asprintf(&xattr_fname, XATTR_LIST_FNAME_RAW_SZ,
[128]1634 MNT_CDROM "/archives", current_tarball_number);
[948]1635 }
1636 if (g_getfacl) {
[1199]1637 mr_asprintf(&acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives",
[128]1638 current_tarball_number);
[948]1639 }
[128]1640 if (strstr(tarball_fname, ".bz2")) {
[1199]1641 mr_asprintf(&executable, "-P bzip2 -Z");
[998]1642 } else if (strstr(tarball_fname, ".gz")) {
[1199]1643 mr_asprintf(&executable, "-P gzip -Z");
[128]1644 } else if (strstr(tarball_fname, ".lzo")) {
[1199]1645 mr_asprintf(&executable, "-P lzop -Z");
[128]1646 }
[1199]1647
1648 if (executable == NULL) {
1649 mr_asprintf(&tmp, "which %s > /dev/null 2> /dev/null", executable);
[128]1650 if (run_program_and_log_output(tmp, FALSE)) {
1651 log_to_screen
[1203]1652 (_("(compare_a_tarball) Compression program not found - oh no!"));
[1199]1653 mr_free(tmp);
1654 mr_free(executable);
1655 mr_free(acl_fname);
1656 mr_free(xattr_fname);
1657 mr_free(filelist_subset_fname);
[128]1658 paranoid_MR_finish(1);
1659 }
[1199]1660 mr_free(tmp);
[128]1661 }
1662 if (use_star) {
[1211]1663 mr_asprintf(&command,
[128]1664 "star -x -force-remove -U " STAR_ACL_SZ
1665 " errctl= file=%s", tarball_fname);
1666 if (strstr(tarball_fname, ".bz2")) {
[1199]1667 mr_strcat(command, " -bz");
[128]1668 }
1669 } else {
[1199]1670 if (filelist_subset_fname != NULL) {
1671 mr_asprintf(&command,
[543]1672 "afio -i -M 8m -b %ld -c %ld %s -w '%s' %s",
[1638]1673 mr_conf->external_tape_blocksize,
[128]1674 BUFSIZE, executable, filelist_subset_fname,
1675 tarball_fname);
1676 } else {
[1199]1677 mr_asprintf(&command,
[128]1678 "afio -i -b %ld -c %ld -M 8m %s %s",
[1638]1679 mr_conf->external_tape_blocksize,
[128]1680 BUFSIZE, executable, tarball_fname);
1681 }
1682 }
[1199]1683 mr_free(executable);
1684
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;
[1638]1845 mr_asprintf(&command, "afio -t -M 8m -b %ld %s %s", mr_conf->external_tape_blocksize,
[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) {
[1638]1887 mr_asprintf(&command, "afio -i -M 8m -b %ld %s -w %s %s 2>> %s", mr_conf->external_tape_blocksize, executable, filelist_subset_fname, afio_fname, MONDO_LOGFILE);
[1199]1888 } else {
[1638]1889 mr_asprintf(&command, "afio -i -M 8m -b %ld %s %s 2>> %s", mr_conf->external_tape_blocksize, 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) {
[1628]3049 mr_allocstr(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.