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