source: MondoRescue/branches/stable/mondo/src/mondorestore/mondorestore.c@ 1239

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

For tape restore, there was a blocking situation where mondorestore tried to eject a CD when it's useless. (Patch provided by Benoit Donnette <bdonnette_at_linagora.com>)

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