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