Changeset 1242 in MondoRescue
- Timestamp:
- Mar 12, 2007, 2:26:06 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.2/mondo/src/mondorestore/mondo-rstr-tools.c
r998 r1242 12 12 13 13 /*************************************************************************** 14 15 16 17 18 19 20 14 * * 15 * This program is free software; you can redistribute it and/or modify * 16 * it under the terms of the GNU General Public License as published by * 17 * the Free Software Foundation; either version 2 of the License, or * 18 * (at your option) any later version. * 19 * * 20 ***************************************************************************/ 21 21 /* mondo-rstr-tools.c Hugo Rabson 22 22 … … 24 24 07/27 25 25 - if the user is foolish enough to use /dev/md0 as boot device, 26 26 call lilo -M /dev/hda to make sure lilo does its job properly 27 27 - better NFS+nuke support 28 28 … … 49 49 06/14 50 50 - shell out to /mnt/RESTORING chroot in order to let user install GRUB 51 51 manually if automatic GRUB installation fails 52 52 53 53 06/15 54 54 - Added check for different 'isodir' chosen by user than stored in the archive 55 55 Conor Daly <conor.daly@met.ie> 56 56 57 57 04/17 … … 66 66 04/02 67 67 - when extracting cfg file and mountlist from all.tar.gz (tape copy), 68 68 use block size of INTERNAL_TAPE_BLK_SIZE, not TAPE_BLOCK_SIZE 69 69 70 70 02/21 … … 79 79 01/16/2004 80 80 - instead of copying filelist, use 'ln -sf' to link to original; 81 81 saves space 82 82 83 83 11/20/2003 … … 86 86 11/16 87 87 - fixed NFS path bug affecting the extractions of filelist/biggielist 88 88 during selective restore 89 89 90 90 11/02 … … 106 106 10/15 107 107 - run_grub() now uses its initiative instead 108 108 of calling grub-install 109 109 110 110 10/10 111 111 - don't leave copies of filelist.full lying around, clogging up 112 112 the ramdisk, there's a good fellow :-) 113 113 114 114 10/02 … … 141 141 extern long g_current_progress, g_maximum_progress; 142 142 extern char *g_biggielist_txt; // where 'biggielist.txt' is stored, on ramdisk / tempdir; 143 144 143 // biggielist.txt is the list of big files stored on the 144 // backup media set in question 145 145 extern char *g_filelist_full; // filelist.full.gz is the list of all regular files 146 146 // (excluding big files) stored on the backup media set 147 147 extern char *g_biggielist_pot; // list of big files which _could_ be restored, if the 148 148 // user chooses them 149 149 extern char *g_filelist_imagedevs; // list of devices (e.g. /dev/hda1, /dev/sda5) which 150 151 150 // were archived as images, not just /dev entries 151 // ... e.g. NTFS, BeOS partitions 152 152 extern char *g_imagedevs_restthese; // of the imagedevs listed in FILELIST_IMAGEDEVS, 153 153 // restore only these 154 154 extern char *g_mondo_cfg_file; // where m*ndo-restore.cfg (the config file) is stored 155 155 extern char *g_mountlist_fname; // where mountlist.txt (the mountlist file) is stored … … 166 166 167 167 /** 168 169 170 171 /** 172 173 168 * @addtogroup restoreUtilityGroup 169 * @{ 170 */ 171 /** 172 * Free the malloc()s for the filename variables. 173 */ 174 174 void free_MR_global_filenames() 175 175 { 176 177 178 176 paranoid_free(g_biggielist_txt); 177 paranoid_free(g_filelist_full); 178 paranoid_free(g_filelist_imagedevs); 179 179 // paranoid_free (g_imagedevs_pot ); 180 181 182 183 184 185 186 187 188 } 189 190 191 192 /** 193 194 195 196 197 198 180 paranoid_free(g_imagedevs_restthese); 181 paranoid_free(g_mondo_cfg_file); 182 paranoid_free(g_mountlist_fname); 183 paranoid_free(g_mondo_home); 184 paranoid_free(g_tmpfs_mountpt); 185 paranoid_free(g_isodir_device); 186 paranoid_free(g_isodir_format); 187 188 } 189 190 191 192 /** 193 * Ask the user which imagedevs from the list contained in @p infname should 194 * actually be restored. 195 * @param infname The file containing a list of all imagedevs. 196 * @param outfname The location of the output file containing the imagedevs the user wanted to restore. 197 * @ingroup restoreUtilityGroup 198 */ 199 199 void ask_about_these_imagedevs(char *infname, char *outfname) 200 200 { 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 201 FILE *fin; 202 FILE *fout; 203 /************************************************************************ 204 * allocate memory regions. test and set -sab 16 feb 2003 * 205 ************************************************************************/ 206 char *incoming_ptr; 207 char *question_ptr; 208 209 char incoming[MAX_STR_LEN] = "\0"; 210 char question[MAX_STR_LEN]; 211 212 assert_string_is_neither_NULL_nor_zerolength(infname); 213 assert_string_is_neither_NULL_nor_zerolength(outfname); 214 215 incoming_ptr = malloc(sizeof(incoming)); 216 if (incoming_ptr == NULL) { 217 fprintf(stderr, "Out of Memory\n"); 218 exit(EXIT_FAILURE); 219 } 220 221 question_ptr = malloc(sizeof(question)); 222 if (question_ptr == NULL) { 223 fprintf(stderr, "Out of Memory\n"); 224 exit(EXIT_FAILURE); 225 } 226 227 memset(incoming_ptr, '\0', sizeof(incoming)); 228 memset(question_ptr, '\0', sizeof(question)); 229 230 231 232 if (!(fin = fopen(infname, "r"))) { 233 fatal_error("Cannot openin infname"); 234 } 235 if (!(fout = fopen(outfname, "w"))) { 236 fatal_error("Cannot openin outfname"); 237 } 238 for (fgets(incoming_ptr, MAX_STR_LEN, fin); 239 !feof(fin); fgets(incoming_ptr, MAX_STR_LEN, fin)) { 240 strip_spaces(incoming_ptr); 241 242 if (incoming[0] == '\0') { 243 continue; 244 } 245 246 sprintf(question_ptr, 247 "Should I restore the image of %s ?", incoming_ptr); 248 249 if (ask_me_yes_or_no(question_ptr)) { 250 fprintf(fout, "%s\n", incoming_ptr); 251 } 252 } 253 254 /*** free memory ***********/ 255 paranoid_free(incoming_ptr); 256 incoming_ptr = NULL; 257 paranoid_free(question_ptr); 258 question_ptr = NULL; 259 260 261 paranoid_fclose(fout); 262 paranoid_fclose(fin); 263 263 } 264 264 265 265 /************************************************************************** 266 267 268 269 270 271 272 273 274 275 276 /** 277 278 279 280 281 282 283 284 266 *ASK_ABOUT_THESE_IMAGEDEVS * 267 **************************************************************************/ 268 269 270 271 272 273 274 275 276 /** 277 * Extract @c mondo-restore.cfg and @c mountlist.txt from @p ramdisk_fname. 278 * @param bkpinfo The backup information structure. @c tmpdir is the only field used. 279 * @param ramdisk_fname The filename of the @b compressed ramdisk to look in. 280 * @param output_cfg_file Where to put the configuration file extracted. 281 * @param output_mountlist_file Where to put the mountlist file extracted. 282 * @return 0 for success, nonzero for failure. 283 * @ingroup restoreUtilityGroup 284 */ 285 285 int 286 286 extract_config_file_from_ramdisk(struct s_bkpinfo *bkpinfo, 287 288 289 290 { 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 } 349 350 351 352 353 /** 354 355 356 287 char *ramdisk_fname, 288 char *output_cfg_file, 289 char *output_mountlist_file) 290 { 291 char *mountpt; 292 char *command; 293 char *orig_fname; 294 int retval = 0; 295 296 assert(bkpinfo != NULL); 297 malloc_string(mountpt); 298 malloc_string(command); 299 malloc_string(orig_fname); 300 assert_string_is_neither_NULL_nor_zerolength(ramdisk_fname); 301 assert_string_is_neither_NULL_nor_zerolength(output_cfg_file); 302 assert_string_is_neither_NULL_nor_zerolength(output_mountlist_file); 303 sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir); 304 sprintf(command, "mkdir -p %s", mountpt); 305 run_program_and_log_output(command, FALSE); 306 sprintf(command, "gzip -dc %s > %s/mindi.rd 2> /dev/null", 307 ramdisk_fname, bkpinfo->tmpdir); 308 309 run_program_and_log_output(command, FALSE); 310 sprintf(command, "umount %s", mountpt); 311 312 run_program_and_log_output(command, FALSE); 313 314 sprintf(command, "mount -o loop %s/mindi.rd -t ext2 %s", 315 bkpinfo->tmpdir, mountpt); 316 317 run_program_and_log_output(command, FALSE); 318 319 sprintf(command, "mkdir -p %s/tmp", bkpinfo->tmpdir); 320 321 run_program_and_log_output(command, FALSE); 322 323 sprintf(command, "cp -f %s/%s %s", // %s/%s becomes {mountpt}/tmp/m*ndo-restore.cfg 324 mountpt, g_mondo_cfg_file, output_cfg_file); 325 run_program_and_log_output(command, FALSE); 326 327 sprintf(orig_fname, "%s/%s", mountpt, g_mountlist_fname); 328 if (does_file_exist(orig_fname)) { 329 sprintf(command, "cp -f %s %s", orig_fname, output_mountlist_file); 330 run_program_and_log_output(command, FALSE); 331 } 332 sprintf(command, "umount %s", mountpt); 333 run_program_and_log_output(command, FALSE); 334 if (!does_file_exist(output_cfg_file) 335 || (!does_file_exist(output_mountlist_file) 336 && does_file_exist(orig_fname))) { 337 log_msg(2, "Failed to extract %s and/or %s from ramdisk", 338 output_cfg_file, output_mountlist_file); 339 retval = 1; 340 } else { 341 retval = 0; 342 } 343 paranoid_free(mountpt); 344 paranoid_free(command); 345 paranoid_free(orig_fname); 346 return (retval); 347 348 } 349 350 351 352 353 /** 354 * Keep trying to get mondo-restore.cfg from the archive, until the user gives up. 355 * @param bkpinfo The backup information structure. 356 */ 357 357 void get_cfg_file_from_archive_or_bust(struct s_bkpinfo *bkpinfo) 358 358 { 359 360 361 362 363 364 365 366 367 } 368 369 370 /** 371 372 373 374 375 376 359 while (get_cfg_file_from_archive(bkpinfo)) { 360 if (!ask_me_yes_or_no 361 ("Failed to find config file/archives. Choose another source?")) 362 { 363 fatal_error("Could not find config file/archives. Aborting."); 364 } 365 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); 366 } 367 } 368 369 370 /** 371 * Determine whether @p list_fname contains a line containing @p f. 372 * @param f The line to search for. 373 * @param list_fname The file to search in. 374 * @param preamble Ignore this beginning part of @p f ("" to disable). 375 * @return TRUE if it's in the list, FALSE if it's not. 376 */ 377 377 bool is_file_in_list(char *f, char *list_fname, char *preamble) 378 378 { 379 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 380 /** needs malloc **/ 381 char *command; 382 char *file; 383 char *tmp; 384 int res; 385 386 malloc_string(command); 387 malloc_string(file); 388 malloc_string(tmp); 389 assert_string_is_neither_NULL_nor_zerolength(f); 390 assert_string_is_neither_NULL_nor_zerolength(list_fname); 391 assert(preamble != NULL); 392 393 if (strncmp(preamble, f, strlen(preamble)) == 0) { 394 strcpy(file, f + strlen(preamble)); 395 } else { 396 strcpy(file, f); 397 } 398 if (file[0] == '/' && file[1] == '/') { 399 strcpy(tmp, file); 400 strcpy(file, tmp + 1); 401 } 402 sprintf(tmp, 403 "Checking to see if f=%s, file=%s, is in the list of biggiefiles", 404 f, file); 405 log_msg(2, tmp); 406 sprintf(command, "grep -E '^%s$' %s", file, list_fname); 407 res = run_program_and_log_output(command, FALSE); 408 paranoid_free(command); 409 paranoid_free(file); 410 paranoid_free(tmp); 411 if (res) { 412 return (FALSE); 413 } else { 414 return (TRUE); 415 } 416 416 } 417 417 418 418 /************************************************************************** 419 420 421 422 423 424 /** 425 426 427 428 429 430 431 432 419 *END_IS_FILE_IN_LIST * 420 **************************************************************************/ 421 422 423 424 /** 425 * Set up an ISO backup. 426 * @param bkpinfo The backup information structure. Fields used: 427 * - @c bkpinfo->backup_media_type 428 * - @c bkpinfo->disaster_recovery 429 * - @c bkpinfo->isodir 430 * @param nuke_me_please If TRUE, we're in nuke mode; if FALSE we're in interactive mode. 431 * @return 0 for success, nonzero for failure. 432 */ 433 433 int iso_fiddly_bits(struct s_bkpinfo *bkpinfo, bool nuke_me_please) 434 434 { 435 436 437 438 439 440 441 442 443 444 445 435 char *mount_isodir_command, *tmp, *command; 436 int retval = 0, i; 437 bool already_mounted = FALSE; 438 439 assert(bkpinfo != NULL); 440 malloc_string(mount_isodir_command); 441 malloc_string(tmp); 442 malloc_string(command); 443 g_ISO_restore_mode = TRUE; 444 read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device); 445 if (bkpinfo->disaster_recovery) { 446 446 /* Patch Conor Daly 26-june-2004 447 448 449 450 447 * Don't let this clobber an existing bkpinfo->isodir */ 448 if (!bkpinfo->isodir[0]) { 449 strcpy(bkpinfo->isodir, "/tmp/isodir"); 450 } 451 451 /* End patch */ 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 } 507 508 509 510 511 /** 512 513 452 sprintf(command, "mkdir -p %s", bkpinfo->isodir); 453 run_program_and_log_output(command, 5); 454 log_msg(2, "Setting isodir to %s", bkpinfo->isodir); 455 } 456 457 if (!get_isodir_info 458 (g_isodir_device, g_isodir_format, bkpinfo->isodir, 459 nuke_me_please)) { 460 return (1); 461 } 462 paranoid_system("umount " MNT_CDROM " 2> /dev/null"); /* just in case */ 463 464 if (is_this_device_mounted(g_isodir_device)) { 465 log_to_screen("WARNING - isodir is already mounted"); 466 already_mounted = TRUE; 467 } else { 468 sprintf(mount_isodir_command, "mount %s", g_isodir_device); 469 if (strlen(g_isodir_format) > 1) { 470 sprintf(mount_isodir_command + strlen(mount_isodir_command), 471 " -t %s", g_isodir_format); 472 } 473 strcat(mount_isodir_command, " -o ro "); 474 strcat(mount_isodir_command, bkpinfo->isodir); 475 run_program_and_log_output("df -m", FALSE); 476 sprintf(tmp, 477 "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?", 478 mount_isodir_command); 479 log_msg(1, tmp); 480 if (run_program_and_log_output(mount_isodir_command, FALSE)) { 481 popup_and_OK 482 ("Cannot mount the device where the ISO files are stored."); 483 return (1); 484 } 485 log_to_screen 486 ("I have mounted the device where the ISO files are stored."); 487 } 488 if (!IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 489 mount_cdrom(bkpinfo); 490 } 491 i = what_number_cd_is_this(bkpinfo); /* has the side-effect of calling mount_cdrom() */ 492 sprintf(tmp, "%s #%d has been mounted via loopback mount", 493 media_descriptor_string(bkpinfo->backup_media_type), i); 494 log_msg(1, tmp); 495 if (i < 0) { 496 popup_and_OK 497 ("Cannot find ISO images in the directory you specified."); 498 retval = 1; 499 } 500 log_msg(2, "%ld: bkpinfo->isodir is now %s", __LINE__, 501 bkpinfo->isodir); 502 paranoid_free(mount_isodir_command); 503 paranoid_free(tmp); 504 paranoid_free(command); 505 return (retval); 506 } 507 508 509 510 511 /** 512 * Kill all Petris processes. 513 */ 514 514 void kill_petris(void) 515 515 { 516 517 518 519 520 521 516 char *command; 517 malloc_string(command); 518 sprintf(command, 519 "kill `ps 2> /dev/null | grep petris 2> /dev/null | grep -v grep | cut -d' ' -f2` 2> /dev/null"); 520 paranoid_system(command); 521 paranoid_free(command); 522 522 } 523 523 524 524 /************************************************************************** 525 526 527 528 529 /** 530 531 532 533 534 535 525 *END_KILL_PETRIS * 526 **************************************************************************/ 527 528 529 /** 530 * (Disabled) Modify rc.local to fix some things on first boot. 531 * This function currently doesn't do anything except make sure /tmp has the 532 * right permissions. 533 * @param path The path to /etc on the user's filesystem. 534 * @return 0 for success, nonzero for failure. 535 */ 536 536 int modify_rclocal_one_time(char *path) 537 537 { 538 539 540 541 542 543 544 545 546 547 548 538 /** malloc **/ 539 char *rclocal_fname; 540 char *newfile_fname; 541 char *tmp; 542 543 malloc_string(rclocal_fname); 544 malloc_string(newfile_fname); 545 malloc_string(tmp); 546 assert_string_is_neither_NULL_nor_zerolength(path); 547 548 sprintf(rclocal_fname, "%s/rc.local", path); 549 549 550 550 // sprintf(tmp, "chmod 1777 %s/tmp", MNT_RESTORING); 551 551 // run_program_and_log_output( tmp, FALSE ); 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 552 return (0); /* remove this line to open the floodgates... */ 553 554 if (!does_file_exist(rclocal_fname)) { 555 sprintf(rclocal_fname, "%s/rc.d/rc.local", path); 556 } 557 if (!does_file_exist(rclocal_fname)) { 558 paranoid_free(rclocal_fname); 559 paranoid_free(newfile_fname); 560 paranoid_free(tmp); 561 return (1); 562 } 563 sprintf(newfile_fname, "%s/rc.local.mondorescue", path); 564 sprintf(tmp, "grep mondorescue %s > /dev/null 2> /dev/null", 565 rclocal_fname); 566 if (system(tmp)) { 567 sprintf(tmp, "echo \"[ -e %s ] && %s\n\" >> %s", 568 newfile_fname, newfile_fname, rclocal_fname); 569 570 paranoid_system(tmp); 571 } 572 sprintf(tmp, "echo -en \"#!/bin/sh\ 573 573 \\n\ 574 574 \\n\ … … 580 580 yes | rm -f %s\\n\ 581 581 \" > %s", rclocal_fname, rclocal_fname, newfile_fname, newfile_fname); 582 583 584 585 586 587 582 sprintf(tmp, "chmod +x \"%s\"", newfile_fname); 583 run_program_and_log_output(tmp, FALSE); 584 paranoid_free(rclocal_fname); 585 paranoid_free(newfile_fname); 586 paranoid_free(tmp); 587 return (0); 588 588 } 589 589 590 590 /************************************************************************** 591 *END_ MODIFY_RCLOCAL_ONE_TIME * 592 **************************************************************************/ 593 594 595 596 597 598 /** 599 * Mount all devices in @p p_external_copy_of_mountlist on @p MNT_RESTORING. 600 * @param p_external_copy_of_mountlist The mountlist containing devices to be mounted. 601 * @param writeable If TRUE, then mount read-write; if FALSE mount read-only. 602 * @return The number of errors encountered (0 for success). 591 *END_ MODIFY_RCLOCAL_ONE_TIME * 592 **************************************************************************/ 593 594 595 596 597 598 /** 599 * Mount all devices in @p p_external_copy_of_mountlist on @p MNT_RESTORING. 600 * @param p_external_copy_of_mountlist The mountlist containing devices to be mounted. 601 * @param writeable If TRUE, then mount read-write; if FALSE mount read-only. 602 * @return The number of errors encountered (0 for success). 603 */ 604 int mount_all_devices(struct mountlist_itself 605 *p_external_copy_of_mountlist, bool writeable) 606 { 607 int retval = 0, lino, res; 608 char *tmp, *these_failed, *format; 609 struct mountlist_itself *mountlist; 610 611 malloc_string(tmp); 612 malloc_string(format); 613 malloc_string(these_failed); 614 assert(p_external_copy_of_mountlist != NULL); 615 mountlist = malloc(sizeof(struct mountlist_itself)); 616 memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist, 617 sizeof(struct mountlist_itself)); 618 sort_mountlist_by_mountpoint(mountlist, 0); 619 620 /** menset **/ 621 these_failed[0] = '\0'; 622 623 mvaddstr_and_log_it(g_currentY, 0, "Mounting devices "); 624 open_progress_form("Mounting devices", 625 "I am now mounting all the drives.", 626 "This should not take long.", 627 "", mountlist->entries); 628 629 for (lino = 0; lino < mountlist->entries; lino++) { 630 if (!strcmp(mountlist->el[lino].device, "/proc")) { 631 log_msg(1, 632 "Again with the /proc - why is this in your mountlist?"); 633 } else if (is_this_device_mounted(mountlist->el[lino].device)) { 634 sprintf(tmp, "%s is already mounted", 635 mountlist->el[lino].device); 636 log_to_screen(tmp); 637 } else if (strcmp(mountlist->el[lino].mountpoint, "none") 638 && strcmp(mountlist->el[lino].mountpoint, "lvm") 639 && strcmp(mountlist->el[lino].mountpoint, "raid") 640 && strcmp(mountlist->el[lino].mountpoint, "image")) { 641 sprintf(tmp, "Mounting %s", mountlist->el[lino].device); 642 update_progress_form(tmp); 643 strcpy(format, mountlist->el[lino].format); 644 if (!strcmp(format, "ext3")) { 645 strcpy(format, "ext2"); 646 } 647 res = mount_device(mountlist->el[lino].device, 648 mountlist->el[lino].mountpoint, 649 format, writeable); 650 retval += res; 651 if (res) { 652 strcat(these_failed, mountlist->el[lino].device); 653 strcat(these_failed, " "); 654 } 655 } 656 g_current_progress++; 657 } 658 close_progress_form(); 659 run_program_and_log_output("df -m", TRUE); 660 if (retval) { 661 if (g_partition_table_locked_up > 0) { 662 log_to_screen 663 ("fdisk's ictol() call to refresh its copy of the partition table causes the kernel to"); 664 log_to_screen 665 ("lock up the partition table. You might have to reboot and use Interactive Mode to"); 666 log_to_screen 667 ("format and restore *without* partitioning first. Sorry for the inconvenience."); 668 } 669 sprintf(tmp, "Could not mount devices %s- shall I abort?", 670 these_failed); 671 if (!ask_me_yes_or_no(tmp)) { 672 retval = 0; 673 log_to_screen 674 ("Continuing, although some devices failed to be mounted"); 675 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 676 } else { 677 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 678 log_to_screen 679 ("Unable to mount some or all of your partitions."); 680 } 681 } else { 682 log_to_screen("All partitions were mounted OK."); 683 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 684 } 685 run_program_and_log_output("df -m", 3); 686 paranoid_free(mountlist); 687 paranoid_free(tmp); 688 paranoid_free(format); 689 paranoid_free(these_failed); 690 return (retval); 691 } 692 693 /************************************************************************** 694 *END_MOUNT_ALL_DEVICES * 695 **************************************************************************/ 696 697 698 /** 699 * Mount the CD-ROM device at /mnt/cdrom. 700 * @param bkpinfo The backup information structure. Fields used: 701 * - @c bkpinfo->backup_media_type 702 * - @c bkpinfo->disaster_recovery 703 * - @c bkpinfo->isodir 704 * - @c bkpinfo->media_device 705 * @return 0 for success, nonzero for failure. 706 */ 707 int mount_cdrom(struct s_bkpinfo *bkpinfo) 708 { 709 char *mount_cmd; 710 int i, res; 711 #ifdef __FreeBSD__ 712 char mdd[32]; 713 char *mddev = mdd; 714 #endif 715 716 malloc_string(mount_cmd); 717 assert(bkpinfo != NULL); 718 719 if (bkpinfo->backup_media_type == tape 720 || bkpinfo->backup_media_type == udev) { 721 log_msg(8, "Tape/udev. Therefore, no need to mount CDROM."); 722 paranoid_free(mount_cmd); 723 return 0; 724 } 725 726 if (!run_program_and_log_output("mount | grep -F " MNT_CDROM, FALSE)) { 727 log_msg(2, "mount_cdrom() - CD already mounted. Fair enough."); 728 paranoid_free(mount_cmd); 729 return (0); 730 } 731 732 if (bkpinfo->backup_media_type == nfs) { 733 log_msg(2, "Mounting for NFS thingy"); 734 log_msg(2, "isodir = %s", bkpinfo->isodir); 735 if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/")) 736 && am_I_in_disaster_recovery_mode()) { 737 strcpy(bkpinfo->isodir, "/tmp/isodir"); 738 log_msg(1, "isodir is being set to %s", bkpinfo->isodir); 739 } 740 #ifdef __FreeBSD__ 741 sprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir, 742 bkpinfo->nfs_remote_dir, bkpinfo->prefix, g_current_media_number); 743 mddev = make_vn(mount_cmd); 744 sprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev); 745 #else 746 sprintf(mount_cmd, "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s", 747 bkpinfo->isodir, bkpinfo->nfs_remote_dir, 748 bkpinfo->prefix, g_current_media_number, MNT_CDROM); 749 #endif 750 751 } else 752 if (bkpinfo->backup_media_type == iso) { 753 #ifdef __FreeBSD__ 754 sprintf(mount_cmd, "%s/%s-%d.iso", bkpinfo->isodir, 755 bkpinfo->prefix, g_current_media_number); 756 mddev = make_vn(mount_cmd); 757 sprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM); 758 #else 759 sprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s", 760 bkpinfo->isodir, bkpinfo->prefix, g_current_media_number, MNT_CDROM); 761 #endif 762 } else if (strstr(bkpinfo->media_device, "/dev/")) 763 #ifdef __FreeBSD__ 764 { 765 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, 766 MNT_CDROM); 767 } 768 #else 769 { 770 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", 771 bkpinfo->media_device, MNT_CDROM); 772 } 773 #endif 774 775 else { 776 if (bkpinfo->disaster_recovery 777 && does_file_exist("/tmp/CDROM-LIVES-HERE")) { 778 strcpy(bkpinfo->media_device, 779 last_line_of_file("/tmp/CDROM-LIVES-HERE")); 780 } else { 781 find_cdrom_device(bkpinfo->media_device, TRUE); 782 } 783 784 #ifdef __FreeBSD__ 785 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, 786 MNT_CDROM); 787 #else 788 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", 789 bkpinfo->media_device, MNT_CDROM); 790 #endif 791 792 } 793 log_msg(2, "(mount_cdrom) --- command = %s", mount_cmd); 794 for (i = 0; i < 2; i++) { 795 res = run_program_and_log_output(mount_cmd, FALSE); 796 if (!res) { 797 break; 798 } else { 799 log_msg(2, "Failed to mount CD-ROM drive."); 800 sleep(5); 801 run_program_and_log_output("sync", FALSE); 802 } 803 } 804 if (res) { 805 log_msg(2, "Failed, despite %d attempts", i); 806 } else { 807 log_msg(2, "Mounted CD-ROM drive OK"); 808 } 809 paranoid_free(mount_cmd); 810 return (res); 811 } 812 813 814 815 816 817 /************************************************************************** 818 *END_MOUNT_CDROM * 819 **************************************************************************/ 820 821 822 /** 823 * Mount @p device at @p mpt as @p format. 824 * @param device The device (/dev entry) to mount. 825 * @param mpt The directory to mount it on. 826 * @param format The filesystem type of @p device. 827 * @param writeable If TRUE, mount read-write; if FALSE, mount read-only. 828 * @return 0 for success, nonzero for failure. 829 */ 830 int mount_device(char *device, char *mpt, char *format, bool writeable) 831 { 832 int res = 0; 833 834 /** malloc **/ 835 char *tmp, *command, *mountdir, *mountpoint, *additional_parameters; 836 837 assert_string_is_neither_NULL_nor_zerolength(device); 838 assert_string_is_neither_NULL_nor_zerolength(mpt); 839 assert(format != NULL); 840 malloc_string(tmp); 841 malloc_string(command); 842 malloc_string(mountdir); 843 malloc_string(mountpoint); 844 malloc_string(additional_parameters); 845 846 if (!strcmp(mpt, "/1")) { 847 strcpy(mountpoint, "/"); 848 log_msg(3, "Mommm! SME is being a dildo!"); 849 } else { 850 strcpy(mountpoint, mpt); 851 } 852 853 if (!strcmp(mountpoint, "lvm")) { 854 return (0); 855 } 856 if (!strcmp(mountpoint, "image")) { 857 return (0); 858 } 859 sprintf(tmp, "Mounting device %s ", device); 860 log_msg(1, tmp); 861 if (writeable) { 862 strcpy(additional_parameters, "-o rw"); 863 } else { 864 strcpy(additional_parameters, "-o ro"); 865 } 866 if (find_home_of_exe("setfattr")) { 867 strcat(additional_parameters, ",user_xattr"); 868 } 869 if (find_home_of_exe("setfacl")) { 870 strcat(additional_parameters, ",acl"); 871 } 872 873 if (!strcmp(mountpoint, "swap")) { 874 sprintf(command, "swapon %s", device); 875 } else { 876 if (!strcmp(mountpoint, "/")) { 877 strcpy(mountdir, MNT_RESTORING); 878 } else { 879 sprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint); 880 } 881 sprintf(command, "mkdir -p %s", mountdir); 882 run_program_and_log_output(command, FALSE); 883 sprintf(command, "mount -t %s %s %s %s 2>> %s", format, device, 884 additional_parameters, mountdir, MONDO_LOGFILE); 885 log_msg(2, "command='%s'", command); 886 } 887 res = run_program_and_log_output(command, TRUE); 888 if (res && (strstr(command, "xattr") || strstr(command, "acl"))) { 889 log_msg(1, "Re-trying without the fancy extra parameters"); 890 sprintf(command, "mount -t %s %s %s 2>> %s", format, device, 891 mountdir, MONDO_LOGFILE); 892 res = run_program_and_log_output(command, TRUE); 893 } 894 if (res) { 895 log_msg(1, "Unable to mount device %s (type %s) at %s", device, 896 format, mountdir); 897 log_msg(1, "command was '%s'", command); 898 if (!strcmp(mountpoint, "swap")) { 899 log_to_screen(tmp); 900 } else { 901 log_msg(2, "Retrying w/o the '-t' switch"); 902 sprintf(command, "mount %s %s 2>> %s", device, mountdir, 903 MONDO_LOGFILE); 904 log_msg(2, "2nd command = '%s'", command); 905 res = run_program_and_log_output(command, TRUE); 906 if (res == 0) { 907 log_msg(1, 908 "That's OK. I called mount w/o a filesystem type and it worked fine in the end."); 909 } else { 910 log_to_screen(tmp); 911 } 912 } 913 } 914 if (res && !strcmp(mountpoint, "swap")) { 915 log_msg(2, "That's ok. It's just a swap partition."); 916 log_msg(2, "Non-fatal error. Returning 0."); 917 res = 0; 918 } 919 920 paranoid_free(tmp); 921 paranoid_free(command); 922 paranoid_free(mountdir); 923 paranoid_free(mountpoint); 924 paranoid_free(additional_parameters); 925 926 return (res); 927 } 928 929 /************************************************************************** 930 *END_MOUNT_DEVICE * 931 **************************************************************************/ 932 933 934 935 /** 936 * Fix some miscellaneous things in the filesystem so the system will come 937 * up correctly on the first boot. 938 */ 939 void protect_against_braindead_sysadmins() 940 { 941 run_program_and_log_output("touch " MNT_RESTORING "/var/log/pacct", 942 FALSE); 943 run_program_and_log_output("touch " MNT_RESTORING "/var/account/pacct", 944 FALSE); 945 if (run_program_and_log_output("ls " MNT_RESTORING " /tmp", FALSE)) { 946 run_program_and_log_output("chmod 1777 " MNT_RESTORING "/tmp", 947 FALSE); 948 } 949 run_program_and_log_output("mkdir -p " MNT_RESTORING 950 "/var/run/console", FALSE); 951 run_program_and_log_output("chmod 777 " MNT_RESTORING "/dev/null", 952 FALSE); 953 run_program_and_log_output("cd " MNT_RESTORING 954 "; for i in `ls home/`; do echo \"Moving $i's spurious files to $i/.disabled\"; mkdir \"$i\"/.disabled ; mv -f \"$i\"/.DCOP* \"$i\"/.MCOP* \"$i\"/.*authority \"$i\"/.kde/tmp* \"$i\"/.kde/socket* \"$i\"/.disabled/ ; done", 955 TRUE); 956 run_program_and_log_output("rm -f " MNT_RESTORING "/var/run/*.pid", 957 TRUE); 958 run_program_and_log_output("rm -f " MNT_RESTORING "/var/lock/subsys/*", 959 TRUE); 960 } 961 962 /************************************************************************** 963 *END_PROTECT_AGAINST_BRAINDEAD_SYSADMINS * 964 **************************************************************************/ 965 966 967 968 969 /** 970 * Fill out @p bkpinfo based on @p cfg_file. 971 * @param cfg_file The mondo-restore.cfg file to read into @p bkpinfo. 972 * @param bkpinfo The backup information structure to fill out with information 973 * from @p cfg_file. 974 * @return 0 for success, nonzero for failure. 975 */ 976 int read_cfg_file_into_bkpinfo(char *cfgf, struct s_bkpinfo *bkpinfo) 977 { 978 /** add mallocs **/ 979 char *value = NULL; 980 char *tmp = NULL; 981 char *envtmp1 = NULL; 982 char *envtmp2 = NULL; 983 char *command = NULL; 984 char *iso_mnt = NULL; 985 char *iso_path = NULL; 986 char *old_isodir = NULL; 987 char cfg_file[100]; 988 t_bkptype media_specified_by_user; 989 990 malloc_string(command); 991 malloc_string(iso_mnt); 992 malloc_string(iso_path); 993 malloc_string(old_isodir); 994 malloc_string(value); 995 malloc_string(tmp); 996 // assert_string_is_neither_NULL_nor_zerolength(cfg_file); 997 assert(bkpinfo != NULL); 998 999 if (!cfgf) { 1000 strcpy(cfg_file, g_mondo_cfg_file); 1001 } else { 1002 strcpy(cfg_file, cfgf); 1003 } 1004 1005 media_specified_by_user = bkpinfo->backup_media_type; // or 'none', if not specified 1006 1007 if (0 == read_cfg_var(cfg_file, "backup-media-type", value)) { 1008 if (!strcmp(value, "cdstream")) { 1009 bkpinfo->backup_media_type = cdstream; 1010 } else if (!strcmp(value, "cdr")) { 1011 bkpinfo->backup_media_type = cdr; 1012 } else if (!strcmp(value, "cdrw")) { 1013 bkpinfo->backup_media_type = cdrw; 1014 } else if (!strcmp(value, "dvd")) { 1015 bkpinfo->backup_media_type = dvd; 1016 } else if (!strcmp(value, "iso")) { 1017 /* 1018 if (am_I_in_disaster_recovery_mode() 1019 && !run_program_and_log_output("mount /dev/cdrom "MNT_CDROM, 1) 1020 && does_file_exist(MNT_CDROM"/archives/filelist.0")) 1021 */ 1022 1023 // Patch by Conor Daly - 2004/07/12 1024 bkpinfo->backup_media_type = iso; 1025 if (am_I_in_disaster_recovery_mode()) { 1026 /* Check to see if CD is already mounted before mounting it... */ 1027 if (!is_this_device_mounted("/dev/cdrom")) { 1028 log_msg(2, 1029 "NB: CDROM device not mounted, mounting..."); 1030 run_program_and_log_output("mount /dev/cdrom " 1031 MNT_CDROM, 1); 1032 } 1033 if (does_file_exist(MNT_CDROM "/archives/filelist.0")) { 1034 bkpinfo->backup_media_type = cdr; 1035 run_program_and_log_output("umount " MNT_CDROM, 1); 1036 log_it 1037 ("Re-jigging configuration AGAIN. CD-R, not ISO."); 1038 } 1039 } 1040 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) { 1041 strcpy(bkpinfo->prefix,value); 1042 } else { 1043 strcpy(bkpinfo->prefix,STD_PREFIX); 1044 } 1045 } else if (!strcmp(value, "nfs")) { 1046 bkpinfo->backup_media_type = nfs; 1047 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) { 1048 strcpy(bkpinfo->prefix,value); 1049 } else { 1050 strcpy(bkpinfo->prefix,STD_PREFIX); 1051 } 1052 if (strstr(call_program_and_get_last_line_of_output 1053 ("cat /proc/cmdline"), "pxe")) { 1054 /* We need to override prefix value in PXE mode as it's 1055 * already done in start-nfs */ 1056 envtmp1 = getenv("imgname"); 1057 if (envtmp1 == NULL) { 1058 fatal_error("no imgname variable in environment"); 1059 } 1060 strcpy(bkpinfo->prefix,envtmp1); 1061 } 1062 1063 } else if (!strcmp(value, "tape")) { 1064 bkpinfo->backup_media_type = tape; 1065 } else if (!strcmp(value, "udev")) { 1066 bkpinfo->backup_media_type = udev; 1067 } else { 1068 fatal_error("UNKNOWN bkp-media-type"); 1069 } 1070 } else { 1071 fatal_error("backup-media-type not specified!"); 1072 } 1073 if (bkpinfo->disaster_recovery) { 1074 if (bkpinfo->backup_media_type == cdstream) { 1075 sprintf(bkpinfo->media_device, "/dev/cdrom"); 1076 // bkpinfo->media_size[0] = -1; 1077 bkpinfo->media_size[0] = 1999 * 1024; 1078 bkpinfo->media_size[1] = 650; /* good guess */ 1079 } else if (bkpinfo->backup_media_type == tape 1080 || bkpinfo->backup_media_type == udev) { 1081 if (read_cfg_var(cfg_file, "media-dev", value)) { 1082 fatal_error("Cannot get tape device name from cfg file"); 1083 } 1084 strcpy(bkpinfo->media_device, value); 1085 read_cfg_var(cfg_file, "media-size", value); 1086 bkpinfo->media_size[1] = atol(value); 1087 sprintf(tmp, "Backup medium is TAPE --- dev=%s", 1088 bkpinfo->media_device); 1089 log_msg(2, tmp); 1090 } else { 1091 strcpy(bkpinfo->media_device, "/dev/cdrom"); /* we don't really need this var */ 1092 bkpinfo->media_size[0] = 1999 * 1024; /* 650, probably, but we don't need this var anyway */ 1093 bkpinfo->media_size[1] = 1999 * 1024; /* 650, probably, but we don't need this var anyway */ 1094 log_msg(2, "Backup medium is CD-R[W]"); 1095 } 1096 } else { 1097 log_msg(2, 1098 "Not in Disaster Recovery Mode. No need to derive device name from config file."); 1099 } 1100 1101 read_cfg_var(cfg_file, "use-star", value); 1102 if (strstr(value, "yes")) { 1103 bkpinfo->use_star = TRUE; 1104 log_msg(1, "Goody! ... bkpinfo->use_star is now true."); 1105 } 1106 1107 read_cfg_var(cfg_file, "acl", value); 1108 if (strstr(value, "TRUE")) { 1109 asprintf(&g_getfacl,"setfacl"); 1110 log_msg(1, "We will restore ACLs"); 1111 if (! find_home_of_exe("setfacl")) { 1112 log_msg(1, "Unable to restore ACLs as no setfacl found"); 1113 } 1114 } 1115 read_cfg_var(cfg_file, "xattr", value); 1116 if (strstr(value, "TRUE")) { 1117 asprintf(&g_getfattr,"setfattr"); 1118 log_msg(1, "We will restore XATTRs"); 1119 if (! find_home_of_exe("setfattr")) { 1120 log_msg(1, "Unable to restore XATTRs as no setfattr found"); 1121 } 1122 } 1123 1124 if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value)) { 1125 bkpinfo->internal_tape_block_size = atol(value); 1126 log_msg(1, "Internal tape block size has been custom-set to %ld", 1127 bkpinfo->internal_tape_block_size); 1128 } else { 1129 bkpinfo->internal_tape_block_size = 1130 DEFAULT_INTERNAL_TAPE_BLOCK_SIZE; 1131 log_msg(1, "Internal tape block size = default (%ld)", 1132 DEFAULT_INTERNAL_TAPE_BLOCK_SIZE); 1133 } 1134 1135 read_cfg_var(cfg_file, "use-lzo", value); 1136 if (strstr(value, "yes")) { 1137 bkpinfo->use_lzo = TRUE; 1138 bkpinfo->use_gzip = FALSE; 1139 strcpy(bkpinfo->zip_exe, "lzop"); 1140 strcpy(bkpinfo->zip_suffix, "lzo"); 1141 } else { 1142 read_cfg_var(cfg_file, "use-gzip", value); 1143 if (strstr(value, "yes")) { 1144 bkpinfo->use_lzo = FALSE; 1145 bkpinfo->use_gzip = TRUE; 1146 strcpy(bkpinfo->zip_exe, "gzip"); 1147 strcpy(bkpinfo->zip_suffix, "gz"); 1148 } else { 1149 read_cfg_var(cfg_file, "use-comp", value); 1150 if (strstr(value, "yes")) { 1151 bkpinfo->use_lzo = FALSE; 1152 bkpinfo->use_gzip = FALSE; 1153 strcpy(bkpinfo->zip_exe, "bzip2"); 1154 strcpy(bkpinfo->zip_suffix, "bz2"); 1155 } else { 1156 bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0'; 1157 } 1158 } 1159 } 1160 1161 value[0] = '\0'; 1162 read_cfg_var(cfg_file, "differential", value); 1163 if (!strcmp(value, "yes") || !strcmp(value, "1")) { 1164 bkpinfo->differential = TRUE; 1165 } 1166 log_msg(2, "differential var = '%s'", value); 1167 if (bkpinfo->differential) { 1168 log_msg(2, "THIS IS A DIFFERENTIAL BACKUP"); 1169 } else { 1170 log_msg(2, "This is a regular (full) backup"); 1171 } 1172 1173 read_cfg_var(g_mondo_cfg_file, "please-dont-eject", tmp); 1174 if (tmp[0] 1175 || 1176 strstr(call_program_and_get_last_line_of_output 1177 ("cat /proc/cmdline"), "donteject")) { 1178 bkpinfo->please_dont_eject = TRUE; 1179 log_msg(2, "Ok, I shan't eject when restoring! Groovy."); 1180 } 1181 1182 if (bkpinfo->backup_media_type == nfs) { 1183 if (!cfgf) { 1184 log_msg(2, "nfs_mount remains %s", bkpinfo->nfs_mount); 1185 log_msg(2, "nfs_remote_dir remains %s", 1186 bkpinfo->nfs_remote_dir); 1187 log_msg(2, 1188 "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place"); 1189 } else { 1190 read_cfg_var(g_mondo_cfg_file, "nfs-server-mount", 1191 bkpinfo->nfs_mount); 1192 read_cfg_var(g_mondo_cfg_file, "nfs-server-path", 1193 bkpinfo->nfs_remote_dir); 1194 log_msg(2, "nfs_mount is %s", bkpinfo->nfs_mount); 1195 log_msg(2, "nfs_remote_dir is %s", bkpinfo->nfs_remote_dir); 1196 } 1197 if (strstr(call_program_and_get_last_line_of_output 1198 ("cat /proc/cmdline"), "pxe")) { 1199 /* We need to override values in PXE mode as it's 1200 * already done in start-nfs */ 1201 envtmp1 = getenv("nfsmount"); 1202 if (envtmp1 == NULL) { 1203 fatal_error("no nfsmount variable in environment"); 1204 } 1205 envtmp2 = getenv("dirimg"); 1206 if (envtmp2 == NULL) { 1207 fatal_error("no dirimg variable in environment"); 1208 } 1209 strcpy(bkpinfo->nfs_mount,envtmp1); 1210 strcpy(bkpinfo->nfs_remote_dir,envtmp2); 1211 } 1212 } else if (bkpinfo->backup_media_type == iso) { 1213 /* Patch by Conor Daly 23-june-2004 1214 * to correctly mount iso-dev and set a sensible 1215 * isodir in disaster recovery mode 603 1216 */ 604 int mount_all_devices(struct mountlist_itself 605 *p_external_copy_of_mountlist, bool writeable) 606 { 607 int retval = 0, lino, res; 608 char *tmp, *these_failed, *format; 609 struct mountlist_itself *mountlist; 610 611 malloc_string(tmp); 612 malloc_string(format); 613 malloc_string(these_failed); 614 assert(p_external_copy_of_mountlist != NULL); 615 mountlist = malloc(sizeof(struct mountlist_itself)); 616 memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist, 617 sizeof(struct mountlist_itself)); 618 sort_mountlist_by_mountpoint(mountlist, 0); 619 620 /** menset **/ 621 these_failed[0] = '\0'; 622 623 mvaddstr_and_log_it(g_currentY, 0, "Mounting devices "); 624 open_progress_form("Mounting devices", 625 "I am now mounting all the drives.", 626 "This should not take long.", 627 "", mountlist->entries); 628 629 for (lino = 0; lino < mountlist->entries; lino++) { 630 if (!strcmp(mountlist->el[lino].device, "/proc")) { 1217 strcpy(old_isodir, bkpinfo->isodir); 1218 read_cfg_var(g_mondo_cfg_file, "iso-mnt", iso_mnt); 1219 read_cfg_var(g_mondo_cfg_file, "isodir", iso_path); 1220 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path); 1221 if (!bkpinfo->isodir[0]) { 1222 strcpy(bkpinfo->isodir, old_isodir); 1223 } 1224 if (!bkpinfo->disaster_recovery) { 1225 if (strcmp(old_isodir, bkpinfo->isodir)) { 1226 log_it 1227 ("user nominated isodir differs from archive, keeping user's choice: %s %s\n", 1228 old_isodir, bkpinfo->isodir); 1229 strcpy(bkpinfo->isodir, old_isodir); 1230 } 1231 } 1232 read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device); 1233 log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir, 1234 g_isodir_device); 1235 if (bkpinfo->disaster_recovery) { 1236 if (is_this_device_mounted(g_isodir_device)) { 1237 log_msg(2, "NB: isodir is already mounted"); 1238 /* Find out where it's mounted */ 1239 sprintf(command, 1240 "mount | grep -E '^%s' | tail -n1 | cut -d' ' -f3", 1241 g_isodir_device); 1242 log_it("command = %s", command); 1243 log_it("res of it = %s", 1244 call_program_and_get_last_line_of_output(command)); 1245 sprintf(iso_mnt, "%s", 1246 call_program_and_get_last_line_of_output(command)); 1247 } else { 1248 sprintf(iso_mnt, "/tmp/isodir"); 1249 sprintf(tmp, "mkdir -p %s", iso_mnt); 1250 run_program_and_log_output(tmp, 5); 1251 sprintf(tmp, "mount %s %s", g_isodir_device, iso_mnt); 1252 if (run_program_and_log_output(tmp, 3)) { 631 1253 log_msg(1, 632 "Again with the /proc - why is this in your mountlist?"); 633 } else if (is_this_device_mounted(mountlist->el[lino].device)) { 634 sprintf(tmp, "%s is already mounted", 635 mountlist->el[lino].device); 636 log_to_screen(tmp); 637 } else if (strcmp(mountlist->el[lino].mountpoint, "none") 638 && strcmp(mountlist->el[lino].mountpoint, "lvm") 639 && strcmp(mountlist->el[lino].mountpoint, "raid") 640 && strcmp(mountlist->el[lino].mountpoint, "image")) { 641 sprintf(tmp, "Mounting %s", mountlist->el[lino].device); 642 update_progress_form(tmp); 643 strcpy(format, mountlist->el[lino].format); 644 if (!strcmp(format, "ext3")) { 645 strcpy(format, "ext2"); 1254 "Unable to mount isodir. Perhaps this is really a CD backup?"); 1255 bkpinfo->backup_media_type = cdr; 1256 strcpy(bkpinfo->media_device, "/dev/cdrom"); /* superfluous */ 1257 bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0'; 1258 if (mount_cdrom(bkpinfo)) { 1259 fatal_error 1260 ("Unable to mount isodir. Failed to mount CD-ROM as well."); 1261 } else { 1262 log_msg(1, 1263 "You backed up to disk, then burned some CDs."); 646 1264 } 647 res = mount_device(mountlist->el[lino].device, 648 mountlist->el[lino].mountpoint, 649 format, writeable); 650 retval += res; 651 if (res) { 652 strcat(these_failed, mountlist->el[lino].device); 653 strcat(these_failed, " "); 654 } 655 } 656 g_current_progress++; 657 } 658 close_progress_form(); 659 run_program_and_log_output("df -m", TRUE); 660 if (retval) { 661 if (g_partition_table_locked_up > 0) { 662 log_to_screen 663 ("fdisk's ictol() call to refresh its copy of the partition table causes the kernel to"); 664 log_to_screen 665 ("lock up the partition table. You might have to reboot and use Interactive Mode to"); 666 log_to_screen 667 ("format and restore *without* partitioning first. Sorry for the inconvenience."); 668 } 669 sprintf(tmp, "Could not mount devices %s- shall I abort?", 670 these_failed); 671 if (!ask_me_yes_or_no(tmp)) { 672 retval = 0; 673 log_to_screen 674 ("Continuing, although some devices failed to be mounted"); 675 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 676 } else { 677 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 678 log_to_screen 679 ("Unable to mount some or all of your partitions."); 680 } 681 } else { 682 log_to_screen("All partitions were mounted OK."); 683 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 684 } 685 run_program_and_log_output("df -m", 3); 686 paranoid_free(mountlist); 687 paranoid_free(tmp); 688 paranoid_free(format); 689 paranoid_free(these_failed); 690 return (retval); 691 } 692 693 /************************************************************************** 694 *END_MOUNT_ALL_DEVICES * 695 **************************************************************************/ 696 697 698 /** 699 * Mount the CD-ROM device at /mnt/cdrom. 700 * @param bkpinfo The backup information structure. Fields used: 701 * - @c bkpinfo->backup_media_type 702 * - @c bkpinfo->disaster_recovery 703 * - @c bkpinfo->isodir 704 * - @c bkpinfo->media_device 705 * @return 0 for success, nonzero for failure. 706 */ 707 int mount_cdrom(struct s_bkpinfo *bkpinfo) 708 { 709 char *mount_cmd; 710 int i, res; 711 #ifdef __FreeBSD__ 712 char mdd[32]; 713 char *mddev = mdd; 714 #endif 715 716 malloc_string(mount_cmd); 717 assert(bkpinfo != NULL); 718 719 if (bkpinfo->backup_media_type == tape 720 || bkpinfo->backup_media_type == udev) { 721 log_msg(8, "Tape/udev. Therefore, no need to mount CDROM."); 722 paranoid_free(mount_cmd); 723 return 0; 724 } 725 726 if (!run_program_and_log_output("mount | grep -F " MNT_CDROM, FALSE)) { 727 log_msg(2, "mount_cdrom() - CD already mounted. Fair enough."); 728 paranoid_free(mount_cmd); 729 return (0); 730 } 731 732 if (bkpinfo->backup_media_type == nfs) { 733 log_msg(2, "Mounting for NFS thingy"); 734 log_msg(2, "isodir = %s", bkpinfo->isodir); 735 if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/")) 736 && am_I_in_disaster_recovery_mode()) { 737 strcpy(bkpinfo->isodir, "/tmp/isodir"); 738 log_msg(1, "isodir is being set to %s", bkpinfo->isodir); 739 } 740 #ifdef __FreeBSD__ 741 sprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir, 742 bkpinfo->nfs_remote_dir, bkpinfo->prefix, g_current_media_number); 743 mddev = make_vn(mount_cmd); 744 sprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev); 745 #else 746 sprintf(mount_cmd, "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s", 747 bkpinfo->isodir, bkpinfo->nfs_remote_dir, 748 bkpinfo->prefix, g_current_media_number, MNT_CDROM); 749 #endif 750 751 } else 752 if (bkpinfo->backup_media_type == iso) { 753 #ifdef __FreeBSD__ 754 sprintf(mount_cmd, "%s/%s-%d.iso", bkpinfo->isodir, 755 bkpinfo->prefix, g_current_media_number); 756 mddev = make_vn(mount_cmd); 757 sprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM); 758 #else 759 sprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s", 760 bkpinfo->isodir, bkpinfo->prefix, g_current_media_number, MNT_CDROM); 761 #endif 762 } else if (strstr(bkpinfo->media_device, "/dev/")) 763 #ifdef __FreeBSD__ 764 { 765 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, 766 MNT_CDROM); 767 } 768 #else 769 { 770 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", 771 bkpinfo->media_device, MNT_CDROM); 772 } 773 #endif 774 775 else { 776 if (bkpinfo->disaster_recovery 777 && does_file_exist("/tmp/CDROM-LIVES-HERE")) { 778 strcpy(bkpinfo->media_device, 779 last_line_of_file("/tmp/CDROM-LIVES-HERE")); 780 } else { 781 find_cdrom_device(bkpinfo->media_device, TRUE); 782 } 783 784 #ifdef __FreeBSD__ 785 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, 786 MNT_CDROM); 787 #else 788 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", 789 bkpinfo->media_device, MNT_CDROM); 790 #endif 791 792 } 793 log_msg(2, "(mount_cdrom) --- command = %s", mount_cmd); 794 for (i = 0; i < 2; i++) { 795 res = run_program_and_log_output(mount_cmd, FALSE); 796 if (!res) { 797 break; 798 } else { 799 log_msg(2, "Failed to mount CD-ROM drive."); 800 sleep(5); 801 run_program_and_log_output("sync", FALSE); 802 } 803 } 804 if (res) { 805 log_msg(2, "Failed, despite %d attempts", i); 806 } else { 807 log_msg(2, "Mounted CD-ROM drive OK"); 808 } 809 paranoid_free(mount_cmd); 810 return (res); 811 } 812 813 814 815 1265 } 1266 } 1267 /* bkpinfo->isodir should now be the true path to prefix-1.iso etc... */ 1268 if (bkpinfo->backup_media_type == iso) { 1269 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path); 1270 } 1271 } 1272 } 1273 1274 if (media_specified_by_user != none) { 1275 if (g_restoring_live_from_cd) { 1276 if (bkpinfo->backup_media_type != media_specified_by_user) { 1277 log_msg(2, 1278 "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)"); 1279 interactively_obtain_media_parameters_from_user(bkpinfo, 1280 FALSE); 1281 media_specified_by_user = bkpinfo->backup_media_type; 1282 get_cfg_file_from_archive(bkpinfo); 1283 /* 1284 if (media_specified_by_user != cdr && media_specified_by_user == cdrw) 1285 { g_restoring_live_from_cd = FALSE; } 1286 */ 1287 } 1288 } 1289 bkpinfo->backup_media_type = media_specified_by_user; 1290 } 1291 g_backup_media_type = bkpinfo->backup_media_type; 1292 paranoid_free(value); 1293 paranoid_free(tmp); 1294 paranoid_free(command); 1295 paranoid_free(iso_mnt); 1296 paranoid_free(iso_path); 1297 paranoid_free(old_isodir); 1298 return (0); 1299 1300 } 816 1301 817 1302 /************************************************************************** 818 *END_MOUNT_CDROM * 819 **************************************************************************/ 820 821 822 /** 823 * Mount @p device at @p mpt as @p format. 824 * @param device The device (/dev entry) to mount. 825 * @param mpt The directory to mount it on. 826 * @param format The filesystem type of @p device. 827 * @param writeable If TRUE, mount read-write; if FALSE, mount read-only. 828 * @return 0 for success, nonzero for failure. 829 */ 830 int mount_device(char *device, char *mpt, char *format, bool writeable) 831 { 832 int res = 0; 833 834 /** malloc **/ 835 char *tmp, *command, *mountdir, *mountpoint, *additional_parameters; 836 837 assert_string_is_neither_NULL_nor_zerolength(device); 838 assert_string_is_neither_NULL_nor_zerolength(mpt); 839 assert(format != NULL); 840 malloc_string(tmp); 841 malloc_string(command); 842 malloc_string(mountdir); 843 malloc_string(mountpoint); 844 malloc_string(additional_parameters); 845 846 if (!strcmp(mpt, "/1")) { 847 strcpy(mountpoint, "/"); 848 log_msg(3, "Mommm! SME is being a dildo!"); 849 } else { 850 strcpy(mountpoint, mpt); 851 } 852 853 if (!strcmp(mountpoint, "lvm")) { 854 return (0); 855 } 856 if (!strcmp(mountpoint, "image")) { 857 return (0); 858 } 859 sprintf(tmp, "Mounting device %s ", device); 860 log_msg(1, tmp); 861 if (writeable) { 862 strcpy(additional_parameters, "-o rw"); 863 } else { 864 strcpy(additional_parameters, "-o ro"); 865 } 866 if (find_home_of_exe("setfattr")) { 867 strcat(additional_parameters, ",user_xattr"); 868 } 869 if (find_home_of_exe("setfacl")) { 870 strcat(additional_parameters, ",acl"); 871 } 872 873 if (!strcmp(mountpoint, "swap")) { 874 sprintf(command, "swapon %s", device); 875 } else { 876 if (!strcmp(mountpoint, "/")) { 877 strcpy(mountdir, MNT_RESTORING); 878 } else { 879 sprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint); 880 } 881 sprintf(command, "mkdir -p %s", mountdir); 882 run_program_and_log_output(command, FALSE); 883 sprintf(command, "mount -t %s %s %s %s 2>> %s", format, device, 884 additional_parameters, mountdir, MONDO_LOGFILE); 885 log_msg(2, "command='%s'", command); 886 } 887 res = run_program_and_log_output(command, TRUE); 888 if (res && (strstr(command, "xattr") || strstr(command, "acl"))) { 889 log_msg(1, "Re-trying without the fancy extra parameters"); 890 sprintf(command, "mount -t %s %s %s 2>> %s", format, device, 891 mountdir, MONDO_LOGFILE); 892 res = run_program_and_log_output(command, TRUE); 893 } 894 if (res) { 895 log_msg(1, "Unable to mount device %s (type %s) at %s", device, 896 format, mountdir); 897 log_msg(1, "command was '%s'", command); 898 if (!strcmp(mountpoint, "swap")) { 899 log_to_screen(tmp); 900 } else { 901 log_msg(2, "Retrying w/o the '-t' switch"); 902 sprintf(command, "mount %s %s 2>> %s", device, mountdir, 903 MONDO_LOGFILE); 904 log_msg(2, "2nd command = '%s'", command); 905 res = run_program_and_log_output(command, TRUE); 906 if (res == 0) { 907 log_msg(1, 908 "That's OK. I called mount w/o a filesystem type and it worked fine in the end."); 909 } else { 910 log_to_screen(tmp); 911 } 912 } 913 } 914 if (res && !strcmp(mountpoint, "swap")) { 915 log_msg(2, "That's ok. It's just a swap partition."); 916 log_msg(2, "Non-fatal error. Returning 0."); 917 res = 0; 918 } 919 920 paranoid_free(tmp); 921 paranoid_free(command); 922 paranoid_free(mountdir); 923 paranoid_free(mountpoint); 924 paranoid_free(additional_parameters); 925 926 return (res); 927 } 928 929 /************************************************************************** 930 *END_MOUNT_DEVICE * 931 **************************************************************************/ 932 933 934 935 /** 936 * Fix some miscellaneous things in the filesystem so the system will come 937 * up correctly on the first boot. 938 */ 939 void protect_against_braindead_sysadmins() 940 { 941 run_program_and_log_output("touch " MNT_RESTORING "/var/log/pacct", 942 FALSE); 943 run_program_and_log_output("touch " MNT_RESTORING "/var/account/pacct", 944 FALSE); 945 if (run_program_and_log_output("ls " MNT_RESTORING " /tmp", FALSE)) { 946 run_program_and_log_output("chmod 1777 " MNT_RESTORING "/tmp", 947 FALSE); 948 } 949 run_program_and_log_output("mkdir -p " MNT_RESTORING 950 "/var/run/console", FALSE); 951 run_program_and_log_output("chmod 777 " MNT_RESTORING "/dev/null", 952 FALSE); 953 run_program_and_log_output("cd " MNT_RESTORING 954 "; for i in `ls home/`; do echo \"Moving $i's spurious files to $i/.disabled\"; mkdir \"$i\"/.disabled ; mv -f \"$i\"/.DCOP* \"$i\"/.MCOP* \"$i\"/.*authority \"$i\"/.kde/tmp* \"$i\"/.kde/socket* \"$i\"/.disabled/ ; done", 955 TRUE); 956 run_program_and_log_output("rm -f " MNT_RESTORING "/var/run/*.pid", 957 TRUE); 958 run_program_and_log_output("rm -f " MNT_RESTORING "/var/lock/subsys/*", 959 TRUE); 960 } 961 962 /************************************************************************** 963 *END_PROTECT_AGAINST_BRAINDEAD_SYSADMINS * 964 **************************************************************************/ 965 966 967 968 969 /** 970 * Fill out @p bkpinfo based on @p cfg_file. 971 * @param cfg_file The mondo-restore.cfg file to read into @p bkpinfo. 972 * @param bkpinfo The backup information structure to fill out with information 973 * from @p cfg_file. 974 * @return 0 for success, nonzero for failure. 975 */ 976 int read_cfg_file_into_bkpinfo(char *cfgf, struct s_bkpinfo *bkpinfo) 977 { 978 /** add mallocs **/ 979 char *value = NULL; 980 char *tmp = NULL; 981 char *envtmp1 = NULL; 982 char *envtmp2 = NULL; 983 char *command = NULL; 984 char *iso_mnt = NULL; 985 char *iso_path = NULL; 986 char *old_isodir = NULL; 987 char cfg_file[100]; 988 t_bkptype media_specified_by_user; 989 990 malloc_string(command); 991 malloc_string(iso_mnt); 992 malloc_string(iso_path); 993 malloc_string(old_isodir); 994 malloc_string(value); 995 malloc_string(tmp); 996 // assert_string_is_neither_NULL_nor_zerolength(cfg_file); 997 assert(bkpinfo != NULL); 998 999 if (!cfgf) { 1000 strcpy(cfg_file, g_mondo_cfg_file); 1001 } else { 1002 strcpy(cfg_file, cfgf); 1003 } 1004 1005 media_specified_by_user = bkpinfo->backup_media_type; // or 'none', if not specified 1006 1007 if (0 == read_cfg_var(cfg_file, "backup-media-type", value)) { 1008 if (!strcmp(value, "cdstream")) { 1009 bkpinfo->backup_media_type = cdstream; 1010 } else if (!strcmp(value, "cdr")) { 1011 bkpinfo->backup_media_type = cdr; 1012 } else if (!strcmp(value, "cdrw")) { 1013 bkpinfo->backup_media_type = cdrw; 1014 } else if (!strcmp(value, "dvd")) { 1015 bkpinfo->backup_media_type = dvd; 1016 } else if (!strcmp(value, "iso")) { 1017 /* 1018 if (am_I_in_disaster_recovery_mode() 1019 && !run_program_and_log_output("mount /dev/cdrom "MNT_CDROM, 1) 1020 && does_file_exist(MNT_CDROM"/archives/filelist.0")) 1303 *END_READ_CFG_FILE_INTO_BKPINFO * 1304 **************************************************************************/ 1305 1306 1307 1308 1309 /** 1310 * Allow the user to edit the filelist and biggielist. 1311 * The filelist is unlinked after it is read. 1312 * @param bkpinfo The backup information structure. Fields used: 1313 * - @c bkpinfo->backup_media_type 1314 * - @c bkpinfo->isodir 1315 * - @c bkpinfo->media_device 1316 * - @c bkpinfo->tmpdir 1317 * @return The filelist structure containing the information read from disk. 1021 1318 */ 1022 1023 // Patch by Conor Daly - 2004/07/121024 bkpinfo->backup_media_type = iso;1025 if (am_I_in_disaster_recovery_mode()) {1026 /* Check to see if CD is already mounted before mounting it... */1027 if (!is_this_device_mounted("/dev/cdrom")) {1028 log_msg(2,1029 "NB: CDROM device not mounted, mounting...");1030 run_program_and_log_output("mount /dev/cdrom "1031 MNT_CDROM, 1);1032 }1033 if (does_file_exist(MNT_CDROM "/archives/filelist.0")) {1034 bkpinfo->backup_media_type = cdr;1035 run_program_and_log_output("umount " MNT_CDROM, 1);1036 log_it1037 ("Re-jigging configuration AGAIN. CD-R, not ISO.");1038 }1039 }1040 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {1041 strcpy(bkpinfo->prefix,value);1042 } else {1043 strcpy(bkpinfo->prefix,STD_PREFIX);1044 }1045 } else if (!strcmp(value, "nfs")) {1046 bkpinfo->backup_media_type = nfs;1047 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {1048 strcpy(bkpinfo->prefix,value);1049 } else {1050 strcpy(bkpinfo->prefix,STD_PREFIX);1051 }1052 if (strstr(call_program_and_get_last_line_of_output1053 ("cat /proc/cmdline"), "pxe")) {1054 /* We need to override prefix value in PXE mode as it's1055 * already done in start-nfs */1056 envtmp1 = getenv("imgname");1057 if (envtmp1 == NULL) {1058 fatal_error("no imgname variable in environment");1059 }1060 strcpy(bkpinfo->prefix,envtmp1);1061 }1062 1063 } else if (!strcmp(value, "tape")) {1064 bkpinfo->backup_media_type = tape;1065 } else if (!strcmp(value, "udev")) {1066 bkpinfo->backup_media_type = udev;1067 } else {1068 fatal_error("UNKNOWN bkp-media-type");1069 }1070 } else {1071 fatal_error("backup-media-type not specified!");1072 }1073 if (bkpinfo->disaster_recovery) {1074 if (bkpinfo->backup_media_type == cdstream) {1075 sprintf(bkpinfo->media_device, "/dev/cdrom");1076 // bkpinfo->media_size[0] = -1;1077 bkpinfo->media_size[0] = 1999 * 1024;1078 bkpinfo->media_size[1] = 650; /* good guess */1079 } else if (bkpinfo->backup_media_type == tape1080 || bkpinfo->backup_media_type == udev) {1081 if (read_cfg_var(cfg_file, "media-dev", value)) {1082 fatal_error("Cannot get tape device name from cfg file");1083 }1084 strcpy(bkpinfo->media_device, value);1085 read_cfg_var(cfg_file, "media-size", value);1086 bkpinfo->media_size[1] = atol(value);1087 sprintf(tmp, "Backup medium is TAPE --- dev=%s",1088 bkpinfo->media_device);1089 log_msg(2, tmp);1090 } else {1091 strcpy(bkpinfo->media_device, "/dev/cdrom"); /* we don't really need this var */1092 bkpinfo->media_size[0] = 1999 * 1024; /* 650, probably, but we don't need this var anyway */1093 bkpinfo->media_size[1] = 1999 * 1024; /* 650, probably, but we don't need this var anyway */1094 log_msg(2, "Backup medium is CD-R[W]");1095 }1096 } else {1097 log_msg(2,1098 "Not in Disaster Recovery Mode. No need to derive device name from config file.");1099 }1100 1101 read_cfg_var(cfg_file, "use-star", value);1102 if (strstr(value, "yes")) {1103 bkpinfo->use_star = TRUE;1104 log_msg(1, "Goody! ... bkpinfo->use_star is now true.");1105 }1106 1107 read_cfg_var(cfg_file, "acl", value);1108 if (strstr(value, "TRUE")) {1109 asprintf(&g_getfacl,"setfacl");1110 log_msg(1, "We will restore ACLs");1111 if (! find_home_of_exe("setfacl")) {1112 log_msg(1, "Unable to restore ACLs as no setfacl found");1113 }1114 }1115 read_cfg_var(cfg_file, "xattr", value);1116 if (strstr(value, "TRUE")) {1117 asprintf(&g_getfattr,"setfattr");1118 log_msg(1, "We will restore XATTRs");1119 if (! find_home_of_exe("setfattr")) {1120 log_msg(1, "Unable to restore XATTRs as no setfattr found");1121 }1122 }1123 1124 if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value)) {1125 bkpinfo->internal_tape_block_size = atol(value);1126 log_msg(1, "Internal tape block size has been custom-set to %ld",1127 bkpinfo->internal_tape_block_size);1128 } else {1129 bkpinfo->internal_tape_block_size =1130 DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;1131 log_msg(1, "Internal tape block size = default (%ld)",1132 DEFAULT_INTERNAL_TAPE_BLOCK_SIZE);1133 }1134 1135 read_cfg_var(cfg_file, "use-lzo", value);1136 if (strstr(value, "yes")) {1137 bkpinfo->use_lzo = TRUE;1138 bkpinfo->use_gzip = FALSE;1139 strcpy(bkpinfo->zip_exe, "lzop");1140 strcpy(bkpinfo->zip_suffix, "lzo");1141 } else {1142 read_cfg_var(cfg_file, "use-gzip", value);1143 if (strstr(value, "yes")) {1144 bkpinfo->use_lzo = FALSE;1145 bkpinfo->use_gzip = TRUE;1146 strcpy(bkpinfo->zip_exe, "gzip");1147 strcpy(bkpinfo->zip_suffix, "gz");1148 } else {1149 read_cfg_var(cfg_file, "use-comp", value);1150 if (strstr(value, "yes")) {1151 bkpinfo->use_lzo = FALSE;1152 bkpinfo->use_gzip = FALSE;1153 strcpy(bkpinfo->zip_exe, "bzip2");1154 strcpy(bkpinfo->zip_suffix, "bz2");1155 } else {1156 bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';1157 }1158 }1159 }1160 1161 value[0] = '\0';1162 read_cfg_var(cfg_file, "differential", value);1163 if (!strcmp(value, "yes") || !strcmp(value, "1")) {1164 bkpinfo->differential = TRUE;1165 }1166 log_msg(2, "differential var = '%s'", value);1167 if (bkpinfo->differential) {1168 log_msg(2, "THIS IS A DIFFERENTIAL BACKUP");1169 } else {1170 log_msg(2, "This is a regular (full) backup");1171 }1172 1173 read_cfg_var(g_mondo_cfg_file, "please-dont-eject", tmp);1174 if (tmp[0]1175 ||1176 strstr(call_program_and_get_last_line_of_output1177 ("cat /proc/cmdline"), "donteject")) {1178 bkpinfo->please_dont_eject = TRUE;1179 log_msg(2, "Ok, I shan't eject when restoring! Groovy.");1180 }1181 1182 if (bkpinfo->backup_media_type == nfs) {1183 if (!cfgf) {1184 log_msg(2, "nfs_mount remains %s", bkpinfo->nfs_mount);1185 log_msg(2, "nfs_remote_dir remains %s",1186 bkpinfo->nfs_remote_dir);1187 log_msg(2,1188 "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place");1189 } else {1190 read_cfg_var(g_mondo_cfg_file, "nfs-server-mount",1191 bkpinfo->nfs_mount);1192 read_cfg_var(g_mondo_cfg_file, "nfs-server-path",1193 bkpinfo->nfs_remote_dir);1194 log_msg(2, "nfs_mount is %s", bkpinfo->nfs_mount);1195 log_msg(2, "nfs_remote_dir is %s", bkpinfo->nfs_remote_dir);1196 }1197 if (strstr(call_program_and_get_last_line_of_output1198 ("cat /proc/cmdline"), "pxe")) {1199 /* We need to override values in PXE mode as it's1200 * already done in start-nfs */1201 envtmp1 = getenv("nfsmount");1202 if (envtmp1 == NULL) {1203 fatal_error("no nfsmount variable in environment");1204 }1205 envtmp2 = getenv("dirimg");1206 if (envtmp2 == NULL) {1207 fatal_error("no dirimg variable in environment");1208 }1209 strcpy(bkpinfo->nfs_mount,envtmp1);1210 strcpy(bkpinfo->nfs_remote_dir,envtmp2);1211 }1212 } else if (bkpinfo->backup_media_type == iso) {1213 /* Patch by Conor Daly 23-june-20041214 * to correctly mount iso-dev and set a sensible1215 * isodir in disaster recovery mode1216 */1217 strcpy(old_isodir, bkpinfo->isodir);1218 read_cfg_var(g_mondo_cfg_file, "iso-mnt", iso_mnt);1219 read_cfg_var(g_mondo_cfg_file, "isodir", iso_path);1220 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);1221 if (!bkpinfo->isodir[0]) {1222 strcpy(bkpinfo->isodir, old_isodir);1223 }1224 if (!bkpinfo->disaster_recovery) {1225 if (strcmp(old_isodir, bkpinfo->isodir)) {1226 log_it1227 ("user nominated isodir differs from archive, keeping user's choice: %s %s\n",1228 old_isodir, bkpinfo->isodir);1229 strcpy(bkpinfo->isodir, old_isodir);1230 }1231 }1232 read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);1233 log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir,1234 g_isodir_device);1235 if (bkpinfo->disaster_recovery) {1236 if (is_this_device_mounted(g_isodir_device)) {1237 log_msg(2, "NB: isodir is already mounted");1238 /* Find out where it's mounted */1239 sprintf(command,1240 "mount | grep -E '^%s' | tail -n1 | cut -d' ' -f3",1241 g_isodir_device);1242 log_it("command = %s", command);1243 log_it("res of it = %s",1244 call_program_and_get_last_line_of_output(command));1245 sprintf(iso_mnt, "%s",1246 call_program_and_get_last_line_of_output(command));1247 } else {1248 sprintf(iso_mnt, "/tmp/isodir");1249 sprintf(tmp, "mkdir -p %s", iso_mnt);1250 run_program_and_log_output(tmp, 5);1251 sprintf(tmp, "mount %s %s", g_isodir_device, iso_mnt);1252 if (run_program_and_log_output(tmp, 3)) {1253 log_msg(1,1254 "Unable to mount isodir. Perhaps this is really a CD backup?");1255 bkpinfo->backup_media_type = cdr;1256 strcpy(bkpinfo->media_device, "/dev/cdrom"); /* superfluous */1257 bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0';1258 if (mount_cdrom(bkpinfo)) {1259 fatal_error1260 ("Unable to mount isodir. Failed to mount CD-ROM as well.");1261 } else {1262 log_msg(1,1263 "You backed up to disk, then burned some CDs.");1264 }1265 }1266 }1267 /* bkpinfo->isodir should now be the true path to prefix-1.iso etc... */1268 if (bkpinfo->backup_media_type == iso) {1269 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);1270 }1271 }1272 }1273 1274 if (media_specified_by_user != none) {1275 if (g_restoring_live_from_cd) {1276 if (bkpinfo->backup_media_type != media_specified_by_user) {1277 log_msg(2,1278 "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)");1279 interactively_obtain_media_parameters_from_user(bkpinfo,1280 FALSE);1281 media_specified_by_user = bkpinfo->backup_media_type;1282 get_cfg_file_from_archive(bkpinfo);1283 /*1284 if (media_specified_by_user != cdr && media_specified_by_user == cdrw)1285 { g_restoring_live_from_cd = FALSE; }1286 */1287 }1288 }1289 bkpinfo->backup_media_type = media_specified_by_user;1290 }1291 g_backup_media_type = bkpinfo->backup_media_type;1292 paranoid_free(value);1293 paranoid_free(tmp);1294 paranoid_free(command);1295 paranoid_free(iso_mnt);1296 paranoid_free(iso_path);1297 paranoid_free(old_isodir);1298 return (0);1299 1300 }1301 1302 /**************************************************************************1303 *END_READ_CFG_FILE_INTO_BKPINFO *1304 **************************************************************************/1305 1306 1307 1308 1309 /**1310 * Allow the user to edit the filelist and biggielist.1311 * The filelist is unlinked after it is read.1312 * @param bkpinfo The backup information structure. Fields used:1313 * - @c bkpinfo->backup_media_type1314 * - @c bkpinfo->isodir1315 * - @c bkpinfo->media_device1316 * - @c bkpinfo->tmpdir1317 * @return The filelist structure containing the information read from disk.1318 */1319 1319 struct 1320 1320 s_node *process_filelist_and_biggielist(struct s_bkpinfo *bkpinfo) 1321 1321 { 1322 struct s_node *filelist; 1323 1324 /** add mallocs**/ 1325 char *command; 1326 char *tmp; 1327 int res = 0; 1328 pid_t pid; 1329 1330 assert(bkpinfo != NULL); 1331 malloc_string(command); 1332 malloc_string(tmp); 1333 1334 if (does_file_exist(g_filelist_full) 1335 && does_file_exist(g_biggielist_txt)) { 1336 log_msg(1, "%s exists", g_filelist_full); 1337 log_msg(1, "%s exists", g_biggielist_txt); 1338 log_msg(2, 1339 "Filelist and biggielist already recovered from media. Yay!"); 1340 } else { 1341 getcwd(tmp, MAX_STR_LEN); 1342 chdir(bkpinfo->tmpdir); 1343 log_msg(1, "chdir(%s)", bkpinfo->tmpdir); 1344 log_to_screen("Extracting filelist and biggielist from media..."); 1345 unlink("/tmp/filelist.full"); 1346 unlink("/" FILELIST_FULL_STUB); 1347 unlink("/tmp/i-want-my-lvm"); 1348 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 1349 sprintf(command, 1350 "tar -zxf %s %s %s %s %s %s", 1351 bkpinfo->media_device, 1352 MOUNTLIST_FNAME_STUB, 1353 BIGGIELIST_TXT_STUB, 1354 FILELIST_FULL_STUB, 1355 "tmp/i-want-my-lvm", MONDO_CFG_FILE_STUB); 1356 log_msg(1, "tarcommand = %s", command); 1357 run_program_and_log_output(command, 1); 1358 } else { 1359 log_msg(2, 1360 "Calling insist_on_this_cd_number; bkpinfo->isodir=%s", 1361 bkpinfo->isodir); 1362 insist_on_this_cd_number(bkpinfo, 1); 1363 log_msg(2, "Back from iotcn"); 1364 run_program_and_log_output("mount", 1); 1365 sprintf(command, 1366 "tar -zxf %s/images/all.tar.gz %s %s %s %s %s", 1367 MNT_CDROM, 1368 MOUNTLIST_FNAME_STUB, 1369 BIGGIELIST_TXT_STUB, 1370 FILELIST_FULL_STUB, 1371 "tmp/i-want-my-lvm", MONDO_CFG_FILE_STUB); 1372 1373 log_msg(1, "tarcommand = %s", command); 1374 run_program_and_log_output(command, 1); 1322 struct s_node *filelist; 1323 1324 /** add mallocs**/ 1325 char *command; 1326 char *tmp; 1327 int res = 0; 1328 pid_t pid; 1329 1330 assert(bkpinfo != NULL); 1331 malloc_string(command); 1332 malloc_string(tmp); 1333 1334 if (does_file_exist(g_filelist_full) 1335 && does_file_exist(g_biggielist_txt)) { 1336 log_msg(1, "%s exists", g_filelist_full); 1337 log_msg(1, "%s exists", g_biggielist_txt); 1338 log_msg(2, 1339 "Filelist and biggielist already recovered from media. Yay!"); 1340 } else { 1341 getcwd(tmp, MAX_STR_LEN); 1342 chdir(bkpinfo->tmpdir); 1343 log_msg(1, "chdir(%s)", bkpinfo->tmpdir); 1344 log_to_screen("Extracting filelist and biggielist from media..."); 1345 unlink("/tmp/filelist.full"); 1346 unlink("/" FILELIST_FULL_STUB); 1347 unlink("/tmp/i-want-my-lvm"); 1348 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 1349 sprintf(command, 1350 "tar -b %ld -zxf %s %s %s %s %s %s", 1351 bkpinfo->internal_tape_block_size, 1352 bkpinfo->media_device, 1353 MOUNTLIST_FNAME_STUB, 1354 BIGGIELIST_TXT_STUB, 1355 FILELIST_FULL_STUB, 1356 "tmp/i-want-my-lvm", MONDO_CFG_FILE_STUB); 1357 log_msg(1, "tarcommand = %s", command); 1358 run_program_and_log_output(command, 1); 1359 } else { 1360 log_msg(2, 1361 "Calling insist_on_this_cd_number; bkpinfo->isodir=%s", 1362 bkpinfo->isodir); 1363 insist_on_this_cd_number(bkpinfo, 1); 1364 log_msg(2, "Back from iotcn"); 1365 run_program_and_log_output("mount", 1); 1366 sprintf(command, 1367 "tar -zxf %s/images/all.tar.gz %s %s %s %s %s", 1368 MNT_CDROM, 1369 MOUNTLIST_FNAME_STUB, 1370 BIGGIELIST_TXT_STUB, 1371 FILELIST_FULL_STUB, 1372 "tmp/i-want-my-lvm", MONDO_CFG_FILE_STUB); 1373 1374 log_msg(1, "tarcommand = %s", command); 1375 run_program_and_log_output(command, 1); 1375 1376 // popup_and_OK("Press ENTER to continue"); 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1377 if (!does_file_exist(BIGGIELIST_TXT_STUB)) { 1378 fatal_error 1379 ("all.tar.gz did not include tmp/biggielist.txt"); 1380 } 1381 if (!does_file_exist(FILELIST_FULL_STUB)) { 1382 fatal_error 1383 ("all.tar.gz did not include tmp/filelist.full.gz"); 1384 } 1385 } 1386 sprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB, 1387 g_mondo_cfg_file); 1388 run_program_and_log_output(command, FALSE); 1389 1390 sprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir, 1391 BIGGIELIST_TXT_STUB, g_biggielist_txt); 1392 log_msg(1, "command = %s", command); 1393 paranoid_system(command); 1394 sprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir, 1395 FILELIST_FULL_STUB, g_filelist_full); 1396 log_msg(1, "command = %s", command); 1397 paranoid_system(command); 1398 } 1399 1400 if (am_I_in_disaster_recovery_mode() 1401 && 1402 ask_me_yes_or_no("Do you want to retrieve the mountlist as well?")) 1403 { 1403 1404 // sprintf(command, "cp -f tmp/mountlist.txt /tmp"); 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1405 sprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB, 1406 bkpinfo->tmpdir); 1407 paranoid_system(command); 1408 } 1409 1410 chdir(tmp); 1411 1412 if (!does_file_exist(g_biggielist_txt)) { 1413 log_msg(1, "Warning - %s not found", g_biggielist_txt); 1414 } 1415 if (!does_file_exist(g_filelist_full)) { 1416 log_msg(1, "Warning - %s does not exist", g_filelist_full); 1417 } 1417 1418 // popup_and_OK("Wonderful."); 1418 1419 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 sprintf(command, " > %s", g_biggielist_txt);1420 log_msg(2, "Forking"); 1421 pid = fork(); 1422 switch (pid) { 1423 case -1: 1424 fatal_error("Forking error"); 1425 break; 1426 1427 case 0: 1428 log_to_screen("Pre-processing filelist"); 1429 if (!does_file_exist(g_biggielist_txt)) { 1430 sprintf(command, "echo -n > %s", g_biggielist_txt); 1430 1431 paranoid_system(command); 1431 1432 }
Note:
See TracChangeset
for help on using the changeset viewer.