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