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