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