source: MondoRescue/branches/2.2.5/mondo/src/mondorestore/mondo-restore.c@ 1579

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

Remove the useless modify_rclocal_one_time

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