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