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