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