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