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