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