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