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