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