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