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