source: MondoRescue/branches/2.2.6/mondo/src/mondorestore/mondorestore.c@ 1969

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