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