source: MondoRescue/trunk/mondo/src/mondorestore/mondorestore.c@ 2009

Last change on this file since 2009 was 2009, checked in by Bruno Cornec, 16 years ago

Commit ald modifs in trunk - just in case

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