source: MondoRescue/branches/3.3/mondo/src/mondorestore/mondorestore.c@ 3862

Last change on this file since 3862 was 3862, checked in by Bruno Cornec, 3 months ago

Remove useless find_pathname_of_executable_preferably_in_RESTORING

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