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