source: MondoRescue/branches/2.2.10/mondo/src/mondorestore/mondorestore.c@ 2644

Last change on this file since 2644 was 2623, checked in by Bruno Cornec, 14 years ago

r3783@localhost: bruno | 2010-04-11 11:57:27 +0200

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