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