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

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

Fix some linking errors in trunk

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