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