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