source: MondoRescue/branches/3.0/mondo/src/mondorestore/mondorestore.c@ 3152

Last change on this file since 3152 was 3145, checked in by Bruno Cornec, 11 years ago

r5361@localhost: bruno | 2013-06-14 12:18:21 +0200

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