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