source: MondoRescue/trunk/mondo/src/mondorestore/mondo-restore.c@ 970

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

typo in trunk

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