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