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