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