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