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