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

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

merge -r1045:1078 £SVN_M/branches/stable

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