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