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