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