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