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