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