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