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

Last change on this file since 729 was 689, checked in by bcornec, 18 years ago

Still other memory management improvements ( I hope :-)

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