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