[1] | 1 | /***************************************************************************
|
---|
[1080] | 2 | * restores mondoarchive data
|
---|
| 3 | * $Id: mondorestore.c 1199 2007-02-24 23:43:27Z bruno $
|
---|
[1] | 4 | ***************************************************************************/
|
---|
| 5 |
|
---|
| 6 | /**
|
---|
| 7 | * @file
|
---|
| 8 | * The main file for mondorestore.
|
---|
| 9 | */
|
---|
| 10 |
|
---|
| 11 | /**************************************************************************
|
---|
| 12 | * #include statements *
|
---|
| 13 | **************************************************************************/
|
---|
[1199] | 14 | #include <unistd.h>
|
---|
| 15 |
|
---|
[1067] | 16 | #include "my-stuff.h"
|
---|
[1168] | 17 | #include "mr_mem.h"
|
---|
| 18 | #include "mr_msg.h"
|
---|
| 19 | #include "mr_str.h"
|
---|
| 20 |
|
---|
| 21 | #include "mondostructures.h"
|
---|
| 22 | #include "libmondo.h"
|
---|
[1] | 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 |
|
---|
[128] | 37 | //static char cvsid[] = "$Id: mondorestore.c 1199 2007-02-24 23:43:27Z bruno $";
|
---|
[1] | 38 |
|
---|
| 39 | /**************************************************************************
|
---|
| 40 | * Globals *
|
---|
| 41 | **************************************************************************/
|
---|
[128] | 42 | extern char *g_tmpfs_mountpt; // declared in libmondo-tools.c
|
---|
[1] | 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 | */
|
---|
[128] | 61 | bool g_sigpipe_caught = FALSE;
|
---|
[1] | 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 | */
|
---|
[128] | 67 | bool g_ISO_restore_mode = FALSE; /* are we in Iso Mode? */
|
---|
[1] | 68 |
|
---|
| 69 | /**
|
---|
| 70 | * If TRUE, then we have had a successful "nuke" restore.
|
---|
| 71 | */
|
---|
[128] | 72 | bool g_I_have_just_nuked = FALSE;
|
---|
[1] | 73 |
|
---|
| 74 | /**
|
---|
| 75 | * The device to mount to get at the ISO images. Ignored unless @p g_ISO_restore_mode.
|
---|
| 76 | */
|
---|
[1199] | 77 | char *g_isodir_device = NULL;
|
---|
[1] | 78 |
|
---|
| 79 | /**
|
---|
| 80 | * The format of @p g_isodir_device. Ignored unless @p g_ISO_restore_mode.
|
---|
| 81 | */
|
---|
[1199] | 82 | char *g_isodir_format = NULL;
|
---|
[1] | 83 |
|
---|
| 84 | /**
|
---|
| 85 | * The location of 'biggielist.txt', containing the biggiefiles on the current archive set.
|
---|
| 86 | */
|
---|
[1199] | 87 | char *g_biggielist_txt = NULL;
|
---|
[1] | 88 |
|
---|
| 89 | /**
|
---|
| 90 | * The location of 'filelist.full', containing all files (<em>including biggiefiles</em>) on
|
---|
| 91 | * the current archive set.
|
---|
| 92 | */
|
---|
[1199] | 93 | char *g_filelist_full = NULL;
|
---|
[1] | 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 | */
|
---|
[1199] | 99 | char *g_filelist_imagedevs = NULL;
|
---|
[1] | 100 |
|
---|
| 101 | /**
|
---|
| 102 | * The location of a file containing a list of imagedevs to actually restore.
|
---|
| 103 | * @see g_filelist_imagedevs
|
---|
| 104 | */
|
---|
[1199] | 105 | char *g_imagedevs_restthese = NULL;
|
---|
[1] | 106 |
|
---|
| 107 | /**
|
---|
| 108 | * The location of 'mondo-restore.cfg', containing the metadata
|
---|
| 109 | * information for this backup.
|
---|
| 110 | */
|
---|
[1199] | 111 | char *g_mondo_cfg_file = NULL;
|
---|
[1] | 112 |
|
---|
| 113 | /**
|
---|
| 114 | * The location of 'mountlist.txt', containing the information on the
|
---|
| 115 | * user's partitions and hard drives.
|
---|
| 116 | */
|
---|
[1199] | 117 | char *g_mountlist_fname = NULL;
|
---|
[1] | 118 |
|
---|
| 119 | /**
|
---|
| 120 | * Mondo's home directory during backup. Unused in mondo-restore; included
|
---|
| 121 | * to avoid link errors.
|
---|
| 122 | */
|
---|
[1199] | 123 | char *g_mondo_home = NULL;
|
---|
[1] | 124 |
|
---|
[928] | 125 | /* Busybox ps has no option and PID in first pos */
|
---|
[792] | 126 | char *ps_options = "";
|
---|
[928] | 127 | char *ps_proc_id = "$1";
|
---|
[792] | 128 |
|
---|
[952] | 129 | extern char *g_getfacl;
|
---|
| 130 | extern char *g_getfattr;
|
---|
[946] | 131 |
|
---|
[1] | 132 | /* @} - end of "Restore-Time Globals" in globalGroup */
|
---|
| 133 |
|
---|
[128] | 134 | extern int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived,
|
---|
| 135 | char direction);
|
---|
[1] | 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 | */
|
---|
[1199] | 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.")
|
---|
[1] | 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 | */
|
---|
[128] | 155 | int let_user_edit_the_mountlist(struct s_bkpinfo *bkpinfo,
|
---|
| 156 | struct mountlist_itself *mountlist,
|
---|
| 157 | struct raidlist_itself *raidlist)
|
---|
[1] | 158 | {
|
---|
[128] | 159 | int retval = 0, res = 0;
|
---|
[1] | 160 |
|
---|
[1108] | 161 | mr_msg(2, "let_user_edit_the_mountlist() --- starting");
|
---|
[1] | 162 |
|
---|
[128] | 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");
|
---|
[1108] | 168 | mr_msg(2, "I guess you're testing edit_mountlist()");
|
---|
[1] | 169 | }
|
---|
[128] | 170 | if (!does_file_exist(g_mountlist_fname)) {
|
---|
| 171 | log_to_screen(g_mountlist_fname);
|
---|
[1199] | 172 | log_to_screen(_("does not exist"));
|
---|
[128] | 173 | return (1);
|
---|
| 174 | }
|
---|
[1] | 175 |
|
---|
[128] | 176 | retval = load_mountlist(mountlist, g_mountlist_fname);
|
---|
| 177 | load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
|
---|
| 178 | if (retval) {
|
---|
| 179 | log_to_screen
|
---|
[1199] | 180 | (_("Warning - load_raidtab_into_raidlist returned an error"));
|
---|
[128] | 181 | }
|
---|
| 182 | res = edit_mountlist(g_mountlist_fname, mountlist, raidlist);
|
---|
| 183 | if (res) {
|
---|
| 184 | return (1);
|
---|
| 185 | }
|
---|
[1] | 186 |
|
---|
[128] | 187 | save_mountlist_to_disk(mountlist, g_mountlist_fname);
|
---|
| 188 | save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
|
---|
[1] | 189 |
|
---|
[1199] | 190 | log_to_screen(_("I have finished editing the mountlist for you."));
|
---|
[1] | 191 |
|
---|
[128] | 192 | return (retval);
|
---|
| 193 | }
|
---|
[1] | 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 | */
|
---|
[128] | 202 | bool
|
---|
| 203 | partition_table_contains_Compaq_diagnostic_partition(struct
|
---|
| 204 | mountlist_itself *
|
---|
| 205 | mountlist)
|
---|
[1] | 206 | {
|
---|
[128] | 207 | int i;
|
---|
[1] | 208 |
|
---|
[128] | 209 | assert(mountlist != NULL);
|
---|
[1] | 210 |
|
---|
[128] | 211 | for (i = 0; i < mountlist->entries; i++) {
|
---|
| 212 | if (strstr(mountlist->el[i].format, "ompaq")) {
|
---|
[1108] | 213 | mr_msg(2, "mountlist[%d] (%s) is %s (Compaq alert!)",
|
---|
[128] | 214 | i, mountlist->el[i].device, mountlist->el[i].format);
|
---|
| 215 |
|
---|
| 216 | return (TRUE);
|
---|
| 217 | }
|
---|
[1] | 218 | }
|
---|
[128] | 219 | return (FALSE);
|
---|
[1] | 220 | }
|
---|
[128] | 221 |
|
---|
[1] | 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 | */
|
---|
[128] | 232 | void offer_to_abort_because_Compaq_Proliants_suck(void)
|
---|
[1] | 233 | {
|
---|
[128] | 234 | popup_and_OK(COMPAQ_PROLIANTS_SUCK);
|
---|
| 235 | if (ask_me_yes_or_no
|
---|
[1199] | 236 | (_
|
---|
| 237 | ("Would you like to reboot and use your Compaq CD to prep your hard drive?")))
|
---|
[128] | 238 | {
|
---|
[1199] | 239 | fatal_error(_
|
---|
| 240 | ("Aborting. Please reboot and prep your hard drive with your Compaq CD."));
|
---|
[128] | 241 | }
|
---|
[1] | 242 | }
|
---|
[128] | 243 |
|
---|
[1] | 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 | */
|
---|
[128] | 257 | int
|
---|
| 258 | catchall_mode(struct s_bkpinfo *bkpinfo,
|
---|
| 259 | struct mountlist_itself *mountlist,
|
---|
| 260 | struct raidlist_itself *raidlist)
|
---|
[1] | 261 | {
|
---|
[128] | 262 | char c, *tmp;
|
---|
| 263 | int retval = 0;
|
---|
[1] | 264 |
|
---|
[128] | 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 {
|
---|
[1199] | 275 | popup_and_OK(_
|
---|
| 276 | ("No restoring or comparing will take place today."));
|
---|
[128] | 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) {
|
---|
[1199] | 281 | mr_asprintf(&tmp, "umount %s", bkpinfo->isodir);
|
---|
[128] | 282 | run_program_and_log_output(tmp, FALSE);
|
---|
[1199] | 283 | mr_free(tmp);
|
---|
[128] | 284 | }
|
---|
| 285 | paranoid_MR_finish(0);
|
---|
[1] | 286 | }
|
---|
| 287 |
|
---|
[128] | 288 | iamhere("post int");
|
---|
[1] | 289 |
|
---|
[128] | 290 | if (bkpinfo->backup_media_type == iso) {
|
---|
| 291 | if (iso_fiddly_bits(bkpinfo, (c == 'N') ? TRUE : FALSE)) {
|
---|
[1108] | 292 | mr_msg(2,
|
---|
[128] | 293 | "catchall_mode --- iso_fiddly_bits returned w/ error");
|
---|
| 294 | return (1);
|
---|
| 295 | } else {
|
---|
[1108] | 296 | mr_msg(2, "catchall_mode --- iso_fiddly_bits ok");
|
---|
[128] | 297 | }
|
---|
| 298 | }
|
---|
[1] | 299 |
|
---|
[128] | 300 | if (c == 'I') {
|
---|
[1108] | 301 | mr_msg(2, "IM selected");
|
---|
[128] | 302 | retval += interactive_mode(bkpinfo, mountlist, raidlist);
|
---|
| 303 | } else if (c == 'N') {
|
---|
[1108] | 304 | mr_msg(2, "NM selected");
|
---|
[128] | 305 | retval += nuke_mode(bkpinfo, mountlist, raidlist);
|
---|
| 306 | } else if (c == 'C') {
|
---|
[1108] | 307 | mr_msg(2, "CM selected");
|
---|
[128] | 308 | retval += compare_mode(bkpinfo, mountlist, raidlist);
|
---|
| 309 | }
|
---|
| 310 | return (retval);
|
---|
[1] | 311 | }
|
---|
[128] | 312 |
|
---|
[1] | 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 | */
|
---|
[128] | 335 | int
|
---|
| 336 | interactive_mode(struct s_bkpinfo *bkpinfo,
|
---|
| 337 | struct mountlist_itself *mountlist,
|
---|
| 338 | struct raidlist_itself *raidlist)
|
---|
[1] | 339 | {
|
---|
[128] | 340 | int retval = 0;
|
---|
| 341 | int res;
|
---|
| 342 | int ptn_errs = 0;
|
---|
| 343 | int fmt_errs = 0;
|
---|
[1] | 344 |
|
---|
[128] | 345 | bool done;
|
---|
| 346 | bool restore_all;
|
---|
[1] | 347 |
|
---|
[1199] | 348 | char *tmp = NULL;
|
---|
| 349 | char *tmp1 = NULL;
|
---|
| 350 | char *fstab_fname = NULL;
|
---|
| 351 | char *old_restpath = NULL;
|
---|
[1] | 352 |
|
---|
[1199] | 353 | struct s_node *filelist = NULL;
|
---|
[1] | 354 |
|
---|
[128] | 355 | /* try to partition and format */
|
---|
[1] | 356 |
|
---|
[1108] | 357 | mr_msg(2, "interactive_mode --- starting (great, assertions OK)");
|
---|
[1] | 358 |
|
---|
[128] | 359 | assert(bkpinfo != NULL);
|
---|
| 360 | assert(mountlist != NULL);
|
---|
| 361 | assert(raidlist != NULL);
|
---|
[1] | 362 |
|
---|
[1108] | 363 | mr_msg(2, "interactive_mode --- assertions OK");
|
---|
[1] | 364 |
|
---|
[128] | 365 | if (g_text_mode) {
|
---|
| 366 | if (!ask_me_yes_or_no
|
---|
[1199] | 367 | (_
|
---|
| 368 | ("Interactive Mode + textonly = experimental! Proceed anyway?")))
|
---|
[128] | 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");
|
---|
[1] | 378 | #ifdef __FreeBSD__
|
---|
[128] | 379 | if (strstr
|
---|
| 380 | (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
|
---|
| 381 | "noresize"))
|
---|
[1] | 382 | #else
|
---|
[128] | 383 | if (strstr
|
---|
| 384 | (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
|
---|
| 385 | "noresize"))
|
---|
[1] | 386 | #endif
|
---|
[128] | 387 | {
|
---|
[1108] | 388 | mr_msg(1, "Not resizing mountlist.");
|
---|
[128] | 389 | } else {
|
---|
| 390 | resize_mountlist_proportionately_to_suit_new_drives(mountlist);
|
---|
[1] | 391 | }
|
---|
[128] | 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);
|
---|
[1199] | 396 | mr_asprintf(&tmp, "%s %s", find_my_editor(), g_mountlist_fname);
|
---|
[128] | 397 | res = system(tmp);
|
---|
[1199] | 398 | mr_free(tmp);
|
---|
[128] | 399 | load_mountlist(mountlist, g_mountlist_fname);
|
---|
| 400 | } else {
|
---|
| 401 | res = edit_mountlist(g_mountlist_fname, mountlist, raidlist);
|
---|
[1] | 402 | }
|
---|
[128] | 403 | iamhere("Finished editing mountlist");
|
---|
| 404 | if (res) {
|
---|
| 405 | paranoid_MR_finish(1);
|
---|
[1] | 406 | }
|
---|
[1108] | 407 | mr_msg(2, "Proceeding...");
|
---|
[128] | 408 | save_mountlist_to_disk(mountlist, g_mountlist_fname);
|
---|
| 409 | save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
|
---|
[1199] | 410 | mvaddstr_and_log_it(1, 30, _("Restoring Interactively"));
|
---|
[128] | 411 | if (bkpinfo->differential) {
|
---|
[1199] | 412 | log_to_screen(_
|
---|
| 413 | ("Because this is a differential backup, disk"));
|
---|
| 414 | log_to_screen(_
|
---|
| 415 | (" partitioning and formatting will not take place."));
|
---|
[128] | 416 | done = TRUE;
|
---|
| 417 | } else {
|
---|
| 418 | if (ask_me_yes_or_no
|
---|
[1199] | 419 | (_
|
---|
| 420 | ("Do you want to erase and partition your hard drives?")))
|
---|
| 421 | {
|
---|
[128] | 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
|
---|
[1199] | 432 | (_
|
---|
| 433 | ("Warning. Errors occurred during disk partitioning."));
|
---|
[128] | 434 | }
|
---|
[1] | 435 |
|
---|
[558] | 436 | fmt_errs = format_everything(mountlist, FALSE, raidlist);
|
---|
[128] | 437 | if (!fmt_errs) {
|
---|
| 438 | log_to_screen
|
---|
[1199] | 439 | (_
|
---|
| 440 | ("Errors during disk partitioning were handled OK."));
|
---|
| 441 | log_to_screen(_
|
---|
| 442 | ("Partitions were formatted OK despite those errors."));
|
---|
[128] | 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,
|
---|
[1199] | 452 | _
|
---|
| 453 | ("User opted not to partition the devices"));
|
---|
[128] | 454 | if (ask_me_yes_or_no
|
---|
[1199] | 455 | (_("Do you want to format your hard drives?"))) {
|
---|
| 456 | fmt_errs =
|
---|
| 457 | format_everything(mountlist, TRUE, raidlist);
|
---|
[128] | 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,
|
---|
[1199] | 469 | _
|
---|
| 470 | ("Errors occurred. Please repartition and format drives manually."));
|
---|
[128] | 471 | done = FALSE;
|
---|
| 472 | }
|
---|
| 473 | if (ptn_errs & !fmt_errs) {
|
---|
| 474 | mvaddstr_and_log_it(g_currentY++,
|
---|
| 475 | 0,
|
---|
[1199] | 476 | _
|
---|
| 477 | ("Errors occurred during partitioning. Formatting, however, went OK."));
|
---|
[128] | 478 | done = TRUE;
|
---|
| 479 | }
|
---|
| 480 | if (!done) {
|
---|
[1199] | 481 | if (!ask_me_yes_or_no(_("Re-edit the mountlist?"))) {
|
---|
[128] | 482 | retval++;
|
---|
[1199] | 483 | iamhere("Leaving interactive_mode()");
|
---|
| 484 | return (retval);
|
---|
[128] | 485 | }
|
---|
| 486 | }
|
---|
[1] | 487 | }
|
---|
| 488 | }
|
---|
| 489 |
|
---|
[128] | 490 | /* mount */
|
---|
| 491 | if (mount_all_devices(mountlist, TRUE)) {
|
---|
| 492 | unmount_all_devices(mountlist);
|
---|
| 493 | retval++;
|
---|
[1199] | 494 | iamhere("Leaving interactive_mode()");
|
---|
| 495 | return (retval);
|
---|
[1] | 496 | }
|
---|
[128] | 497 | /* restore */
|
---|
| 498 | if ((restore_all =
|
---|
[1199] | 499 | ask_me_yes_or_no(_
|
---|
| 500 | ("Do you want me to restore all of your data?"))))
|
---|
[1] | 501 | {
|
---|
[1108] | 502 | mr_msg(1, "Restoring all data");
|
---|
[128] | 503 | retval += restore_everything(bkpinfo, NULL);
|
---|
[1199] | 504 | } else if ((restore_all =
|
---|
[128] | 505 | ask_me_yes_or_no
|
---|
[1199] | 506 | (_("Do you want me to restore _some_ of your data?")))) {
|
---|
| 507 | mr_asprintf(&old_restpath,bkpinfo->restore_path);
|
---|
[128] | 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) {
|
---|
[1199] | 515 | malloc_string(tmp1);
|
---|
[128] | 516 | gotos_suck:
|
---|
[1199] | 517 | strcpy(tmp1, old_restpath);
|
---|
| 518 | // (NB: MNT_RESTORING is where your filesystem is mounted now, by default)
|
---|
[128] | 519 | if (popup_and_get_string
|
---|
[1199] | 520 | (_("Restore path"), _("Restore files to where?"), tmp1,
|
---|
[128] | 521 | MAX_STR_LEN / 4)) {
|
---|
[1199] | 522 | if (!strcmp(tmp1, "/")) {
|
---|
| 523 | if (!ask_me_yes_or_no(_("Are you sure?"))) {
|
---|
[128] | 524 | goto gotos_suck;
|
---|
| 525 | }
|
---|
[1199] | 526 | tmp1[0] = '\0'; // so we restore to [blank]/file/name :)
|
---|
[128] | 527 | }
|
---|
[1199] | 528 | strcpy(bkpinfo->restore_path, tmp1);
|
---|
[1108] | 529 | mr_msg(1, "Restoring subset");
|
---|
[128] | 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
|
---|
[1199] | 537 | (_("Restore another subset of your backup?"))) {
|
---|
[128] | 538 | done = TRUE;
|
---|
| 539 | }
|
---|
[1199] | 540 | mr_free(tmp1);
|
---|
[128] | 541 | } else {
|
---|
| 542 | done = TRUE;
|
---|
| 543 | }
|
---|
| 544 | }
|
---|
[1199] | 545 | mr_free(old_restpath);
|
---|
[128] | 546 | } else {
|
---|
| 547 | mvaddstr_and_log_it(g_currentY++,
|
---|
| 548 | 0,
|
---|
[1199] | 549 | _
|
---|
| 550 | ("User opted not to restore any data. "));
|
---|
[1] | 551 | }
|
---|
[128] | 552 | if (retval) {
|
---|
| 553 | mvaddstr_and_log_it(g_currentY++,
|
---|
| 554 | 0,
|
---|
[1199] | 555 | _
|
---|
| 556 | ("Errors occurred during the restore phase. "));
|
---|
[1] | 557 | }
|
---|
| 558 |
|
---|
[1199] | 559 | if (ask_me_yes_or_no(_("Initialize the boot loader?"))) {
|
---|
[128] | 560 | run_boot_loader(TRUE);
|
---|
| 561 | } else {
|
---|
| 562 | mvaddstr_and_log_it(g_currentY++,
|
---|
| 563 | 0,
|
---|
[1199] | 564 | _
|
---|
| 565 | ("User opted not to initialize the boot loader."));
|
---|
[128] | 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
|
---|
[1199] | 572 | (_("Label your ext2 and ext3 partitions if necessary?"))) {
|
---|
[128] | 573 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
[1199] | 574 | _
|
---|
| 575 | ("Using e2label to label your ext2,3 partitions"));
|
---|
[128] | 576 | if (does_file_exist("/tmp/fstab.new")) {
|
---|
[1199] | 577 | mr_asprintf(&fstab_fname, "/tmp/fstab.new");
|
---|
[128] | 578 | } else {
|
---|
[1199] | 579 | mr_asprintf(&fstab_fname, "/tmp/fstab");
|
---|
[128] | 580 | }
|
---|
[1199] | 581 | mr_asprintf(&tmp,
|
---|
[128] | 582 | "label-partitions-as-necessary %s < %s >> %s 2>> %s",
|
---|
| 583 | g_mountlist_fname, fstab_fname, MONDO_LOGFILE,
|
---|
| 584 | MONDO_LOGFILE);
|
---|
[1199] | 585 | mr_free(fstab_fname);
|
---|
| 586 |
|
---|
[128] | 587 | res = system(tmp);
|
---|
[1199] | 588 | mr_free(tmp);
|
---|
[128] | 589 | if (res) {
|
---|
| 590 | log_to_screen
|
---|
[1199] | 591 | (_("label-partitions-as-necessary returned an error"));
|
---|
| 592 | mvaddstr_and_log_it(g_currentY++, 74, _("Failed."));
|
---|
[128] | 593 | } else {
|
---|
[1199] | 594 | mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
|
---|
[128] | 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,
|
---|
[1199] | 603 | _
|
---|
| 604 | ("Warning - errors occurred during the restore phase."));
|
---|
[128] | 605 | }
|
---|
| 606 | iamhere("Leaving interactive_mode()");
|
---|
[1199] | 607 | return(retval);
|
---|
[1] | 608 | }
|
---|
[128] | 609 |
|
---|
[1] | 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 | */
|
---|
[128] | 624 | int
|
---|
| 625 | iso_mode(struct s_bkpinfo *bkpinfo,
|
---|
| 626 | struct mountlist_itself *mountlist,
|
---|
| 627 | struct raidlist_itself *raidlist, bool nuke_me_please)
|
---|
[1] | 628 | {
|
---|
[1199] | 629 | char c = ' ';
|
---|
[128] | 630 | int retval = 0;
|
---|
[1] | 631 |
|
---|
[128] | 632 | assert(bkpinfo != NULL);
|
---|
| 633 | assert(mountlist != NULL);
|
---|
| 634 | assert(raidlist != NULL);
|
---|
| 635 | if (iso_fiddly_bits(bkpinfo, nuke_me_please)) {
|
---|
[1108] | 636 | mr_msg(1, "iso_mode --- returning w/ error");
|
---|
[128] | 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 {
|
---|
[1199] | 651 | log_to_screen(_("OK, I shan't restore/compare any files."));
|
---|
[128] | 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
|
---|
[1199] | 659 | (_
|
---|
| 660 | ("WARNING - unable to unmount device where the ISO files are stored."));
|
---|
[128] | 661 | }
|
---|
| 662 | return (retval);
|
---|
[1] | 663 | }
|
---|
[128] | 664 |
|
---|
[1] | 665 | /**************************************************************************
|
---|
| 666 | *END_ISO_MODE *
|
---|
| 667 | **************************************************************************/
|
---|
[1199] | 668 | static void call_me_after_the_nuke(int retval) {
|
---|
[1] | 669 |
|
---|
[1199] | 670 | char *tmp = NULL;
|
---|
| 671 | char *tmp1 = NULL;
|
---|
[1] | 672 |
|
---|
[1199] | 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 | }
|
---|
[1] | 693 |
|
---|
[1199] | 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 | }
|
---|
[1] | 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 | */
|
---|
[128] | 715 | int
|
---|
| 716 | nuke_mode(struct s_bkpinfo *bkpinfo,
|
---|
| 717 | struct mountlist_itself *mountlist,
|
---|
| 718 | struct raidlist_itself *raidlist)
|
---|
[1] | 719 | {
|
---|
[128] | 720 | int retval = 0;
|
---|
| 721 | int res = 0;
|
---|
| 722 | bool boot_loader_installed = FALSE;
|
---|
[1199] | 723 | char *tmp = NULL;
|
---|
| 724 | char tmpA[MAX_STR_LEN], tmpB[MAX_STR_LEN],
|
---|
[128] | 725 | tmpC[MAX_STR_LEN];
|
---|
[1] | 726 |
|
---|
[128] | 727 | assert(bkpinfo != NULL);
|
---|
| 728 | assert(mountlist != NULL);
|
---|
| 729 | assert(raidlist != NULL);
|
---|
[1] | 730 |
|
---|
[1108] | 731 | mr_msg(2, "nuke_mode --- starting");
|
---|
[1] | 732 |
|
---|
[128] | 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
|
---|
[1] | 735 | #ifdef __FreeBSD__
|
---|
[1199] | 736 | tmp = call_program_and_get_last_line_of_output("cat /tmp/cmdline");
|
---|
[1] | 737 | #else
|
---|
[1199] | 738 | tmp = call_program_and_get_last_line_of_output("cat /proc/cmdline");
|
---|
[1] | 739 | #endif
|
---|
[1199] | 740 | if (strstr(tmp,"noresize")) {
|
---|
[1108] | 741 | mr_msg(2, "Not resizing mountlist.");
|
---|
[128] | 742 | } else {
|
---|
| 743 | resize_mountlist_proportionately_to_suit_new_drives(mountlist);
|
---|
[1] | 744 | }
|
---|
[128] | 745 | if (!evaluate_mountlist(mountlist, tmpA, tmpB, tmpC)) {
|
---|
[1199] | 746 | mr_asprintf(&tmp,
|
---|
| 747 | _
|
---|
| 748 | ("Mountlist analyzed. Result: \"%s %s %s\" Switch to Interactive Mode?"),
|
---|
[128] | 749 | tmpA, tmpB, tmpC);
|
---|
| 750 | if (ask_me_yes_or_no(tmp)) {
|
---|
[1199] | 751 | mr_free(tmp);
|
---|
[128] | 752 | retval = interactive_mode(bkpinfo, mountlist, raidlist);
|
---|
[1199] | 753 | call_me_after_the_nuke(retval);
|
---|
| 754 | return(retval);
|
---|
[128] | 755 | } else {
|
---|
[1199] | 756 | mr_free(tmp);
|
---|
[128] | 757 | fatal_error("Nuke Mode aborted. ");
|
---|
| 758 | }
|
---|
[1] | 759 | }
|
---|
[128] | 760 | save_mountlist_to_disk(mountlist, g_mountlist_fname);
|
---|
[1199] | 761 | mvaddstr_and_log_it(1, 30, _("Restoring Automatically"));
|
---|
[128] | 762 | if (bkpinfo->differential) {
|
---|
[1199] | 763 | log_to_screen(_("Because this is a differential backup, disk"));
|
---|
| 764 | log_to_screen(_
|
---|
| 765 | ("partitioning and formatting will not take place."));
|
---|
[128] | 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");
|
---|
[1] | 774 | #ifdef __FreeBSD__
|
---|
[1199] | 775 | tmp = call_program_and_get_last_line_of_output("cat /tmp/cmdline");
|
---|
[1] | 776 | #else
|
---|
[1199] | 777 | tmp = call_program_and_get_last_line_of_output("cat /proc/cmdline");
|
---|
[1] | 778 | #endif
|
---|
[1199] | 779 | if (strstr(tmp,"nopart")) {
|
---|
[1108] | 780 | mr_msg(2,
|
---|
[128] | 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
|
---|
[1199] | 787 | (_
|
---|
| 788 | ("Warning. Errors occurred during partitioning."));
|
---|
[128] | 789 | res = 0;
|
---|
| 790 | }
|
---|
| 791 | }
|
---|
| 792 | retval += res;
|
---|
| 793 | if (!res) {
|
---|
[1199] | 794 | log_to_screen(_("Preparing to format your disk(s)"));
|
---|
[128] | 795 | sleep(1);
|
---|
[1199] | 796 | sync();
|
---|
| 797 | log_to_screen(_
|
---|
| 798 | ("Please wait. This may take a few minutes."));
|
---|
[558] | 799 | res += format_everything(mountlist, FALSE, raidlist);
|
---|
[128] | 800 | }
|
---|
| 801 | paranoid_fclose(g_fprep);
|
---|
| 802 | }
|
---|
[1] | 803 | }
|
---|
[128] | 804 | retval += res;
|
---|
| 805 | if (res) {
|
---|
| 806 | mvaddstr_and_log_it(g_currentY++,
|
---|
| 807 | 0,
|
---|
[1199] | 808 | _
|
---|
| 809 | ("Failed to partition and/or format your hard drives."));
|
---|
[128] | 810 |
|
---|
[1199] | 811 | if (ask_me_yes_or_no(_("Try in interactive mode instead?"))) {
|
---|
[128] | 812 | retval = interactive_mode(bkpinfo, mountlist, raidlist);
|
---|
[1199] | 813 | call_me_after_the_nuke(retval);
|
---|
| 814 | return(retval);
|
---|
[128] | 815 | } else
|
---|
| 816 | if (!ask_me_yes_or_no
|
---|
[1199] | 817 | (_("Would you like to try to proceed anyway?"))) {
|
---|
| 818 | return(retval);
|
---|
[128] | 819 | }
|
---|
[1] | 820 | }
|
---|
[128] | 821 | retval = mount_all_devices(mountlist, TRUE);
|
---|
| 822 | if (retval) {
|
---|
| 823 | unmount_all_devices(mountlist);
|
---|
| 824 | log_to_screen
|
---|
[1199] | 825 | (_
|
---|
| 826 | ("Unable to mount all partitions. Sorry, I cannot proceed."));
|
---|
[128] | 827 | return (retval);
|
---|
[1] | 828 | }
|
---|
[128] | 829 | iamhere("Restoring everything");
|
---|
| 830 | retval += restore_everything(bkpinfo, NULL);
|
---|
| 831 | if (!run_boot_loader(FALSE)) {
|
---|
[1108] | 832 | mr_msg(1,
|
---|
[128] | 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,
|
---|
[1199] | 840 | _
|
---|
| 841 | ("Using e2label to label your ext2,3 partitions"));
|
---|
[1] | 842 |
|
---|
[1199] | 843 | mr_asprintf(&tmp, "label-partitions-as-necessary %s < /tmp/fstab",
|
---|
[128] | 844 | g_mountlist_fname);
|
---|
| 845 | res = run_program_and_log_output(tmp, TRUE);
|
---|
[1199] | 846 | mr_free(tmp);
|
---|
| 847 |
|
---|
[128] | 848 | if (res) {
|
---|
[1199] | 849 | log_to_screen(_
|
---|
| 850 | ("label-partitions-as-necessary returned an error"));
|
---|
| 851 | mvaddstr_and_log_it(g_currentY++, 74, _("Failed."));
|
---|
[128] | 852 | } else {
|
---|
[1199] | 853 | mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
|
---|
[128] | 854 | }
|
---|
| 855 | retval += res;
|
---|
[1] | 856 |
|
---|
[1199] | 857 | call_me_after_the_nuke(retval);
|
---|
[128] | 858 | return (retval);
|
---|
[1] | 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 | */
|
---|
[128] | 872 | int restore_to_live_filesystem(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 873 | {
|
---|
[128] | 874 | int retval = 0;
|
---|
[1] | 875 |
|
---|
[1199] | 876 | char *old_restpath = NULL;
|
---|
[1] | 877 |
|
---|
[1199] | 878 | struct mountlist_itself *mountlist = NULL;
|
---|
| 879 | struct raidlist_itself *raidlist = NULL;
|
---|
| 880 | struct s_node *filelist = NULL;
|
---|
[1] | 881 |
|
---|
[1108] | 882 | mr_msg(1, "restore_to_live_filesystem() - starting");
|
---|
[128] | 883 | assert(bkpinfo != NULL);
|
---|
[1199] | 884 |
|
---|
[1080] | 885 | mountlist = mr_malloc(sizeof(struct mountlist_itself));
|
---|
| 886 | raidlist = mr_malloc(sizeof(struct raidlist_itself));
|
---|
[1] | 887 |
|
---|
[128] | 888 | strcpy(bkpinfo->restore_path, "/");
|
---|
| 889 | if (!g_restoring_live_from_cd) {
|
---|
| 890 | popup_and_OK
|
---|
[1199] | 891 | (_
|
---|
| 892 | ("Please insert tape/CD/boot floppy, then hit 'OK' to continue."));
|
---|
[128] | 893 | sleep(1);
|
---|
| 894 | }
|
---|
| 895 | interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
|
---|
| 896 | if (!bkpinfo->media_device[0]) {
|
---|
[1108] | 897 | mr_msg(2, "Warning - failed to find media dev");
|
---|
[1199] | 898 | } else {
|
---|
| 899 | mr_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device);
|
---|
[128] | 900 | }
|
---|
[1] | 901 |
|
---|
| 902 |
|
---|
[1108] | 903 | mr_msg(2, "bkpinfo->isodir = %s", bkpinfo->isodir);
|
---|
[1] | 904 |
|
---|
[1199] | 905 | open_evalcall_form(_("Thinking..."));
|
---|
[1] | 906 |
|
---|
[128] | 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");
|
---|
[1199] | 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)) {
|
---|
[128] | 921 | iamhere("Restoring everything");
|
---|
| 922 | retval += restore_everything(bkpinfo, filelist);
|
---|
| 923 | }
|
---|
[1199] | 924 | free_filelist(filelist);
|
---|
[128] | 925 | strcpy(bkpinfo->restore_path, old_restpath);
|
---|
[1199] | 926 | mr_free(old_restpath);
|
---|
[128] | 927 | }
|
---|
| 928 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
[1108] | 929 | mr_msg(2,
|
---|
[128] | 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);
|
---|
[1199] | 933 | if ((!bkpinfo->please_dont_eject) && (bkpinfo->media_device != NULL)) {
|
---|
[128] | 934 | eject_device(bkpinfo->media_device);
|
---|
| 935 | }
|
---|
[1080] | 936 | mr_free(mountlist);
|
---|
| 937 | mr_free(raidlist);
|
---|
[128] | 938 | return (retval);
|
---|
[1] | 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,
|
---|
[128] | 966 | long bigfileno,
|
---|
| 967 | struct s_node *filelist,
|
---|
| 968 | char *pathname_of_last_file_restored)
|
---|
[1] | 969 | {
|
---|
[1199] | 970 | FILE *fin = NULL;
|
---|
| 971 | FILE *fout = NULL;
|
---|
| 972 | FILE *fbzip2 = NULL;
|
---|
[128] | 973 |
|
---|
[1199] | 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;
|
---|
[128] | 980 | int retval = 0;
|
---|
| 981 | int finished = FALSE;
|
---|
[1199] | 982 | long sliceno = 0L;
|
---|
[128] | 983 | long siz;
|
---|
[1199] | 984 | char *ntfsprog_fifo = NULL;
|
---|
[128] | 985 | char *file_to_openout = NULL;
|
---|
| 986 | struct s_filename_and_lstat_info biggiestruct;
|
---|
[1199] | 987 | struct utimbuf the_utime_buf, *ubuf = NULL;
|
---|
[296] | 988 | bool use_ntfsprog_hack = FALSE;
|
---|
[128] | 989 | pid_t pid;
|
---|
| 990 | int res = 0;
|
---|
| 991 | int old_loglevel;
|
---|
[1199] | 992 | char *sz_msg = NULL;
|
---|
| 993 | struct s_node *node = NULL;
|
---|
[1] | 994 |
|
---|
[128] | 995 | old_loglevel = g_loglevel;
|
---|
| 996 | ubuf = &the_utime_buf;
|
---|
| 997 | assert(bkpinfo != NULL);
|
---|
[1] | 998 |
|
---|
[128] | 999 | pathname_of_last_file_restored[0] = '\0';
|
---|
[1080] | 1000 | bigblk = mr_malloc(TAPE_BLOCK_SIZE);
|
---|
[1] | 1001 |
|
---|
[128] | 1002 | if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) {
|
---|
[541] | 1003 | log_to_screen("Cannot even open bigfile's info file");
|
---|
[128] | 1004 | return (1);
|
---|
| 1005 | }
|
---|
[1] | 1006 |
|
---|
[128] | 1007 | memset((void *) &biggiestruct, 0, sizeof(biggiestruct));
|
---|
| 1008 | if (fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin) <
|
---|
| 1009 | sizeof(biggiestruct)) {
|
---|
[1108] | 1010 | mr_msg(2, "Warning - unable to get biggiestruct of bigfile #%d",
|
---|
[128] | 1011 | bigfileno + 1);
|
---|
| 1012 | }
|
---|
| 1013 | paranoid_fclose(fin);
|
---|
[1] | 1014 |
|
---|
[1199] | 1015 | mr_asprintf(&checksum, biggiestruct.checksum);
|
---|
[1] | 1016 |
|
---|
[128] | 1017 | if (!checksum[0]) {
|
---|
[1199] | 1018 | mr_msg(3, "Warning - bigfile %ld does not have a checksum",
|
---|
[128] | 1019 | bigfileno + 1);
|
---|
| 1020 | }
|
---|
[1199] | 1021 | mr_free(checksum);
|
---|
[1] | 1022 |
|
---|
[128] | 1023 | if (!strncmp(biggiestruct.filename, "/dev/", 5)) // Whether NTFS or not :)
|
---|
| 1024 | {
|
---|
[1199] | 1025 | mr_asprintf(&outfile_fname, biggiestruct.filename);
|
---|
[128] | 1026 | } else {
|
---|
[1199] | 1027 | mr_asprintf(&outfile_fname, "%s/%s", bkpinfo->restore_path,
|
---|
[128] | 1028 | biggiestruct.filename);
|
---|
| 1029 | }
|
---|
[1] | 1030 |
|
---|
[128] | 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) {
|
---|
[1108] | 1035 | mr_msg(0, "Skipping %s (name isn't in filelist)",
|
---|
[128] | 1036 | biggiestruct.filename);
|
---|
| 1037 | return (0);
|
---|
| 1038 | } else if (!(node->selected)) {
|
---|
[1108] | 1039 | mr_msg(1, "Skipping %s (name isn't in biggielist subset)",
|
---|
[128] | 1040 | biggiestruct.filename);
|
---|
| 1041 | return (0);
|
---|
| 1042 | }
|
---|
[1] | 1043 | }
|
---|
[128] | 1044 | /* otherwise, continue */
|
---|
[1] | 1045 |
|
---|
[1108] | 1046 | mr_msg(1, "DEFINITELY restoring %s", biggiestruct.filename);
|
---|
[296] | 1047 | if (biggiestruct.use_ntfsprog) {
|
---|
[128] | 1048 | if (strncmp(biggiestruct.filename, "/dev/", 5)) {
|
---|
[1108] | 1049 | mr_msg(1,
|
---|
[296] | 1050 | "I was in error when I set biggiestruct.use_ntfsprog to TRUE.");
|
---|
[1108] | 1051 | mr_msg(1, "%s isn't even in /dev", biggiestruct.filename);
|
---|
[296] | 1052 | biggiestruct.use_ntfsprog = FALSE;
|
---|
[128] | 1053 | }
|
---|
| 1054 | }
|
---|
| 1055 |
|
---|
[296] | 1056 | if (biggiestruct.use_ntfsprog) // if it's an NTFS device
|
---|
[128] | 1057 | {
|
---|
| 1058 | g_loglevel = 4;
|
---|
[296] | 1059 | use_ntfsprog_hack = TRUE;
|
---|
[1108] | 1060 | mr_msg(2,
|
---|
[296] | 1061 | "Calling ntfsclone in background because %s is an NTFS /dev entry",
|
---|
[128] | 1062 | outfile_fname);
|
---|
[1199] | 1063 | mr_asprintf(&ntfsprog_fifo, "/tmp/%d.%d.000", (int) (random() % 32768),
|
---|
[128] | 1064 | (int) (random() % 32768));
|
---|
[1199] | 1065 | mkfifo(ntfsprog_fifo, 0x770);
|
---|
| 1066 |
|
---|
[296] | 1067 | file_to_openout = ntfsprog_fifo;
|
---|
[128] | 1068 | switch (pid = fork()) {
|
---|
| 1069 | case -1:
|
---|
| 1070 | fatal_error("Fork failure");
|
---|
| 1071 | case 0:
|
---|
[1108] | 1072 | mr_msg(3,
|
---|
[296] | 1073 | "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)",
|
---|
| 1074 | biggiestruct.filename, ntfsprog_fifo);
|
---|
[128] | 1075 | res =
|
---|
[296] | 1076 | feed_outfrom_ntfsprog(biggiestruct.filename,
|
---|
[1199] | 1077 | ntfsprog_fifo);
|
---|
[128] | 1078 | exit(res);
|
---|
| 1079 | break;
|
---|
| 1080 | default:
|
---|
[1108] | 1081 | mr_msg(3,
|
---|
[296] | 1082 | "feed_into_ntfsprog() called in background --- pid=%ld",
|
---|
[128] | 1083 | (long int) (pid));
|
---|
| 1084 | }
|
---|
| 1085 | } else {
|
---|
[296] | 1086 | use_ntfsprog_hack = FALSE;
|
---|
[128] | 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 | }
|
---|
[1] | 1093 |
|
---|
[1199] | 1094 | mr_msg(2, "Reassembling big file %ld (%s)", bigfileno + 1,
|
---|
[128] | 1095 | outfile_fname);
|
---|
[1] | 1096 |
|
---|
[128] | 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 | */
|
---|
[1] | 1102 |
|
---|
[128] | 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';
|
---|
[1] | 1106 |
|
---|
[1108] | 1107 | mr_msg(3, "file_to_openout = %s", file_to_openout);
|
---|
[128] | 1108 | if (!(fout = fopen(file_to_openout, "w"))) {
|
---|
[1199] | 1109 | log_to_screen(_("Cannot openout file_to_openout - hard disk full?"));
|
---|
[128] | 1110 | return (1);
|
---|
[1] | 1111 | }
|
---|
[1199] | 1112 |
|
---|
| 1113 | mr_free(ntfsprog_fifo);
|
---|
[1108] | 1114 | mr_msg(3, "Opened out to %s", outfile_fname); // CD/DVD --> mondorestore --> ntfsclone --> hard disk itself
|
---|
[1] | 1115 |
|
---|
[128] | 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
|
---|
[1053] | 1124 | (bigfileno, sliceno, ARCHIVES_PATH, "gz"))
|
---|
| 1125 | &&
|
---|
| 1126 | !does_file_exist(slice_fname
|
---|
[128] | 1127 | (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
|
---|
[1108] | 1128 | mr_msg(3,
|
---|
[128] | 1129 | "Cannot find a data slice or terminator slice on CD %d",
|
---|
| 1130 | g_current_media_number);
|
---|
| 1131 | g_current_media_number++;
|
---|
[1199] | 1132 | mr_msg(2, "Asking for %s #%d so that I may read slice #%ld\n",
|
---|
[128] | 1133 | media_descriptor_string(bkpinfo->backup_media_type),
|
---|
| 1134 | g_current_media_number, sliceno);
|
---|
[1199] | 1135 | log_to_screen(_("Restoring from %s #%d"),
|
---|
| 1136 | bkpinfo->backup_media_string,
|
---|
[128] | 1137 | g_current_media_number);
|
---|
| 1138 | insist_on_this_cd_number(bkpinfo, g_current_media_number);
|
---|
[1199] | 1139 | log_to_screen(_("Continuing to restore."));
|
---|
[128] | 1140 | } else {
|
---|
[1199] | 1141 | mr_asprintf(&tmp,
|
---|
[128] | 1142 | slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""));
|
---|
| 1143 | if (does_file_exist(tmp) && length_of_file(tmp) == 0) {
|
---|
[1108] | 1144 | mr_msg(2,
|
---|
[128] | 1145 | "End of bigfile # %ld (slice %ld is the terminator)",
|
---|
| 1146 | bigfileno + 1, sliceno);
|
---|
| 1147 | finished = TRUE;
|
---|
[1199] | 1148 | mr_free(tmp);
|
---|
[128] | 1149 | continue;
|
---|
| 1150 | } else {
|
---|
[1199] | 1151 | mr_free(tmp);
|
---|
[128] | 1152 | if (does_file_exist
|
---|
| 1153 | (slice_fname
|
---|
| 1154 | (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) {
|
---|
[1199] | 1155 | mr_asprintf(&bzip2_command, "lzop");
|
---|
| 1156 | mr_asprintf(&suffix, "lzo");
|
---|
[128] | 1157 | } else
|
---|
| 1158 | if (does_file_exist
|
---|
| 1159 | (slice_fname
|
---|
[998] | 1160 | (bigfileno, sliceno, ARCHIVES_PATH, "gz"))) {
|
---|
[1199] | 1161 | mr_asprintf(&bzip2_command, "gzip");
|
---|
| 1162 | mr_asprintf(&suffix, "gz");
|
---|
[998] | 1163 | } else
|
---|
| 1164 | if (does_file_exist
|
---|
| 1165 | (slice_fname
|
---|
[128] | 1166 | (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
|
---|
[1199] | 1167 | mr_asprintf(&bzip2_command, "bzip2");
|
---|
| 1168 | mr_asprintf(&suffix, "bz2");
|
---|
[128] | 1169 | } else
|
---|
| 1170 | if (does_file_exist
|
---|
| 1171 | (slice_fname
|
---|
| 1172 | (bigfileno, sliceno, ARCHIVES_PATH, ""))) {
|
---|
[1199] | 1173 | mr_asprintf(&bzip2_command, "");
|
---|
| 1174 | mr_asprintf(&suffix, "");
|
---|
[128] | 1175 | } else {
|
---|
[1199] | 1176 | log_to_screen(_("OK, that's pretty fsck0red..."));
|
---|
[128] | 1177 | return (1);
|
---|
| 1178 | }
|
---|
| 1179 | }
|
---|
| 1180 | if (bzip2_command[0] != '\0') {
|
---|
[1199] | 1181 | mr_strcat(bzip2_command,
|
---|
[128] | 1182 | " -dc %s 2>> %s",
|
---|
| 1183 | slice_fname(bigfileno, sliceno, ARCHIVES_PATH,
|
---|
| 1184 | suffix), MONDO_LOGFILE);
|
---|
| 1185 | } else {
|
---|
[1199] | 1186 | mr_free(bzip2_command);
|
---|
| 1187 | mr_asprintf(&bzip2_command, "cat %s 2>> %s",
|
---|
[128] | 1188 | slice_fname(bigfileno, sliceno, ARCHIVES_PATH,
|
---|
| 1189 | suffix), MONDO_LOGFILE);
|
---|
| 1190 | }
|
---|
[1199] | 1191 | mr_asprintf(&tmp, "Working on %s #%d, file #%ld, slice #%ld",
|
---|
| 1192 | bkpinfo->backup_media_string,
|
---|
[128] | 1193 | g_current_media_number, bigfileno + 1, sliceno);
|
---|
[1108] | 1194 | mr_msg(2, tmp);
|
---|
[128] | 1195 | if (!g_text_mode) {
|
---|
| 1196 | newtDrawRootText(0, g_noof_rows - 2, tmp);
|
---|
| 1197 | newtRefresh();
|
---|
| 1198 | update_progress_form(tmp);
|
---|
| 1199 | }
|
---|
[1199] | 1200 | mr_free(tmp);
|
---|
| 1201 |
|
---|
[128] | 1202 | if (!(fbzip2 = popen(bzip2_command, "r"))) {
|
---|
[1199] | 1203 | mr_free(bzip2_command);
|
---|
| 1204 | mr_free(suffix);
|
---|
[128] | 1205 | fatal_error("Can't run popen command");
|
---|
| 1206 | }
|
---|
[1199] | 1207 | mr_free(bzip2_command);
|
---|
| 1208 | mr_free(suffix);
|
---|
| 1209 |
|
---|
[128] | 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);
|
---|
[1] | 1217 |
|
---|
[128] | 1218 | sliceno++;
|
---|
| 1219 | g_current_progress++;
|
---|
| 1220 | }
|
---|
| 1221 | }
|
---|
| 1222 | paranoid_fclose(fout);
|
---|
| 1223 | g_loglevel = old_loglevel;
|
---|
[1] | 1224 |
|
---|
[296] | 1225 | if (use_ntfsprog_hack) {
|
---|
[1108] | 1226 | mr_msg(3, "Waiting for ntfsclone to finish");
|
---|
[1199] | 1227 | mr_asprintf(&tmp,
|
---|
[433] | 1228 | " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
|
---|
[128] | 1229 | while (system(tmp) == 0) {
|
---|
| 1230 | sleep(1);
|
---|
| 1231 | }
|
---|
[1199] | 1232 | mr_free(tmp);
|
---|
[296] | 1233 | log_it("OK, ntfsclone has really finished");
|
---|
[128] | 1234 | }
|
---|
[1] | 1235 |
|
---|
[128] | 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 | }
|
---|
[1199] | 1244 | mr_free(outfile_fname);
|
---|
[1080] | 1245 | mr_free(bigblk);
|
---|
[1] | 1246 |
|
---|
[128] | 1247 | return (retval);
|
---|
[1] | 1248 | }
|
---|
| 1249 |
|
---|
[1199] | 1250 |
|
---|
[1] | 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 | */
|
---|
[128] | 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,
|
---|
[296] | 1270 | int use_ntfsprog,
|
---|
[128] | 1271 | char *pathname_of_last_file_restored)
|
---|
[1] | 1272 | {
|
---|
[1199] | 1273 | FILE *pout = NULL;
|
---|
| 1274 | FILE *fin = NULL;
|
---|
[1] | 1275 |
|
---|
| 1276 | /** mallocs ********/
|
---|
[1199] | 1277 | char *tmp = NULL;
|
---|
| 1278 | char *tmp1 = NULL;
|
---|
| 1279 | char *command = NULL;
|
---|
| 1280 | char *outfile_fname = NULL;
|
---|
| 1281 | char *ntfsprog_fifo = NULL;
|
---|
[128] | 1282 | char *file_to_openout = NULL;
|
---|
[1] | 1283 |
|
---|
[1199] | 1284 | struct s_node *node = NULL;
|
---|
[1] | 1285 |
|
---|
[1199] | 1286 | int old_loglevel = 0;
|
---|
[128] | 1287 | long current_slice_number = 0;
|
---|
| 1288 | int retval = 0;
|
---|
| 1289 | int res = 0;
|
---|
| 1290 | int ctrl_chr = '\0';
|
---|
[1199] | 1291 | long long slice_siz = 0L;
|
---|
[128] | 1292 | bool dummy_restore = FALSE;
|
---|
[296] | 1293 | bool use_ntfsprog_hack = FALSE;
|
---|
[128] | 1294 | pid_t pid;
|
---|
| 1295 | struct s_filename_and_lstat_info biggiestruct;
|
---|
[1199] | 1296 | struct utimbuf the_utime_buf, *ubuf = NULL;
|
---|
[128] | 1297 | ubuf = &the_utime_buf;
|
---|
[1] | 1298 |
|
---|
[128] | 1299 | old_loglevel = g_loglevel;
|
---|
| 1300 | assert(bkpinfo != NULL);
|
---|
| 1301 | assert(orig_bf_fname != NULL);
|
---|
| 1302 | assert(orig_checksum != NULL);
|
---|
[1] | 1303 |
|
---|
[128] | 1304 | pathname_of_last_file_restored[0] = '\0';
|
---|
[296] | 1305 | if (use_ntfsprog == BLK_START_A_PIHBIGGIE) {
|
---|
| 1306 | use_ntfsprog = 1;
|
---|
[1108] | 1307 | mr_msg(1, "%s --- pih=YES", orig_bf_fname);
|
---|
[296] | 1308 | } else if (use_ntfsprog == BLK_START_A_NORMBIGGIE) {
|
---|
| 1309 | use_ntfsprog = 0;
|
---|
[1108] | 1310 | mr_msg(1, "%s --- pih=NO", orig_bf_fname);
|
---|
[128] | 1311 | } else {
|
---|
[296] | 1312 | use_ntfsprog = 0;
|
---|
[1108] | 1313 | mr_msg(1, "%s --- pih=NO (weird marker though)", orig_bf_fname);
|
---|
[128] | 1314 | }
|
---|
[1] | 1315 |
|
---|
[128] | 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';
|
---|
[1] | 1319 |
|
---|
[128] | 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;
|
---|
[1108] | 1326 | mr_msg(1,
|
---|
[128] | 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;
|
---|
[1108] | 1332 | mr_msg(1, "Skipping %s (name isn't in biggielist subset)",
|
---|
[128] | 1333 | orig_bf_fname);
|
---|
| 1334 | pathname_of_last_file_restored[0] = '\0';
|
---|
| 1335 | }
|
---|
[1] | 1336 | }
|
---|
| 1337 |
|
---|
[296] | 1338 | if (use_ntfsprog) {
|
---|
[128] | 1339 | if (strncmp(orig_bf_fname, "/dev/", 5)) {
|
---|
[1199] | 1340 | mr_msg(1, "I was in error when I set use_ntfsprog to TRUE.");
|
---|
[1108] | 1341 | mr_msg(1, "%s isn't even in /dev", orig_bf_fname);
|
---|
[296] | 1342 | use_ntfsprog = FALSE;
|
---|
[128] | 1343 | }
|
---|
| 1344 | }
|
---|
[1] | 1345 |
|
---|
[296] | 1346 | if (use_ntfsprog) {
|
---|
[128] | 1347 | g_loglevel = 4;
|
---|
[1199] | 1348 | mr_asprintf(&outfile_fname, orig_bf_fname);
|
---|
[296] | 1349 | use_ntfsprog_hack = TRUE;
|
---|
[1108] | 1350 | mr_msg(2,
|
---|
[296] | 1351 | "Calling ntfsclone in background because %s is a /dev entry",
|
---|
[128] | 1352 | outfile_fname);
|
---|
[1199] | 1353 | mr_asprintf(&ntfsprog_fifo, "%s/%d.%d.000",
|
---|
[812] | 1354 | bkpinfo->tmpdir,
|
---|
| 1355 | (int) (random() % 32768),
|
---|
[128] | 1356 | (int) (random() % 32768));
|
---|
[1199] | 1357 | mkfifo(ntfsprog_fifo, 0x770);
|
---|
| 1358 |
|
---|
[296] | 1359 | file_to_openout = ntfsprog_fifo;
|
---|
[128] | 1360 | switch (pid = fork()) {
|
---|
| 1361 | case -1:
|
---|
| 1362 | fatal_error("Fork failure");
|
---|
| 1363 | case 0:
|
---|
[1108] | 1364 | mr_msg(3,
|
---|
[296] | 1365 | "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)",
|
---|
| 1366 | outfile_fname, ntfsprog_fifo);
|
---|
[1199] | 1367 | res = feed_outfrom_ntfsprog(outfile_fname, ntfsprog_fifo);
|
---|
[128] | 1368 | exit(res);
|
---|
| 1369 | break;
|
---|
| 1370 | default:
|
---|
[1108] | 1371 | mr_msg(3,
|
---|
[296] | 1372 | "feed_into_ntfsprog() called in background --- pid=%ld",
|
---|
[128] | 1373 | (long int) (pid));
|
---|
| 1374 | }
|
---|
| 1375 | } else {
|
---|
| 1376 | if (!strncmp(orig_bf_fname, "/dev/", 5)) // non-NTFS partition
|
---|
| 1377 | {
|
---|
[1199] | 1378 | mr_asprintf(&outfile_fname, orig_bf_fname);
|
---|
[128] | 1379 | } else // biggiefile
|
---|
| 1380 | {
|
---|
[1199] | 1381 | mr_asprintf(&outfile_fname, "%s/%s", bkpinfo->restore_path,
|
---|
[128] | 1382 | orig_bf_fname);
|
---|
| 1383 | }
|
---|
[296] | 1384 | use_ntfsprog_hack = FALSE;
|
---|
[128] | 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 | }
|
---|
[1199] | 1390 | mr_msg(2, "Reassembling big file %ld (%s)",
|
---|
[128] | 1391 | biggiefile_number + 1, orig_bf_fname);
|
---|
[1] | 1392 | }
|
---|
[128] | 1393 |
|
---|
| 1394 | if (dummy_restore) {
|
---|
[1199] | 1395 | mr_free(outfile_fname);
|
---|
| 1396 | mr_asprintf(&outfile_fname, "/dev/null");
|
---|
[1] | 1397 | }
|
---|
[128] | 1398 |
|
---|
| 1399 | if (!bkpinfo->zip_exe[0]) {
|
---|
[1199] | 1400 | mr_asprintf(&command, "cat > \"%s\"", file_to_openout);
|
---|
[128] | 1401 | } else {
|
---|
[1199] | 1402 | mr_asprintf(&command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe,
|
---|
[128] | 1403 | file_to_openout, MONDO_LOGFILE);
|
---|
[1] | 1404 | }
|
---|
[1199] | 1405 | mr_msg(3, "Pipe command = '%s'", command);
|
---|
| 1406 | mr_free(outfile_fname);
|
---|
| 1407 | mr_free(ntfsprog_fifo);
|
---|
[1] | 1408 |
|
---|
[128] | 1409 | /* restore biggiefile, one slice at a time */
|
---|
| 1410 | if (!(pout = popen(command, "w"))) {
|
---|
| 1411 | fatal_error("Cannot pipe out");
|
---|
| 1412 | }
|
---|
[1199] | 1413 | mr_free(command);
|
---|
| 1414 |
|
---|
| 1415 | malloc_string(tmp1);
|
---|
| 1416 | for (res = read_header_block_from_stream(&slice_siz, tmp1, &ctrl_chr);
|
---|
[128] | 1417 | ctrl_chr != BLK_STOP_A_BIGGIE;
|
---|
[1199] | 1418 | res = read_header_block_from_stream(&slice_siz, tmp1, &ctrl_chr)) {
|
---|
[128] | 1419 | if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
|
---|
| 1420 | wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
|
---|
| 1421 | }
|
---|
[1199] | 1422 | mr_asprintf(&tmp, "Working on file #%ld, slice #%ld ",
|
---|
[128] | 1423 | biggiefile_number + 1, current_slice_number);
|
---|
[1108] | 1424 | mr_msg(2, tmp);
|
---|
[128] | 1425 | if (!g_text_mode) {
|
---|
| 1426 | newtDrawRootText(0, g_noof_rows - 2, tmp);
|
---|
| 1427 | newtRefresh();
|
---|
| 1428 | }
|
---|
[1168] | 1429 | mr_strip_spaces(tmp);
|
---|
[128] | 1430 | update_progress_form(tmp);
|
---|
[1199] | 1431 | mr_free(tmp);
|
---|
[128] | 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)) {
|
---|
[1108] | 1443 | mr_msg(2,
|
---|
[128] | 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;
|
---|
[1199] | 1454 | res = read_header_block_from_stream(&slice_siz, tmp1, &ctrl_chr);
|
---|
[128] | 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 | }
|
---|
[1199] | 1461 | mr_free(tmp1);
|
---|
[128] | 1462 | paranoid_pclose(pout);
|
---|
[1] | 1463 |
|
---|
[1108] | 1464 | mr_msg(1, "pathname_of_last_file_restored is now %s",
|
---|
[128] | 1465 | pathname_of_last_file_restored);
|
---|
[1] | 1466 |
|
---|
[296] | 1467 | if (use_ntfsprog_hack) {
|
---|
[1108] | 1468 | mr_msg(3, "Waiting for ntfsclone to finish");
|
---|
[1199] | 1469 | mr_asprintf(&tmp,
|
---|
[433] | 1470 | " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
|
---|
[128] | 1471 | while (system(tmp) == 0) {
|
---|
| 1472 | sleep(1);
|
---|
[1199] | 1473 | }
|
---|
| 1474 | mr_free(tmp);
|
---|
[1108] | 1475 | mr_msg(3, "OK, ntfsclone has really finished");
|
---|
[128] | 1476 | }
|
---|
| 1477 |
|
---|
[1108] | 1478 | mr_msg(3, "biggiestruct.filename = %s", biggiestruct.filename);
|
---|
| 1479 | mr_msg(3, "biggiestruct.checksum = %s", biggiestruct.checksum);
|
---|
[128] | 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);
|
---|
[1] | 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,
|
---|
[128] | 1511 | long current_tarball_number,
|
---|
[1170] | 1512 | struct s_node *filelist, struct s_bkpinfo *bkpinfo)
|
---|
[1] | 1513 | {
|
---|
[128] | 1514 | int retval = 0;
|
---|
[1199] | 1515 | int res = 0;
|
---|
| 1516 | char *p = NULL;
|
---|
[1] | 1517 |
|
---|
| 1518 | /** malloc **/
|
---|
[1199] | 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;
|
---|
[128] | 1525 | long matches = 0;
|
---|
[1199] | 1526 | bool use_star = FALSE;
|
---|
| 1527 | char *xattr_fname = NULL;
|
---|
| 1528 | char *acl_fname = NULL;
|
---|
[1] | 1529 |
|
---|
[128] | 1530 | assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
|
---|
| 1531 |
|
---|
[1108] | 1532 | mr_msg(5, "Entering");
|
---|
[128] | 1533 | use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
|
---|
[1199] | 1534 | mr_asprintf(&command, "mkdir -p %s/tmp", MNT_RESTORING);
|
---|
[128] | 1535 | run_program_and_log_output(command, 9);
|
---|
[1199] | 1536 | mr_free(command);
|
---|
[1] | 1537 |
|
---|
[1199] | 1538 | mr_asprintf(&filelist_name, MNT_CDROM "/archives/filelist.%ld",
|
---|
[128] | 1539 | current_tarball_number);
|
---|
| 1540 | if (length_of_file(filelist_name) <= 2) {
|
---|
[1108] | 1541 | mr_msg(2, "There are _zero_ files in filelist '%s'",
|
---|
[128] | 1542 | filelist_name);
|
---|
[1108] | 1543 | mr_msg(2,
|
---|
[676] | 1544 | "This is a bit silly (ask dev-team to fix mondo_makefilelist, please)");
|
---|
[1108] | 1545 | mr_msg(2,
|
---|
[128] | 1546 | "but it's non-critical. It's cosmetic. Don't worry about it.");
|
---|
| 1547 | retval = 0;
|
---|
[1199] | 1548 | mr_msg(5, "Leaving");
|
---|
| 1549 | mr_free(filelist_name);
|
---|
| 1550 | return (retval);
|
---|
[1] | 1551 | }
|
---|
[128] | 1552 | if (count_lines_in_file(filelist_name) <= 0
|
---|
| 1553 | || length_of_file(tarball_fname) <= 0) {
|
---|
[1108] | 1554 | mr_msg(3, "length_of_file(%s) = %llu", tarball_fname,
|
---|
[128] | 1555 | length_of_file(tarball_fname));
|
---|
[1199] | 1556 | log_to_screen(_("Unable to restore fileset #%ld (CD I/O error)"),
|
---|
[128] | 1557 | current_tarball_number);
|
---|
| 1558 | retval = 1;
|
---|
[1199] | 1559 | mr_msg(5, "Leaving");
|
---|
| 1560 | mr_free(filelist_name);
|
---|
| 1561 | return (retval);
|
---|
[1] | 1562 | }
|
---|
| 1563 |
|
---|
[128] | 1564 | if (filelist) {
|
---|
[1199] | 1565 | mr_asprintf(&filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp",
|
---|
[128] | 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) {
|
---|
[1199] | 1572 | mr_msg(1, "Skipping fileset %ld", current_tarball_number);
|
---|
[128] | 1573 | } else {
|
---|
[1108] | 1574 | mr_msg(3, "Saved fileset %ld's subset to %s",
|
---|
[128] | 1575 | current_tarball_number, filelist_subset_fname);
|
---|
| 1576 | }
|
---|
[1199] | 1577 | log_to_screen("Tarball #%ld --- %ld matches",
|
---|
[128] | 1578 | current_tarball_number, matches);
|
---|
| 1579 | }
|
---|
[1199] | 1580 | mr_free(filelist_name);
|
---|
[128] | 1581 |
|
---|
| 1582 | if (filelist == NULL || matches > 0) {
|
---|
[948] | 1583 | if (g_getfattr) {
|
---|
[1199] | 1584 | mr_asprintf(&xattr_fname, XATTR_LIST_FNAME_RAW_SZ,
|
---|
[128] | 1585 | MNT_CDROM "/archives", current_tarball_number);
|
---|
[948] | 1586 | }
|
---|
| 1587 | if (g_getfacl) {
|
---|
[1199] | 1588 | mr_asprintf(&acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives",
|
---|
[128] | 1589 | current_tarball_number);
|
---|
[948] | 1590 | }
|
---|
[128] | 1591 | if (strstr(tarball_fname, ".bz2")) {
|
---|
[1199] | 1592 | mr_asprintf(&executable, "-P bzip2 -Z");
|
---|
[998] | 1593 | } else if (strstr(tarball_fname, ".gz")) {
|
---|
[1199] | 1594 | mr_asprintf(&executable, "-P gzip -Z");
|
---|
[128] | 1595 | } else if (strstr(tarball_fname, ".lzo")) {
|
---|
[1199] | 1596 | mr_asprintf(&executable, "-P lzop -Z");
|
---|
[128] | 1597 | }
|
---|
[1199] | 1598 |
|
---|
| 1599 | if (executable == NULL) {
|
---|
| 1600 | mr_asprintf(&tmp, "which %s > /dev/null 2> /dev/null", executable);
|
---|
[128] | 1601 | if (run_program_and_log_output(tmp, FALSE)) {
|
---|
| 1602 | log_to_screen
|
---|
[1199] | 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);
|
---|
[128] | 1610 | paranoid_MR_finish(1);
|
---|
| 1611 | }
|
---|
[1199] | 1612 | mr_free(tmp);
|
---|
[128] | 1613 | }
|
---|
[1] | 1614 | #ifdef __FreeBSD__
|
---|
| 1615 | #define BUFSIZE 512
|
---|
| 1616 | #else
|
---|
| 1617 | #define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE
|
---|
| 1618 | #endif
|
---|
| 1619 |
|
---|
[128] | 1620 | if (use_star) {
|
---|
[1199] | 1621 | mr_sprintf(&command,
|
---|
[128] | 1622 | "star -x -force-remove -U " STAR_ACL_SZ
|
---|
| 1623 | " errctl= file=%s", tarball_fname);
|
---|
| 1624 | if (strstr(tarball_fname, ".bz2")) {
|
---|
[1199] | 1625 | mr_strcat(command, " -bz");
|
---|
[128] | 1626 | }
|
---|
| 1627 | } else {
|
---|
[1199] | 1628 | if (filelist_subset_fname != NULL) {
|
---|
| 1629 | mr_asprintf(&command,
|
---|
[543] | 1630 | "afio -i -M 8m -b %ld -c %ld %s -w '%s' %s",
|
---|
[128] | 1631 | TAPE_BLOCK_SIZE,
|
---|
| 1632 | BUFSIZE, executable, filelist_subset_fname,
|
---|
| 1633 | tarball_fname);
|
---|
| 1634 | } else {
|
---|
[1199] | 1635 | mr_asprintf(&command,
|
---|
[128] | 1636 | "afio -i -b %ld -c %ld -M 8m %s %s",
|
---|
| 1637 | TAPE_BLOCK_SIZE,
|
---|
| 1638 | BUFSIZE, executable, tarball_fname);
|
---|
| 1639 | }
|
---|
| 1640 | }
|
---|
[1199] | 1641 | mr_free(executable);
|
---|
| 1642 |
|
---|
[128] | 1643 | #undef BUFSIZE
|
---|
[1199] | 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);
|
---|
[1108] | 1648 | mr_msg(1, "command = '%s'", command);
|
---|
[128] | 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] = ' ';
|
---|
[1108] | 1655 | mr_msg(1, "new command = '%s'", command);
|
---|
[128] | 1656 | res = system(command);
|
---|
| 1657 | }
|
---|
| 1658 | }
|
---|
[1199] | 1659 | mr_free(command);
|
---|
| 1660 |
|
---|
[128] | 1661 | if (res && length_of_file(temp_log) < 5) {
|
---|
| 1662 | res = 0;
|
---|
| 1663 | }
|
---|
| 1664 |
|
---|
[948] | 1665 | if (g_getfattr) {
|
---|
[1108] | 1666 | mr_msg(1, "Setting fattr list %s", xattr_fname);
|
---|
[948] | 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 {
|
---|
[1108] | 1673 | mr_msg(1, "I set xattr OK");
|
---|
[948] | 1674 | }
|
---|
| 1675 | retval += res;
|
---|
[128] | 1676 | }
|
---|
| 1677 | }
|
---|
[948] | 1678 | if (g_getfacl) {
|
---|
[1108] | 1679 | mr_msg(1, "Setting acl list %s", acl_fname);
|
---|
[948] | 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 {
|
---|
[1108] | 1686 | mr_msg(1, "I set ACL OK");
|
---|
[948] | 1687 | }
|
---|
| 1688 | retval += res;
|
---|
[128] | 1689 | }
|
---|
| 1690 | }
|
---|
| 1691 | if (retval) {
|
---|
[1199] | 1692 | mr_asprintf(&command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
|
---|
[128] | 1693 | system(command);
|
---|
[1199] | 1694 | mr_free(command);
|
---|
[1108] | 1695 | mr_msg(2, "Errors occurred while processing fileset #%d",
|
---|
[128] | 1696 | current_tarball_number);
|
---|
| 1697 | } else {
|
---|
[1108] | 1698 | mr_msg(2, "Fileset #%d processed OK", current_tarball_number);
|
---|
[128] | 1699 | }
|
---|
[1199] | 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);
|
---|
[1] | 1706 | }
|
---|
[128] | 1707 | if (does_file_exist("/PAUSE")) {
|
---|
| 1708 | popup_and_OK
|
---|
[1199] | 1709 | (_
|
---|
| 1710 | ("Press ENTER to go on. Delete /PAUSE to stop these pauses."));
|
---|
[1] | 1711 | }
|
---|
[128] | 1712 | unlink(filelist_subset_fname);
|
---|
[1080] | 1713 | mr_free(filelist_subset_fname);
|
---|
[1108] | 1714 | mr_msg(5, "Leaving");
|
---|
[128] | 1715 | return (retval);
|
---|
[1] | 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,
|
---|
[128] | 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)
|
---|
[1] | 1745 | {
|
---|
[128] | 1746 | int retval = 0;
|
---|
| 1747 | int res = 0;
|
---|
[1] | 1748 |
|
---|
| 1749 | /** malloc add ***/
|
---|
[1199] | 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;
|
---|
[128] | 1756 | long matches = 0;
|
---|
| 1757 | bool restore_this_fileset = FALSE;
|
---|
[1199] | 1758 | bool use_star = FALSE;
|
---|
[1] | 1759 |
|
---|
[128] | 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;
|
---|
[1199] | 1764 | mr_msg(2, "Restoring from fileset #%ld (%ld KB) on %s #%d",
|
---|
[128] | 1765 | current_tarball_number, (long) size >> 10,
|
---|
[1199] | 1766 | bkpinfo->backup_media_string,
|
---|
[128] | 1767 | g_current_media_number);
|
---|
| 1768 | run_program_and_log_output("mkdir -p " MNT_RESTORING "/tmp", FALSE);
|
---|
| 1769 |
|
---|
[1] | 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 | ****************************************************************************/
|
---|
[1199] | 1775 | mr_asprintf(&afio_fname, "/tmp/tmpfs/archive.tmp.%ld",
|
---|
[128] | 1776 | current_tarball_number);
|
---|
[1199] | 1777 | mr_asprintf(&filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir,
|
---|
[128] | 1778 | current_tarball_number);
|
---|
[1199] | 1779 | mr_asprintf(&filelist_subset_fname, "%s/filelist-subset-%ld.tmp",
|
---|
[128] | 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;
|
---|
[1] | 1784 | }
|
---|
[128] | 1785 | if (res) {
|
---|
[1108] | 1786 | mr_msg(1, "Warning - error reading afioball from tape");
|
---|
[1] | 1787 | }
|
---|
[1199] | 1788 | if (bkpinfo->compression_level != 0) {
|
---|
[128] | 1789 | if (bkpinfo->use_star) {
|
---|
[1199] | 1790 | mr_asprintf(&executable, " -bz");
|
---|
[128] | 1791 | } else {
|
---|
[1199] | 1792 | mr_asprintf(&executable, "-P %s -Z", bkpinfo->zip_exe);
|
---|
[128] | 1793 | }
|
---|
[1] | 1794 | }
|
---|
| 1795 |
|
---|
[128] | 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;
|
---|
[1199] | 1803 | mr_asprintf(&command, "star -t file=%s %s", afio_fname, executable);
|
---|
[128] | 1804 | } else {
|
---|
| 1805 | use_star = FALSE;
|
---|
[1199] | 1806 | mr_asprintf(&command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE,
|
---|
[128] | 1807 | executable, afio_fname);
|
---|
| 1808 | }
|
---|
[1199] | 1809 | mr_strcat(command, " > %s 2>> %s", filelist_fname, MONDO_LOGFILE);
|
---|
[1108] | 1810 | mr_msg(1, "command = %s", command);
|
---|
[128] | 1811 | if (system(command)) {
|
---|
[1108] | 1812 | mr_msg(4, "Warning - error occurred while retrieving TOC");
|
---|
[128] | 1813 | }
|
---|
[1199] | 1814 | mr_free(command);
|
---|
| 1815 |
|
---|
[128] | 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) {
|
---|
[1108] | 1822 | mr_msg(1, "No matches found in fileset %ld",
|
---|
[128] | 1823 | current_tarball_number);
|
---|
| 1824 | }
|
---|
[1199] | 1825 | mr_msg(2, "Skipping fileset %ld", current_tarball_number);
|
---|
[128] | 1826 | restore_this_fileset = FALSE;
|
---|
| 1827 | } else {
|
---|
[1108] | 1828 | mr_msg(5, "%ld matches. Saved fileset %ld's subset to %s",
|
---|
[128] | 1829 | matches, current_tarball_number,
|
---|
| 1830 | filelist_subset_fname);
|
---|
| 1831 | restore_this_fileset = TRUE;
|
---|
| 1832 | }
|
---|
| 1833 | }
|
---|
[1199] | 1834 | unlink(filelist_fname);
|
---|
| 1835 | mr_free(filelist_fname);
|
---|
[128] | 1836 |
|
---|
[1] | 1837 | // Concoct the call to star/afio to restore files
|
---|
[1199] | 1838 | if (strstr(tarball_fname, ".star.")) {
|
---|
| 1839 | // star
|
---|
[128] | 1840 | if (filelist) {
|
---|
[1199] | 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);
|
---|
[128] | 1844 | }
|
---|
[1199] | 1845 | } else {
|
---|
| 1846 | // afio
|
---|
[128] | 1847 | if (filelist) {
|
---|
[1199] | 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);
|
---|
[128] | 1851 | }
|
---|
| 1852 | }
|
---|
[1199] | 1853 | mr_free(executable);
|
---|
[1] | 1854 |
|
---|
[1199] | 1855 | // Call if IF there are files to restore (selectively/unconditionally)
|
---|
[128] | 1856 | if (restore_this_fileset) {
|
---|
[1108] | 1857 | mr_msg(1, "Calling command='%s'", command);
|
---|
[128] | 1858 | paranoid_system(command);
|
---|
[1] | 1859 |
|
---|
[948] | 1860 | if (g_getfattr) {
|
---|
| 1861 | iamhere("Restoring xattr stuff");
|
---|
| 1862 | res = set_fattr_list(filelist_subset_fname, xattr_fname);
|
---|
| 1863 | if (res) {
|
---|
[1108] | 1864 | mr_msg(1, "Errors occurred while setting xattr");
|
---|
[948] | 1865 | } else {
|
---|
[1108] | 1866 | mr_msg(1, "I set xattr OK");
|
---|
[948] | 1867 | }
|
---|
| 1868 | retval += res;
|
---|
[128] | 1869 | }
|
---|
[1] | 1870 |
|
---|
[948] | 1871 | if (g_getfacl) {
|
---|
| 1872 | iamhere("Restoring acl stuff");
|
---|
| 1873 | res = set_acl_list(filelist_subset_fname, acl_fname);
|
---|
| 1874 | if (res) {
|
---|
[1108] | 1875 | mr_msg(1, "Errors occurred while setting ACL");
|
---|
[948] | 1876 | } else {
|
---|
[1108] | 1877 | mr_msg(1, "I set ACL OK");
|
---|
[948] | 1878 | }
|
---|
| 1879 | retval += res;
|
---|
[128] | 1880 | }
|
---|
| 1881 |
|
---|
| 1882 | } else {
|
---|
[1108] | 1883 | mr_msg(1, "NOT CALLING '%s'", command);
|
---|
[128] | 1884 | }
|
---|
[1199] | 1885 | mr_free(command);
|
---|
[128] | 1886 |
|
---|
| 1887 | if (does_file_exist("/PAUSE") && current_tarball_number >= 50) {
|
---|
[1199] | 1888 | log_to_screen(_("Paused after set %ld"), current_tarball_number);
|
---|
| 1889 | popup_and_OK(_("Pausing. Press ENTER to continue."));
|
---|
[128] | 1890 | }
|
---|
| 1891 |
|
---|
| 1892 | unlink(filelist_subset_fname);
|
---|
| 1893 | unlink(afio_fname);
|
---|
| 1894 |
|
---|
[1080] | 1895 | mr_free(filelist_subset_fname);
|
---|
| 1896 | mr_free(afio_fname);
|
---|
[128] | 1897 | return (retval);
|
---|
[1] | 1898 | }
|
---|
[128] | 1899 |
|
---|
[1] | 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
|
---|
[128] | 1915 | restore_all_biggiefiles_from_CD(struct s_bkpinfo *bkpinfo,
|
---|
| 1916 | struct s_node *filelist)
|
---|
[1] | 1917 | {
|
---|
[128] | 1918 | int retval = 0;
|
---|
[1199] | 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;
|
---|
[128] | 1928 | FILE *fbw = NULL;
|
---|
[1] | 1929 |
|
---|
[1199] | 1930 | malloc_string(tmp1);
|
---|
[128] | 1931 | malloc_string(pathname_of_last_biggie_restored);
|
---|
| 1932 | assert(bkpinfo != NULL);
|
---|
| 1933 |
|
---|
[1199] | 1934 | mr_asprintf(&biggies_whose_EXATs_we_should_set,
|
---|
[128] | 1935 | "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
|
---|
| 1936 | if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
|
---|
[1108] | 1937 | mr_msg(1, "Warning - cannot openout %s",
|
---|
[128] | 1938 | biggies_whose_EXATs_we_should_set);
|
---|
[1] | 1939 | }
|
---|
| 1940 |
|
---|
[1199] | 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 "));
|
---|
[128] | 1946 | mvaddstr_and_log_it(g_currentY, 0, tmp);
|
---|
[1199] | 1947 | mr_free(tmp);
|
---|
| 1948 |
|
---|
[128] | 1949 | if (length_of_file(BIGGIELIST) < 6) {
|
---|
[1108] | 1950 | mr_msg(1, "OK, no biggielist; not restoring biggiefiles");
|
---|
[128] | 1951 | return (0);
|
---|
[1] | 1952 | }
|
---|
[128] | 1953 | noof_biggiefiles = count_lines_in_file(BIGGIELIST);
|
---|
| 1954 | if (noof_biggiefiles <= 0) {
|
---|
[1108] | 1955 | mr_msg(2,
|
---|
[128] | 1956 | "OK, no biggiefiles in biggielist; not restoring biggiefiles");
|
---|
| 1957 | return (0);
|
---|
| 1958 | }
|
---|
[1199] | 1959 | mr_msg(2, "OK, there are %ld biggiefiles in the archives", noof_biggiefiles);
|
---|
[1] | 1960 |
|
---|
[1199] | 1961 | open_progress_form(_("Reassembling large files"),
|
---|
| 1962 | _("I am now reassembling all the large files."),
|
---|
| 1963 | _("Please wait. This may take some time."),
|
---|
[128] | 1964 | "", total_slices);
|
---|
| 1965 | for (bigfileno = 0, finished = FALSE; !finished;) {
|
---|
[1108] | 1966 | mr_msg(2, "Thinking about restoring bigfile %ld", bigfileno + 1);
|
---|
[128] | 1967 | if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) {
|
---|
[1108] | 1968 | mr_msg(3,
|
---|
[128] | 1969 | "...but its first slice isn't on this CD. Perhaps this was a selective restore?");
|
---|
[1108] | 1970 | mr_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d",
|
---|
[128] | 1971 | bigfileno + 1,
|
---|
[1199] | 1972 | bkpinfo->backup_media_string,
|
---|
[128] | 1973 | g_current_media_number);
|
---|
[1108] | 1974 | mr_msg(3, "Slicename would have been %s",
|
---|
[128] | 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;
|
---|
[1108] | 1979 | mr_msg(3,
|
---|
[128] | 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);
|
---|
[1199] | 1984 | log_to_screen(_("Restoring from %s #%d"),
|
---|
| 1985 | bkpinfo->backup_media_string,
|
---|
[128] | 1986 | g_current_media_number);
|
---|
| 1987 | just_changed_cds = TRUE;
|
---|
| 1988 | } else {
|
---|
[1108] | 1989 | mr_msg(2, "There was no bigfile #%ld. That's OK.",
|
---|
[128] | 1990 | bigfileno + 1);
|
---|
[1108] | 1991 | mr_msg(2, "I'm going to stop restoring bigfiles now.");
|
---|
[128] | 1992 | finished = TRUE;
|
---|
| 1993 | }
|
---|
| 1994 | } else {
|
---|
| 1995 | just_changed_cds = FALSE;
|
---|
[1199] | 1996 | mr_asprintf(&tmp, _("Restoring big file %ld"), bigfileno + 1);
|
---|
[128] | 1997 | update_progress_form(tmp);
|
---|
[1199] | 1998 | mr_free(tmp);
|
---|
| 1999 |
|
---|
[128] | 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 | }
|
---|
[1] | 2010 | }
|
---|
[128] | 2011 |
|
---|
| 2012 | if (fbw) {
|
---|
| 2013 | fclose(fbw);
|
---|
[948] | 2014 | if (g_getfattr) {
|
---|
[1199] | 2015 | mr_asprintf(&xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
|
---|
[948] | 2016 | if (length_of_file(xattr_fname) > 0) {
|
---|
| 2017 | set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
|
---|
| 2018 | }
|
---|
[128] | 2019 | }
|
---|
[948] | 2020 | if (g_getfacl) {
|
---|
[1199] | 2021 | mr_asprintf(&acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
|
---|
[948] | 2022 | if (length_of_file(acl_fname) > 0) {
|
---|
| 2023 | set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
|
---|
| 2024 | }
|
---|
[128] | 2025 | }
|
---|
[1199] | 2026 | mr_free(acl_fname);
|
---|
| 2027 | mr_free(xattr_fname);
|
---|
[1] | 2028 | }
|
---|
[1199] | 2029 | mr_free(biggies_whose_EXATs_we_should_set);
|
---|
| 2030 |
|
---|
[128] | 2031 | if (does_file_exist("/PAUSE")) {
|
---|
| 2032 | popup_and_OK
|
---|
[1199] | 2033 | (_
|
---|
| 2034 | ("Press ENTER to go on. Delete /PAUSE to stop these pauses."));
|
---|
[128] | 2035 | }
|
---|
| 2036 | close_progress_form();
|
---|
| 2037 | if (retval) {
|
---|
[1199] | 2038 | mvaddstr_and_log_it(g_currentY++, 74, _("Errors."));
|
---|
[128] | 2039 | } else {
|
---|
[1199] | 2040 | mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
|
---|
[128] | 2041 | }
|
---|
[1080] | 2042 | mr_free(pathname_of_last_biggie_restored);
|
---|
[128] | 2043 | return (retval);
|
---|
[1] | 2044 | }
|
---|
[128] | 2045 |
|
---|
[1] | 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
|
---|
[128] | 2062 | restore_all_tarballs_from_CD(struct s_bkpinfo *bkpinfo,
|
---|
| 2063 | struct s_node *filelist)
|
---|
[1] | 2064 | {
|
---|
[128] | 2065 | int retval = 0;
|
---|
[1199] | 2066 | int res = 0;
|
---|
| 2067 | int attempts = 0;
|
---|
[128] | 2068 | long current_tarball_number = 0;
|
---|
[1199] | 2069 | long max_val = 0L;
|
---|
[1] | 2070 | /**malloc ***/
|
---|
[1199] | 2071 | char *tmp = NULL;
|
---|
| 2072 | char *tmp1 = NULL;
|
---|
| 2073 | char *tarball_fname = NULL;
|
---|
| 2074 | char *progress_str = NULL;
|
---|
| 2075 | char *comment = NULL;
|
---|
[1] | 2076 |
|
---|
[1199] | 2077 | malloc_string(tmp1);
|
---|
[128] | 2078 | malloc_string(tarball_fname);
|
---|
| 2079 | malloc_string(progress_str);
|
---|
| 2080 | malloc_string(comment);
|
---|
[1] | 2081 |
|
---|
[128] | 2082 | assert(bkpinfo != NULL);
|
---|
| 2083 |
|
---|
[1199] | 2084 | mvaddstr_and_log_it(g_currentY, 0, _("Restoring from archives"));
|
---|
[1108] | 2085 | mr_msg(2,
|
---|
[128] | 2086 | "Insisting on 1st CD, so that I can have a look at LAST-FILELIST-NUMBER");
|
---|
| 2087 | if (g_current_media_number != 1) {
|
---|
[1108] | 2088 | mr_msg(3, "OK, that's jacked up.");
|
---|
[128] | 2089 | g_current_media_number = 1;
|
---|
[1] | 2090 | }
|
---|
[128] | 2091 | insist_on_this_cd_number(bkpinfo, g_current_media_number);
|
---|
[1199] | 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,
|
---|
[128] | 2098 | g_current_media_number);
|
---|
| 2099 | log_to_screen(progress_str);
|
---|
[1199] | 2100 | open_progress_form(_("Restoring from archives"),
|
---|
| 2101 | _("Restoring data from the archives."),
|
---|
| 2102 | _("Please wait. This may take some time."),
|
---|
[128] | 2103 | progress_str, max_val);
|
---|
| 2104 | for (;;) {
|
---|
| 2105 | insist_on_this_cd_number(bkpinfo, g_current_media_number);
|
---|
| 2106 | update_progress_form(progress_str);
|
---|
[1199] | 2107 | mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2",
|
---|
[128] | 2108 | current_tarball_number);
|
---|
[1077] | 2109 | if (!does_file_exist(tarball_fname)) {
|
---|
[1199] | 2110 | mr_free(tarball_fname);
|
---|
| 2111 | mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo",
|
---|
[1053] | 2112 | current_tarball_number);
|
---|
[1077] | 2113 | }
|
---|
[128] | 2114 | if (!does_file_exist(tarball_fname)) {
|
---|
[1199] | 2115 | mr_free(tarball_fname);
|
---|
| 2116 | mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.afio.gz",
|
---|
[128] | 2117 | current_tarball_number);
|
---|
| 2118 | }
|
---|
| 2119 | if (!does_file_exist(tarball_fname)) {
|
---|
[1199] | 2120 | mr_free(tarball_fname);
|
---|
| 2121 | mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.afio.",
|
---|
[128] | 2122 | current_tarball_number);
|
---|
| 2123 | }
|
---|
| 2124 | if (!does_file_exist(tarball_fname)) {
|
---|
[1199] | 2125 | mr_free(tarball_fname);
|
---|
| 2126 | mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.star.bz2",
|
---|
[128] | 2127 | current_tarball_number);
|
---|
| 2128 | }
|
---|
| 2129 | if (!does_file_exist(tarball_fname)) {
|
---|
[1199] | 2130 | mr_free(tarball_fname);
|
---|
| 2131 | mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.star.",
|
---|
[128] | 2132 | current_tarball_number);
|
---|
| 2133 | }
|
---|
| 2134 | if (!does_file_exist(tarball_fname)) {
|
---|
[1199] | 2135 | mr_free(tarball_fname);
|
---|
[128] | 2136 | if (current_tarball_number == 0) {
|
---|
| 2137 | log_to_screen
|
---|
[1199] | 2138 | (_
|
---|
| 2139 | ("No tarballs. Strange. Maybe you only backed up freakin' big files?"));
|
---|
| 2140 | mr_free(progress_str);
|
---|
[128] | 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) {
|
---|
[1199] | 2147 | mr_free(tarball_fname);
|
---|
| 2148 | mr_free(progress_str);
|
---|
[128] | 2149 | break;
|
---|
| 2150 | }
|
---|
| 2151 | g_current_media_number++;
|
---|
[1199] | 2152 | mr_free(progress_str);
|
---|
| 2153 |
|
---|
| 2154 | mr_asprintf(&progress_str, _("Restoring from %s #%d"),
|
---|
| 2155 | bkpinfo->backup_media_string,
|
---|
[128] | 2156 | g_current_media_number);
|
---|
| 2157 | log_to_screen(progress_str);
|
---|
| 2158 | } else {
|
---|
[1199] | 2159 | mr_free(progress_str);
|
---|
| 2160 | mr_asprintf(&progress_str,
|
---|
| 2161 | _("Restoring from fileset #%ld on %s #%d"),
|
---|
[128] | 2162 | current_tarball_number,
|
---|
[1199] | 2163 | bkpinfo->backup_media_string,
|
---|
[128] | 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,
|
---|
[1166] | 2170 | filelist, bkpinfo);
|
---|
[128] | 2171 | }
|
---|
[1199] | 2172 | mr_asprintf(&tmp, _("%s #%d, fileset #%ld - restore "),
|
---|
[128] | 2173 | media_descriptor_string(bkpinfo->backup_media_type),
|
---|
| 2174 | g_current_media_number, current_tarball_number);
|
---|
| 2175 | if (res) {
|
---|
[1199] | 2176 | mr_strcat(tmp, _("reported errors"));
|
---|
[128] | 2177 | } else {
|
---|
[1199] | 2178 | mr_strcat(tmp, _("succeeded"));
|
---|
[128] | 2179 | }
|
---|
| 2180 | if (attempts > 1) {
|
---|
[1199] | 2181 | mr_strcat(tmp, _(" (%d attempts) - review logs"), attempts);
|
---|
[128] | 2182 | }
|
---|
| 2183 | if (attempts > 1) {
|
---|
[1199] | 2184 | log_to_screen(tmp);
|
---|
[128] | 2185 | }
|
---|
[1199] | 2186 | mr_free(tmp);
|
---|
[128] | 2187 |
|
---|
| 2188 | retval += res;
|
---|
| 2189 | current_tarball_number++;
|
---|
| 2190 | g_current_progress++;
|
---|
| 2191 | }
|
---|
[1199] | 2192 | mr_free(tarball_fname);
|
---|
[1] | 2193 | }
|
---|
[1199] | 2194 | mr_free(progress_str);
|
---|
[128] | 2195 | close_progress_form();
|
---|
[1199] | 2196 |
|
---|
[128] | 2197 | if (retval) {
|
---|
[1199] | 2198 | mvaddstr_and_log_it(g_currentY++, 74, _("Errors."));
|
---|
[128] | 2199 | } else {
|
---|
[1199] | 2200 | mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
|
---|
[1] | 2201 | }
|
---|
[128] | 2202 | return (retval);
|
---|
[1] | 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
|
---|
[128] | 2218 | restore_all_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo,
|
---|
| 2219 | struct s_node *filelist)
|
---|
[1] | 2220 | {
|
---|
[1199] | 2221 | long noof_biggiefiles = 0L;
|
---|
| 2222 | long current_bigfile_number = 0L;
|
---|
| 2223 | long total_slices = 0L;
|
---|
[1] | 2224 |
|
---|
[128] | 2225 | int retval = 0;
|
---|
| 2226 | int res = 0;
|
---|
[1199] | 2227 | int ctrl_chr = 0;
|
---|
[1] | 2228 |
|
---|
| 2229 | /** malloc add ****/
|
---|
[1199] | 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;
|
---|
[1] | 2239 |
|
---|
[1199] | 2240 | assert(bkpinfo != NULL);
|
---|
| 2241 |
|
---|
[128] | 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);
|
---|
[1199] | 2247 | total_slices = atol(tmp);
|
---|
| 2248 | mr_free(tmp);
|
---|
[1] | 2249 |
|
---|
[1199] | 2250 | mr_asprintf(&tmp, "Reassembling large files ");
|
---|
[948] | 2251 | if (g_getfattr) {
|
---|
[1199] | 2252 | mr_asprintf(&xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
|
---|
[948] | 2253 | }
|
---|
| 2254 | if (g_getfacl) {
|
---|
[1199] | 2255 | mr_asprintf(&acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
|
---|
[948] | 2256 | }
|
---|
[128] | 2257 | mvaddstr_and_log_it(g_currentY, 0, tmp);
|
---|
[1199] | 2258 | mr_free(tmp);
|
---|
| 2259 |
|
---|
| 2260 | mr_asprintf(&biggies_whose_EXATs_we_should_set,
|
---|
[128] | 2261 | "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
|
---|
| 2262 | if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
|
---|
[1108] | 2263 | mr_msg(1, "Warning - cannot openout %s",
|
---|
[128] | 2264 | biggies_whose_EXATs_we_should_set);
|
---|
| 2265 | }
|
---|
[1199] | 2266 | // get xattr and acl files if they're there
|
---|
[128] | 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 | }
|
---|
[1] | 2275 |
|
---|
[128] | 2276 | noof_biggiefiles = atol(biggie_fname);
|
---|
[1199] | 2277 | mr_msg(2, "OK, there are %ld biggiefiles in the archives",
|
---|
[128] | 2278 | noof_biggiefiles);
|
---|
[1199] | 2279 | open_progress_form(_("Reassembling large files"),
|
---|
| 2280 | _("I am now reassembling all the large files."),
|
---|
| 2281 | _("Please wait. This may take some time."),
|
---|
[128] | 2282 | "", total_slices);
|
---|
[1] | 2283 |
|
---|
[128] | 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 | }
|
---|
[1199] | 2295 | /* BERLIOS: useless
|
---|
[128] | 2296 | p = strrchr(biggie_fname, '/');
|
---|
| 2297 | if (!p) {
|
---|
| 2298 | p = biggie_fname;
|
---|
| 2299 | } else {
|
---|
| 2300 | p++;
|
---|
| 2301 | }
|
---|
[1199] | 2302 | */
|
---|
| 2303 | mr_asprintf(&tmp, _("Restoring big file %ld (%lld K)"),
|
---|
[128] | 2304 | current_bigfile_number + 1, biggie_size / 1024);
|
---|
| 2305 | update_progress_form(tmp);
|
---|
[1199] | 2306 | mr_free(tmp);
|
---|
| 2307 |
|
---|
[128] | 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);
|
---|
[1108] | 2314 | mr_msg(1, "I believe I have restored %s",
|
---|
[128] | 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 | }
|
---|
[1199] | 2319 | mr_free(pathname_of_last_biggie_restored);
|
---|
| 2320 |
|
---|
[128] | 2321 | retval += res;
|
---|
| 2322 | current_bigfile_number++;
|
---|
| 2323 |
|
---|
[1] | 2324 | }
|
---|
[128] | 2325 | if (current_bigfile_number != noof_biggiefiles
|
---|
| 2326 | && noof_biggiefiles != 0) {
|
---|
[1199] | 2327 | mr_msg(1, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n",
|
---|
[128] | 2328 | current_bigfile_number, noof_biggiefiles);
|
---|
| 2329 | } else {
|
---|
[1199] | 2330 | mr_msg(1, "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.",
|
---|
[128] | 2331 | noof_biggiefiles, current_bigfile_number);
|
---|
[1] | 2332 | }
|
---|
| 2333 |
|
---|
[128] | 2334 | if (fbw) {
|
---|
| 2335 | fclose(fbw);
|
---|
| 2336 | if (length_of_file(biggies_whose_EXATs_we_should_set) > 2) {
|
---|
| 2337 | iamhere("Setting biggie-EXATs");
|
---|
[948] | 2338 | if (g_getfattr) {
|
---|
| 2339 | if (length_of_file(xattr_fname) > 0) {
|
---|
[1108] | 2340 | mr_msg(1, "set_fattr_List(%s,%s)",
|
---|
[128] | 2341 | biggies_whose_EXATs_we_should_set, xattr_fname);
|
---|
[948] | 2342 | set_fattr_list(biggies_whose_EXATs_we_should_set,
|
---|
[128] | 2343 | xattr_fname);
|
---|
[948] | 2344 | }
|
---|
[128] | 2345 | }
|
---|
[948] | 2346 | if (g_getfacl) {
|
---|
| 2347 | if (length_of_file(acl_fname) > 0) {
|
---|
[1108] | 2348 | mr_msg(1, "set_acl_list(%s,%s)",
|
---|
[948] | 2349 | biggies_whose_EXATs_we_should_set, acl_fname);
|
---|
| 2350 | set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
|
---|
| 2351 | }
|
---|
| 2352 | }
|
---|
[128] | 2353 | } else {
|
---|
| 2354 | iamhere
|
---|
| 2355 | ("No biggiefiles selected. So, no biggie-EXATs to set.");
|
---|
| 2356 | }
|
---|
[1] | 2357 | }
|
---|
[1199] | 2358 | mr_free(xattr_fname);
|
---|
| 2359 | mr_free(acl_fname);
|
---|
| 2360 | mr_free(biggies_whose_EXATs_we_should_set);
|
---|
| 2361 |
|
---|
[128] | 2362 | if (does_file_exist("/PAUSE")) {
|
---|
| 2363 | popup_and_OK
|
---|
[1199] | 2364 | (_
|
---|
| 2365 | ("Press ENTER to go on. Delete /PAUSE to stop these pauses."));
|
---|
[1] | 2366 | }
|
---|
| 2367 |
|
---|
[128] | 2368 | close_progress_form();
|
---|
| 2369 | if (retval) {
|
---|
[1199] | 2370 | mvaddstr_and_log_it(g_currentY++, 74, _("Errors."));
|
---|
[128] | 2371 | } else {
|
---|
[1199] | 2372 | mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
|
---|
[128] | 2373 | }
|
---|
[1080] | 2374 | mr_free(biggie_fname);
|
---|
| 2375 | mr_free(biggie_cksum);
|
---|
[128] | 2376 | return (retval);
|
---|
[1] | 2377 | }
|
---|
[128] | 2378 |
|
---|
[1] | 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
|
---|
[128] | 2395 | restore_all_tarballs_from_stream(struct s_bkpinfo *bkpinfo,
|
---|
| 2396 | struct s_node *filelist)
|
---|
[1] | 2397 | {
|
---|
[128] | 2398 | int retval = 0;
|
---|
[1199] | 2399 | int res = 0;
|
---|
[128] | 2400 | long current_afioball_number = 0;
|
---|
[1199] | 2401 | int ctrl_chr = 0;
|
---|
| 2402 | long max_val = 0L /*, total_noof_files */ ;
|
---|
[1] | 2403 |
|
---|
| 2404 | /** malloc **/
|
---|
[1199] | 2405 | char *tmp = NULL;
|
---|
| 2406 | char *progress_str = NULL;
|
---|
| 2407 | char *tmp_fname = NULL;
|
---|
| 2408 | char *xattr_fname = NULL;
|
---|
| 2409 | char *acl_fname = NULL;
|
---|
[1] | 2410 |
|
---|
[1199] | 2411 | long long tmp_size = 0L;
|
---|
[1] | 2412 |
|
---|
[1199] | 2413 | malloc_string(tmp_fname);
|
---|
[128] | 2414 | malloc_string(tmp);
|
---|
| 2415 | assert(bkpinfo != NULL);
|
---|
[1199] | 2416 | mvaddstr_and_log_it(g_currentY, 0, _("Restoring from archives"));
|
---|
[128] | 2417 | read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
|
---|
| 2418 | max_val = atol(tmp) + 1;
|
---|
[1199] | 2419 | mr_free(tmp);
|
---|
[1] | 2420 |
|
---|
[128] | 2421 | chdir(bkpinfo->restore_path); /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */
|
---|
[1] | 2422 |
|
---|
[128] | 2423 | run_program_and_log_output("pwd", 5);
|
---|
[1] | 2424 |
|
---|
[1199] | 2425 | mr_asprintf(&progress_str, _("Restoring from media #%d"),
|
---|
[128] | 2426 | g_current_media_number);
|
---|
| 2427 | log_to_screen(progress_str);
|
---|
[1199] | 2428 | open_progress_form(_("Restoring from archives"),
|
---|
| 2429 | _("Restoring data from the archives."),
|
---|
| 2430 | _("Please wait. This may take some time."),
|
---|
[128] | 2431 | progress_str, max_val);
|
---|
[1] | 2432 |
|
---|
[1108] | 2433 | mr_msg(3, "hey");
|
---|
[1] | 2434 |
|
---|
[128] | 2435 | res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
|
---|
| 2436 | if (res) {
|
---|
[1108] | 2437 | mr_msg(2, "Warning - error reading afioball from tape");
|
---|
[1] | 2438 | }
|
---|
[128] | 2439 | retval += res;
|
---|
| 2440 | if (ctrl_chr != BLK_START_AFIOBALLS) {
|
---|
| 2441 | wrong_marker(BLK_START_AFIOBALLS, ctrl_chr);
|
---|
[1] | 2442 | }
|
---|
[1108] | 2443 | mr_msg(2, "ho");
|
---|
[128] | 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);
|
---|
[948] | 2447 | if (g_getfattr) {
|
---|
[1199] | 2448 | mr_asprintf(&xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir,
|
---|
[128] | 2449 | current_afioball_number);
|
---|
[948] | 2450 | unlink(xattr_fname);
|
---|
| 2451 | }
|
---|
| 2452 | if (g_getfacl) {
|
---|
[1199] | 2453 | mr_asprintf(&acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir,
|
---|
[128] | 2454 | current_afioball_number);
|
---|
[948] | 2455 | unlink(acl_fname);
|
---|
| 2456 | }
|
---|
[128] | 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 | }
|
---|
[1199] | 2467 | /* BERLIOS: useless ?
|
---|
| 2468 | mr_asprintf(&tmp,
|
---|
| 2469 | _("Restoring from fileset #%ld (name=%s, size=%ld K)"),
|
---|
[128] | 2470 | current_afioball_number, tmp_fname, (long) tmp_size >> 10);
|
---|
[1199] | 2471 | */
|
---|
[128] | 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) {
|
---|
[1199] | 2479 | log_to_screen("Fileset %ld - errors occurred",
|
---|
[128] | 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 | }
|
---|
[1] | 2487 |
|
---|
[128] | 2488 | current_afioball_number++;
|
---|
| 2489 | g_current_progress++;
|
---|
[1199] | 2490 |
|
---|
| 2491 | mr_free(progress_str);
|
---|
| 2492 | mr_asprintf(&progress_str, _("Restoring from fileset #%ld on %s #%d"),
|
---|
[128] | 2493 | current_afioball_number,
|
---|
[1199] | 2494 | bkpinfo->backup_media_string,
|
---|
[128] | 2495 | g_current_media_number);
|
---|
| 2496 | res =
|
---|
| 2497 | read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
|
---|
[948] | 2498 | if (g_getfattr) {
|
---|
| 2499 | unlink(xattr_fname);
|
---|
| 2500 | }
|
---|
| 2501 | if (g_getfacl) {
|
---|
| 2502 | unlink(acl_fname);
|
---|
| 2503 | }
|
---|
[1199] | 2504 | mr_free(xattr_fname);
|
---|
| 2505 | mr_free(acl_fname);
|
---|
[128] | 2506 | } // next
|
---|
[1199] | 2507 | mr_free(progress_str);
|
---|
| 2508 | mr_free(tmp_fname);
|
---|
| 2509 |
|
---|
[1108] | 2510 | mr_msg(1, "All done with afioballs");
|
---|
[128] | 2511 | close_progress_form();
|
---|
| 2512 | if (retval) {
|
---|
[1199] | 2513 | mvaddstr_and_log_it(g_currentY++, 74, _("Errors."));
|
---|
[128] | 2514 | } else {
|
---|
[1199] | 2515 | mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
|
---|
[128] | 2516 | }
|
---|
| 2517 | return (retval);
|
---|
[1] | 2518 | }
|
---|
[128] | 2519 |
|
---|
[1] | 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 | */
|
---|
[128] | 2535 | int restore_everything(struct s_bkpinfo *bkpinfo, struct s_node *filelist)
|
---|
[1] | 2536 | {
|
---|
[128] | 2537 | int resA;
|
---|
| 2538 | int resB;
|
---|
[1] | 2539 |
|
---|
| 2540 | /** mallco ***/
|
---|
[1199] | 2541 | char *cwd = NULL;
|
---|
| 2542 | char *newpath = NULL;
|
---|
| 2543 | char *tmp = NULL;
|
---|
[128] | 2544 | assert(bkpinfo != NULL);
|
---|
[1] | 2545 |
|
---|
[128] | 2546 | malloc_string(cwd);
|
---|
| 2547 | malloc_string(newpath);
|
---|
[1108] | 2548 | mr_msg(2, "restore_everything() --- starting");
|
---|
[128] | 2549 | g_current_media_number = 1;
|
---|
[1199] | 2550 | /* BERLIOS: should test return value, or better change the function */
|
---|
[128] | 2551 | getcwd(cwd, MAX_STR_LEN - 1);
|
---|
[1199] | 2552 | mr_asprintf(&tmp, "mkdir -p %s", bkpinfo->restore_path);
|
---|
[128] | 2553 | run_program_and_log_output(tmp, FALSE);
|
---|
[1199] | 2554 | mr_free(tmp);
|
---|
| 2555 |
|
---|
[1108] | 2556 | mr_msg(1, "Changing dir to %s", bkpinfo->restore_path);
|
---|
[128] | 2557 | chdir(bkpinfo->restore_path);
|
---|
[1199] | 2558 | /* BERLIOS: should test return value, or better change the function */
|
---|
[128] | 2559 | getcwd(newpath, MAX_STR_LEN - 1);
|
---|
[1108] | 2560 | mr_msg(1, "path is now %s", newpath);
|
---|
| 2561 | mr_msg(1, "restoring everything");
|
---|
[128] | 2562 | if (!find_home_of_exe("petris") && !g_text_mode) {
|
---|
| 2563 | newtDrawRootText(0, g_noof_rows - 2,
|
---|
[1199] | 2564 | _
|
---|
| 2565 | ("Press ALT-<left cursor> twice to play Petris :-) "));
|
---|
[128] | 2566 | newtRefresh();
|
---|
[1] | 2567 | }
|
---|
[1199] | 2568 | mvaddstr_and_log_it(g_currentY, 0, _("Preparing to read your archives"));
|
---|
[128] | 2569 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 2570 | mount_cdrom(bkpinfo);
|
---|
| 2571 | mvaddstr_and_log_it(g_currentY++, 0,
|
---|
[1199] | 2572 | _
|
---|
| 2573 | ("Restoring OS and data from streaming media"));
|
---|
[128] | 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,
|
---|
[1199] | 2590 | _("Restoring OS and data from CD "));
|
---|
[128] | 2591 | mount_cdrom(bkpinfo);
|
---|
| 2592 | resA = restore_all_tarballs_from_CD(bkpinfo, filelist);
|
---|
| 2593 | resB = restore_all_biggiefiles_from_CD(bkpinfo, filelist);
|
---|
[1] | 2594 | }
|
---|
[128] | 2595 | chdir(cwd);
|
---|
| 2596 | if (resA + resB) {
|
---|
[1199] | 2597 | log_to_screen(_("Errors occurred while data was being restored."));
|
---|
[1] | 2598 | }
|
---|
[128] | 2599 | if (length_of_file("/etc/raidtab") > 0) {
|
---|
[1108] | 2600 | mr_msg(2, "Copying local raidtab to restored filesystem");
|
---|
[128] | 2601 | run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING
|
---|
| 2602 | "/etc/raidtab", FALSE);
|
---|
[1] | 2603 | }
|
---|
[128] | 2604 | kill_petris();
|
---|
[1108] | 2605 | mr_msg(2, "restore_everything() --- leaving");
|
---|
[1080] | 2606 | mr_free(cwd);
|
---|
| 2607 | mr_free(newpath);
|
---|
[128] | 2608 | return (resA + resB);
|
---|
[1] | 2609 | }
|
---|
| 2610 |
|
---|
| 2611 | /**************************************************************************
|
---|
| 2612 | *END_RESTORE_EVERYTHING *
|
---|
| 2613 | **************************************************************************/
|
---|
| 2614 |
|
---|
| 2615 |
|
---|
| 2616 | /**
|
---|
| 2617 | * @brief Haha. You wish! (This function is not implemented :-)
|
---|
| 2618 | */
|
---|
| 2619 | int
|
---|
[128] | 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" */
|
---|
[1] | 2625 | {
|
---|
[128] | 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;
|
---|
[1] | 2632 | /** malloc **/
|
---|
[128] | 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);
|
---|
[1] | 2645 |
|
---|
[128] | 2646 | sprintf(tmp, "restore_here = '%s'", restore_here);
|
---|
[1] | 2647 |
|
---|
[1108] | 2648 | mr_msg(2, tmp);
|
---|
[1] | 2649 |
|
---|
[1108] | 2650 | mr_msg(2, "restore_live_from_monitas_server() - starting");
|
---|
[128] | 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 | }
|
---|
[1108] | 2659 | mr_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
|
---|
[128] | 2660 | sprintf(tmp, "FYI - data will be restored to %s",
|
---|
| 2661 | bkpinfo->restore_path);
|
---|
[1108] | 2662 | mr_msg(3, tmp);
|
---|
| 2663 | mr_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
|
---|
[128] | 2664 | sprintf(datadisks_fname, "/tmp/mondorestore.datadisks.%d",
|
---|
| 2665 | (int) (random() % 32768));
|
---|
| 2666 | chdir(bkpinfo->tmpdir);
|
---|
[1] | 2667 |
|
---|
[128] | 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);
|
---|
[1] | 2691 |
|
---|
[128] | 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,
|
---|
[911] | 2701 | "grep -E '^%s.*$' %s > %s",
|
---|
[273] | 2702 | restore_this_directory, g_filelist_full, g_filelist_full);
|
---|
[128] | 2703 | if (system(command)) {
|
---|
| 2704 | retval++;
|
---|
| 2705 | log_to_screen
|
---|
[541] | 2706 | ("Error(s) occurred while processing filelist and wildcard");
|
---|
[128] | 2707 | }
|
---|
| 2708 | iamhere("FIXME");
|
---|
| 2709 | fatal_error("This will fail");
|
---|
| 2710 | sprintf(command,
|
---|
[911] | 2711 | "grep -E '^%s.*$' %s > %s",
|
---|
[273] | 2712 | restore_this_directory, g_biggielist_txt, g_biggielist_txt);
|
---|
[128] | 2713 | if (system(command)) {
|
---|
[1108] | 2714 | mr_msg(1,
|
---|
[128] | 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);
|
---|
[1] | 2719 | // filelist = load_filelist(g_filelist_restthese); // FIXME --- this probably doesn't work because it doesn't include the biggiefiles
|
---|
[128] | 2720 | retval += restore_everything(bkpinfo, filelist);
|
---|
| 2721 | free_filelist(filelist);
|
---|
[1108] | 2722 | mr_msg(2, "--------End of restore_live_from_monitas_server--------");
|
---|
[128] | 2723 | return (retval);
|
---|
[1] | 2724 | }
|
---|
[128] | 2725 |
|
---|
[1] | 2726 | /**************************************************************************
|
---|
| 2727 | *END_RESTORE_LIVE_FROM_MONITAS_SERVER *
|
---|
| 2728 | **************************************************************************/
|
---|
| 2729 |
|
---|
| 2730 |
|
---|
| 2731 |
|
---|
| 2732 |
|
---|
[128] | 2733 | extern void wait_until_software_raids_are_prepped(char *, int);
|
---|
[1] | 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 | {
|
---|
[1108] | 2743 | mr_msg(0, "-------------- Mondo Restore v%s -------------", PACKAGE_VERSION);
|
---|
| 2744 | mr_msg(0,
|
---|
[128] | 2745 | "DON'T PANIC! Mondorestore logs almost everything, so please ");
|
---|
[1108] | 2746 | mr_msg(0,
|
---|
[128] | 2747 | "don't break out in a cold sweat just because you see a few ");
|
---|
[1108] | 2748 | mr_msg(0,
|
---|
[128] | 2749 | "error messages in the log. Read them; analyze them; see if ");
|
---|
[1108] | 2750 | mr_msg(0,
|
---|
[128] | 2751 | "they are significant; above all, verify your backups! Please");
|
---|
[1108] | 2752 | mr_msg(0,
|
---|
[128] | 2753 | "attach a compressed copy of this log to any e-mail you send ");
|
---|
[1108] | 2754 | mr_msg(0,
|
---|
[128] | 2755 | "to the Mondo mailing list when you are seeking technical ");
|
---|
[1108] | 2756 | mr_msg(0,
|
---|
[607] | 2757 | "support. Without it, we can't help you. - DevTeam");
|
---|
[1108] | 2758 | mr_msg(0,
|
---|
[128] | 2759 | "------------------------------------------------------------");
|
---|
[1108] | 2760 | mr_msg(0,
|
---|
[128] | 2761 | "BTW, despite (or perhaps because of) the wealth of messages,");
|
---|
[1108] | 2762 | mr_msg(0,
|
---|
[128] | 2763 | "some users are inclined to stop reading this log. If Mondo ");
|
---|
[1108] | 2764 | mr_msg(0,
|
---|
[128] | 2765 | "stopped for some reason, chances are it's detailed here. ");
|
---|
[1108] | 2766 | mr_msg(0,
|
---|
[1199] | 2767 | "More than likely there's a message near the end of this ");
|
---|
[1108] | 2768 | mr_msg(0,
|
---|
[128] | 2769 | "log that will tell you what is wrong. Please read it! ");
|
---|
[1108] | 2770 | mr_msg(0,
|
---|
[128] | 2771 | "------------------------------------------------------------");
|
---|
[1] | 2772 | }
|
---|
| 2773 |
|
---|
| 2774 |
|
---|
| 2775 | /**
|
---|
| 2776 | * Restore the user's data.
|
---|
| 2777 | * What did you think it did, anyway? :-)
|
---|
| 2778 | */
|
---|
[128] | 2779 | int main(int argc, char *argv[])
|
---|
[1] | 2780 | {
|
---|
[1199] | 2781 | FILE *fin = NULL;
|
---|
| 2782 | FILE *fout = NULL;
|
---|
[128] | 2783 | int retval = 0;
|
---|
[1199] | 2784 | int res = 0;
|
---|
| 2785 | char *tmp = NULL;
|
---|
[1] | 2786 |
|
---|
[1199] | 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;
|
---|
[818] | 2792 | bool run_postnuke = FALSE;
|
---|
[1] | 2793 |
|
---|
[1199] | 2794 | #ifdef ENABLE_NLS
|
---|
| 2795 | setlocale(LC_ALL, "");
|
---|
| 2796 | (void) textdomain("mondo");
|
---|
| 2797 | #endif
|
---|
| 2798 |
|
---|
[128] | 2799 | if (getuid() != 0) {
|
---|
[1199] | 2800 | fprintf(stderr, _("Please run as root.\n"));
|
---|
[128] | 2801 | exit(127);
|
---|
| 2802 | }
|
---|
[1] | 2803 |
|
---|
[128] | 2804 | g_loglevel = DEFAULT_MR_LOGLEVEL;
|
---|
| 2805 |
|
---|
[1] | 2806 | /* Configure global variables */
|
---|
| 2807 | #ifdef __FreeBSD__
|
---|
[128] | 2808 | if (strstr
|
---|
| 2809 | (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
|
---|
| 2810 | "textonly"))
|
---|
[1] | 2811 | #else
|
---|
[128] | 2812 | if (strstr
|
---|
| 2813 | (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
|
---|
| 2814 | "textonly"))
|
---|
[1] | 2815 | #endif
|
---|
[128] | 2816 | {
|
---|
| 2817 | g_text_mode = TRUE;
|
---|
[1108] | 2818 | mr_msg(1, "TEXTONLY MODE");
|
---|
[128] | 2819 | } else {
|
---|
| 2820 | g_text_mode = FALSE;
|
---|
| 2821 | } // newt :-)
|
---|
[1166] | 2822 | bkpinfo = mr_malloc(sizeof(struct s_bkpinfo));
|
---|
[1080] | 2823 | mountlist = mr_malloc(sizeof(struct mountlist_itself));
|
---|
| 2824 | raidlist = mr_malloc(sizeof(struct raidlist_itself));
|
---|
[1] | 2825 |
|
---|
[128] | 2826 | malloc_libmondo_global_strings();
|
---|
[1] | 2827 |
|
---|
[128] | 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
|
---|
[1] | 2833 |
|
---|
[128] | 2834 | run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE);
|
---|
| 2835 | run_program_and_log_output("mkdir -p /mnt/floppy", FALSE);
|
---|
[1] | 2836 |
|
---|
[128] | 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
|
---|
[1199] | 2842 | bkpinfo->backup_media_string = NULL;
|
---|
[128] | 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();
|
---|
[1] | 2852 |
|
---|
[1108] | 2853 | mr_msg(1, "FYI - g_mountlist_fname = %s", g_mountlist_fname);
|
---|
[128] | 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 |
|
---|
[1] | 2860 | /* Backup original mountlist.txt */
|
---|
[1199] | 2861 | mr_asprintf(&tmp, "%s.orig", g_mountlist_fname);
|
---|
[128] | 2862 | if (!does_file_exist(g_mountlist_fname)) {
|
---|
[1108] | 2863 | mr_msg(2,
|
---|
[128] | 2864 | "%ld: Warning - g_mountlist_fname (%s) does not exist yet",
|
---|
| 2865 | __LINE__, g_mountlist_fname);
|
---|
| 2866 | } else if (!does_file_exist(tmp)) {
|
---|
[1199] | 2867 | mr_free(tmp);
|
---|
| 2868 | mr_asprintf(&tmp, "cp -f %s %s.orig", g_mountlist_fname,
|
---|
[128] | 2869 | g_mountlist_fname);
|
---|
| 2870 | run_program_and_log_output(tmp, FALSE);
|
---|
| 2871 | }
|
---|
[1199] | 2872 | mr_free(tmp);
|
---|
[1] | 2873 |
|
---|
| 2874 | /* Init directories */
|
---|
[128] | 2875 | make_hole_for_dir(bkpinfo->tmpdir);
|
---|
[1199] | 2876 | mr_asprintf(&tmp, "mkdir -p %s", bkpinfo->tmpdir);
|
---|
[128] | 2877 | run_program_and_log_output(tmp, FALSE);
|
---|
[1199] | 2878 | mr_free(tmp);
|
---|
| 2879 |
|
---|
[128] | 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);
|
---|
[1] | 2886 |
|
---|
[128] | 2887 | run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE);
|
---|
[1] | 2888 |
|
---|
[1199] | 2889 | /* Init GUI */
|
---|
[128] | 2890 | malloc_libmondo_global_strings();
|
---|
| 2891 | setup_newt_stuff(); /* call newtInit and setup screen log */
|
---|
| 2892 | welcome_to_mondorestore();
|
---|
| 2893 | if (bkpinfo->disaster_recovery) {
|
---|
[1108] | 2894 | mr_msg(1, "I am in disaster recovery mode");
|
---|
[128] | 2895 | } else {
|
---|
[1108] | 2896 | mr_msg(1, "I am in normal, live mode");
|
---|
[128] | 2897 | }
|
---|
[1] | 2898 |
|
---|
[128] | 2899 | iamhere("what time is it");
|
---|
[1] | 2900 |
|
---|
[1199] | 2901 | /* Process command-line parameters */
|
---|
[128] | 2902 | if (argc == 2 && strcmp(argv[1], "--edit-mountlist") == 0) {
|
---|
[1] | 2903 | #ifdef __FreeBSD__
|
---|
[128] | 2904 | system("mv -f /tmp/raidconf.txt /etc/raidtab");
|
---|
| 2905 | if (!does_file_exist("/etc/raidtab"))
|
---|
| 2906 | system("vinum printconfig > /etc/raidtab");
|
---|
[1] | 2907 | #endif
|
---|
[128] | 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);
|
---|
[1] | 2913 | #ifdef __FreeBSD__
|
---|
[128] | 2914 | system("mv -f /etc/raidtab /tmp/raidconf.txt");
|
---|
[1] | 2915 | #endif
|
---|
[128] | 2916 | paranoid_MR_finish(res);
|
---|
| 2917 | }
|
---|
[1] | 2918 |
|
---|
[128] | 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 | }
|
---|
[1] | 2925 |
|
---|
[128] | 2926 | if (argc == 3 && strcmp(argv[1], "--gendf") == 0) {
|
---|
| 2927 | make_grub_install_scriptlet(argv[2]);
|
---|
| 2928 | finish(0);
|
---|
| 2929 | }
|
---|
[1] | 2930 |
|
---|
[128] | 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;
|
---|
[1199] | 2939 | open_progress_form(_("Reassembling /dev/hda1"),
|
---|
| 2940 | _("Shark is a bit of a silly person."),
|
---|
| 2941 | _("Please wait. This may take some time."),
|
---|
[128] | 2942 | "", 1999);
|
---|
| 2943 | system("rm -Rf /tmp/*pih*");
|
---|
[1] | 2944 |
|
---|
[1199] | 2945 | malloc_string(tmp);
|
---|
[128] | 2946 | restore_a_biggiefile_from_CD(bkpinfo, 42, NULL, tmp);
|
---|
[1199] | 2947 | mr_free(tmp);
|
---|
[128] | 2948 | }
|
---|
[1] | 2949 |
|
---|
[128] | 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);
|
---|
[179] | 2958 | // BERLIOS: /usr/lib ???
|
---|
[128] | 2959 | toggle_path_selection(filelist, "/usr/share", TRUE);
|
---|
| 2960 | save_filelist(filelist, "/tmp/out.txt");
|
---|
[1199] | 2961 | mr_asprintf(&a, argv[3]);
|
---|
| 2962 | mr_asprintf(&b, argv[4]);
|
---|
[1] | 2963 |
|
---|
[128] | 2964 | res = save_filelist_entries_in_common(a, filelist, b, FALSE);
|
---|
| 2965 | free_filelist(filelist);
|
---|
[1199] | 2966 | mr_free(a);
|
---|
| 2967 | mr_free(b);
|
---|
[128] | 2968 | printf("res = %d", res);
|
---|
| 2969 | finish(0);
|
---|
| 2970 | }
|
---|
[1] | 2971 |
|
---|
[128] | 2972 | if (argc == 3 && strcmp(argv[1], "--popuplist") == 0) {
|
---|
| 2973 | popup_changelist_from_file(argv[2]);
|
---|
| 2974 | paranoid_MR_finish(0);
|
---|
| 2975 | }
|
---|
[1] | 2976 |
|
---|
[128] | 2977 | if (argc == 5 && strcmp(argv[1], "--copy") == 0) {
|
---|
[1108] | 2978 | mr_msg(1, "SCORE");
|
---|
[128] | 2979 | g_loglevel = 10;
|
---|
| 2980 | if (strstr(argv[2], "save")) {
|
---|
[1108] | 2981 | mr_msg(1, "Saving from %s to %s", argv[3], argv[4]);
|
---|
[128] | 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 | }
|
---|
[1] | 3004 |
|
---|
[128] | 3005 | if (argc == 3 && strcmp(argv[1], "--mdstat") == 0) {
|
---|
| 3006 | wait_until_software_raids_are_prepped(argv[2], 100);
|
---|
| 3007 | finish(0);
|
---|
| 3008 | }
|
---|
[1] | 3009 |
|
---|
[558] | 3010 | if (argc == 3 && strcmp(argv[1], "--mdconv") == 0) {
|
---|
| 3011 | finish(create_raidtab_from_mdstat(argv[2]));
|
---|
[128] | 3012 | }
|
---|
[1] | 3013 |
|
---|
[128] | 3014 |
|
---|
| 3015 | if (argc == 2 && strcmp(argv[1], "--live-grub") == 0) {
|
---|
| 3016 | retval = run_grub(FALSE, "/dev/hda");
|
---|
| 3017 | if (retval) {
|
---|
[1199] | 3018 | log_to_screen(_("Failed to write Master Boot Record"));
|
---|
[128] | 3019 | }
|
---|
| 3020 | paranoid_MR_finish(0);
|
---|
[1] | 3021 | }
|
---|
[128] | 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
|
---|
[1199] | 3029 | (_
|
---|
| 3030 | ("Live mode doesn't support command-line parameters yet."));
|
---|
[128] | 3031 | paranoid_MR_finish(1);
|
---|
| 3032 | }
|
---|
[1108] | 3033 | mr_msg(1, "I am in normal, live mode.");
|
---|
| 3034 | mr_msg(2, "FYI, MOUNTLIST_FNAME = %s", g_mountlist_fname);
|
---|
[128] | 3035 | mount_boot_if_necessary(); /* for Gentoo users */
|
---|
[1108] | 3036 | mr_msg(2, "Still here.");
|
---|
[128] | 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 {
|
---|
[1108] | 3046 | mr_msg(2, "Calling restore_to_live_filesystem()");
|
---|
[128] | 3047 | retval = restore_to_live_filesystem(bkpinfo);
|
---|
| 3048 | }
|
---|
[1108] | 3049 | mr_msg(2, "Still here. Yay.");
|
---|
[128] | 3050 | if (strlen(bkpinfo->tmpdir) > 0) {
|
---|
[1199] | 3051 | mr_asprintf(&tmp, "rm -Rf %s/*", bkpinfo->tmpdir);
|
---|
[128] | 3052 | run_program_and_log_output(tmp, FALSE);
|
---|
[1199] | 3053 | mr_free(tmp);
|
---|
[128] | 3054 | }
|
---|
| 3055 | unmount_boot_if_necessary(); /* for Gentoo users */
|
---|
| 3056 | paranoid_MR_finish(retval);
|
---|
| 3057 | } else {
|
---|
[804] | 3058 | /* Disaster recovery mode (must be) */
|
---|
[1108] | 3059 | mr_msg(1, "I must be in disaster recovery mode.");
|
---|
| 3060 | mr_msg(2, "FYI, MOUNTLIST_FNAME = %s ", g_mountlist_fname);
|
---|
[128] | 3061 | if (argc == 3 && strcmp(argv[1], "--monitas-memorex") == 0) {
|
---|
[1199] | 3062 | log_to_screen(_("Uh, that hasn't been implemented yet."));
|
---|
[128] | 3063 | paranoid_MR_finish(1);
|
---|
| 3064 | }
|
---|
[1] | 3065 |
|
---|
[128] | 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");
|
---|
[1] | 3073 |
|
---|
[128] | 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)) {
|
---|
[1108] | 3079 | mr_msg(1, "Mounting nfs dir");
|
---|
[128] | 3080 | sprintf(bkpinfo->isodir, "/tmp/isodir");
|
---|
| 3081 | run_program_and_log_output("mkdir -p /tmp/isodir", 5);
|
---|
[1199] | 3082 | mr_asprintf(&tmp, "mount %s -t nfs -o nolock /tmp/isodir",
|
---|
[128] | 3083 | bkpinfo->nfs_mount);
|
---|
| 3084 | run_program_and_log_output(tmp, 1);
|
---|
[1199] | 3085 | mr_free(tmp);
|
---|
[128] | 3086 | }
|
---|
| 3087 | }
|
---|
[1] | 3088 |
|
---|
| 3089 |
|
---|
[128] | 3090 | if (retval) {
|
---|
| 3091 | log_to_screen
|
---|
[1199] | 3092 | (_
|
---|
| 3093 | ("Warning - load_raidtab_into_raidlist returned an error"));
|
---|
[128] | 3094 | }
|
---|
[1] | 3095 |
|
---|
| 3096 |
|
---|
[1108] | 3097 | mr_msg(1, "Send in the clowns.");
|
---|
[1] | 3098 |
|
---|
[128] | 3099 | if (argc == 2 && strcmp(argv[1], "--partition-only") == 0) {
|
---|
[1108] | 3100 | mr_msg(0, "Partitioning only.");
|
---|
[128] | 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 | }
|
---|
[1] | 3107 |
|
---|
[128] | 3108 | if (argc == 2 && strcmp(argv[1], "--format-only") == 0) {
|
---|
[1108] | 3109 | mr_msg(0, "Formatting only.");
|
---|
[128] | 3110 | load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
|
---|
| 3111 | strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
|
---|
| 3112 | load_mountlist(mountlist, g_mountlist_fname);
|
---|
[558] | 3113 | res = format_everything(mountlist, FALSE, raidlist);
|
---|
[128] | 3114 | finish(res);
|
---|
| 3115 | }
|
---|
[1] | 3116 |
|
---|
[128] | 3117 | if (argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0) {
|
---|
[1108] | 3118 | mr_msg(0, "Stopping LVM and RAID");
|
---|
[128] | 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) {
|
---|
[1199] | 3147 | log_to_screen(_("Failed to write Master Boot Record"));
|
---|
[128] | 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) {
|
---|
[1199] | 3153 | log_to_screen(_("Invalid paremeters"));
|
---|
[128] | 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 | }
|
---|
[1] | 3159 | }
|
---|
[128] | 3160 |
|
---|
| 3161 | /* clean up at the end */
|
---|
| 3162 | if (retval) {
|
---|
| 3163 | if (does_file_exist("/tmp/changed.files")) {
|
---|
| 3164 | log_to_screen
|
---|
[1199] | 3165 | (_
|
---|
| 3166 | ("See /tmp/changed.files for list of files that have changed."));
|
---|
[128] | 3167 | }
|
---|
| 3168 | mvaddstr_and_log_it(g_currentY++,
|
---|
| 3169 | 0,
|
---|
[1199] | 3170 | _
|
---|
| 3171 | ("Run complete. Errors were reported. Please review the logfile."));
|
---|
[128] | 3172 | } else {
|
---|
| 3173 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 3174 | mvaddstr_and_log_it(g_currentY++,
|
---|
| 3175 | 0,
|
---|
[1199] | 3176 | _
|
---|
| 3177 | ("Run complete. Please remove floppy/CD/media and reboot."));
|
---|
[128] | 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,
|
---|
[1199] | 3192 | _
|
---|
| 3193 | ("Run complete. Please remove media and reboot."));
|
---|
[128] | 3194 | }
|
---|
[1] | 3195 | }
|
---|
| 3196 |
|
---|
[1199] | 3197 | // g_I_have_just_nuked is set true by nuke_mode() just before it returns
|
---|
[818] | 3198 | if (!system("which post-nuke > /dev/null 2> /dev/null")) {
|
---|
[1108] | 3199 | mr_msg(1, "post-nuke found; find out whether we should run it...");
|
---|
[818] | 3200 | if (g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY")) {
|
---|
| 3201 | run_postnuke = TRUE;
|
---|
[1108] | 3202 | mr_msg(1, "Yes, will run post-nuke because in nuke mode or file /POST-NUKE-ANYWAY exists.");
|
---|
[818] | 3203 | } else if (ask_me_yes_or_no("post-nuke script found. Do you want to run it?")) {
|
---|
| 3204 | run_postnuke = TRUE;
|
---|
[1108] | 3205 | mr_msg(1, "Yes, will run post-nuke because user interactively asked for it.");
|
---|
[818] | 3206 | } else {
|
---|
| 3207 | run_postnuke = FALSE;
|
---|
[1108] | 3208 | mr_msg(1, "No, will not run post-nuke.");
|
---|
[818] | 3209 | }
|
---|
| 3210 | } else {
|
---|
[1108] | 3211 | mr_msg(1, "No post-nuke found.");
|
---|
[128] | 3212 | }
|
---|
[818] | 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 {
|
---|
[1108] | 3219 | mr_msg(1, "Re-mounted partitions for post-nuke stuff");
|
---|
[1199] | 3220 | mr_asprintf(&tmp, "post-nuke %s %d", bkpinfo->restore_path,
|
---|
[818] | 3221 | retval);
|
---|
[1108] | 3222 | mr_msg(2, "Calling '%s'", tmp);
|
---|
[818] | 3223 | if ((res = run_program_and_log_output(tmp, 0))) {
|
---|
| 3224 | log_OS_error(tmp);
|
---|
| 3225 | }
|
---|
[1199] | 3226 | mr_free(tmp);
|
---|
[1108] | 3227 | mr_msg(1, "post-nuke returned w/ res=%d", res);
|
---|
[818] | 3228 | }
|
---|
| 3229 | unmount_all_devices(mountlist);
|
---|
| 3230 | log_to_screen("I've finished post-nuking.");
|
---|
| 3231 | }
|
---|
| 3232 |
|
---|
[128] | 3233 | unlink("/tmp/mondo-run-prog.tmp");
|
---|
| 3234 | set_signals(FALSE);
|
---|
[1199] | 3235 | mr_asprintf(&tmp, "rm -Rf %s", bkpinfo->tmpdir);
|
---|
[128] | 3236 | run_program_and_log_output(tmp, FALSE);
|
---|
[1199] | 3237 | mr_free(tmp);
|
---|
| 3238 |
|
---|
[128] | 3239 | log_to_screen
|
---|
[1199] | 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);
|
---|
[128] | 3245 | run_program_and_log_output(tmp, 5);
|
---|
[1199] | 3246 | mr_free(tmp);
|
---|
| 3247 |
|
---|
[1080] | 3248 | mr_free(mountlist);
|
---|
| 3249 | mr_free(raidlist);
|
---|
[128] | 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 :)
|
---|
[1] | 3255 |
|
---|
[128] | 3256 | unlink("/tmp/filelist.full");
|
---|
| 3257 | unlink("/tmp/filelist.full.gz");
|
---|
| 3258 |
|
---|
| 3259 | exit(retval);
|
---|
[1] | 3260 | }
|
---|
| 3261 |
|
---|
| 3262 | /**************************************************************************
|
---|
| 3263 | *END_MAIN *
|
---|
| 3264 | **************************************************************************/
|
---|
| 3265 |
|
---|
| 3266 |
|
---|
| 3267 | /**************************************************************************
|
---|
| 3268 | *END_MONDO-RESTORE.C *
|
---|
| 3269 | **************************************************************************/
|
---|