Changeset 2623 in MondoRescue for branches/2.2.10/mondo/src/mondorestore/mondo-rstr-tools.c
- Timestamp:
- Apr 12, 2010, 3:23:24 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.10/mondo/src/mondorestore/mondo-rstr-tools.c
r2607 r2623 13 13 #include "mondo-rstr-tools.h" 14 14 15 /**16 * The biggielist stub (appended to the directory where all.tar.gz was unpacked).17 */18 #define BIGGIELIST_TXT_STUB "tmp/biggielist.txt"19 20 /**21 * The filelist stub (appended to the directory where all.tar.gz was unpacked).22 */23 #define FILELIST_FULL_STUB "tmp/filelist.full.gz"24 25 /**26 * The mountlist stub (appended to the directory where all.tar.gz was unpacked).27 */28 #define MOUNTLIST_FNAME_STUB MINDI_CACHE_REL"/mountlist.txt"29 30 /**31 * The mondorestore.cfg stub (appended to the directory where all.tar.gz was unpacked).32 */33 #define MONDO_CFG_FILE_STUB MINDI_CACHE_REL"/mondorestore.cfg"34 /**35 * The i-want-my-lvm stub36 */37 #define IWANTMYLVM_STUB "tmp/i-want-my-lvm"38 39 15 extern bool g_ISO_restore_mode; /* are we in Iso Mode? */ 40 16 extern bool g_I_have_just_nuked; … … 44 20 extern char *g_isodir_device; 45 21 extern long g_current_progress, g_maximum_progress; 46 extern char *g_biggielist_txt; // where 'biggielist.txt' is stored, on ramdisk / tempdir;47 // biggielist.txt is the list of big files stored on the48 // backup media set in question49 extern char *g_filelist_full; // filelist.full.gz is the list of all regular files50 // (excluding big files) stored on the backup media set51 22 extern char *g_biggielist_pot; // list of big files which _could_ be restored, if the 52 23 // user chooses them … … 56 27 extern char *g_imagedevs_restthese; // of the imagedevs listed in FILELIST_IMAGEDEVS, 57 28 // restore only these 58 extern char *g_mondo_cfg_file; // where m*ndo-restore.cfg (the config file) is stored59 extern char *g_mountlist_fname; // where mountlist.txt (the mountlist file) is stored60 29 extern char *g_mondo_home; // homedir of Mondo; usually /usr/local/share/mondo 61 30 … … 85 54 void free_MR_global_filenames(void) 86 55 { 87 paranoid_free(g_biggielist_txt);88 paranoid_free(g_filelist_full);89 56 paranoid_free(g_filelist_imagedevs); 90 57 paranoid_free(g_imagedevs_restthese); 91 paranoid_free(g_mondo_cfg_file);92 paranoid_free(g_mountlist_fname);93 58 paranoid_free(g_mondo_home); 94 59 /* … … 148 113 *ASK_ABOUT_THESE_IMAGEDEVS * 149 114 **************************************************************************/ 150 151 152 153 154 155 156 157 158 /**159 * Extract @c mondorestore.cfg and @c mountlist.txt from @p ramdisk_fname.160 * @param bkpinfo The backup information structure. @c tmpdir is the only field used.161 * @param ramdisk_fname The filename of the @b compressed ramdisk to look in.162 * @param output_cfg_file Where to put the configuration file extracted.163 * @param output_mountlist_file Where to put the mountlist file extracted.164 * @return 0 for success, nonzero for failure.165 * @ingroup restoreUtilityGroup166 */167 168 /**169 * Keep trying to get mondorestore.cfg from the archive, until the user gives up.170 */171 void get_cfg_file_from_archive_or_bust()172 {173 while (get_cfg_file_from_archive()) {174 if (!ask_me_yes_or_no175 ("Failed to find config file/archives. Choose another source?"))176 {177 fatal_error("Could not find config file/archives. Aborting.");178 }179 interactively_obtain_media_parameters_from_user(FALSE);180 }181 }182 183 115 184 116 /** … … 252 184 g_ISO_restore_mode = TRUE; 253 185 mr_free(g_isodir_device); 254 g_isodir_device = read_cfg_var( g_mondo_cfg_file, "iso-dev");186 g_isodir_device = read_cfg_var(MINDI_CACHE"/mondorestore.cfg", "iso-dev"); 255 187 if (bkpinfo->disaster_recovery) { 256 188 /* Patch Conor Daly 26-june-2004 … … 272 204 return (1); 273 205 } 274 paranoid_system("umount " MNT_CDROM" 2> /dev/null"); /* just in case */206 paranoid_system("umount "MNT_CDROM" 2> /dev/null"); /* just in case */ 275 207 276 208 if (is_this_device_mounted(g_isodir_device)) { … … 554 486 } 555 487 556 if (!run_program_and_log_output("mount | grep -F " 488 if (!run_program_and_log_output("mount | grep -F "MNT_CDROM, FALSE)) { 557 489 log_msg(2, "mount_media() - media already mounted. Fair enough."); 558 490 return (0); … … 579 511 mr_free(mount_cmd); 580 512 581 mr_asprintf(mount_cmd, "mount_cd9660 -r %s " 513 mr_asprintf(mount_cmd, "mount_cd9660 -r %s "MNT_CDROM, mddev); 582 514 #else 583 515 mr_asprintf(mount_cmd, "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s", bkpinfo->isodir, bkpinfo->netfs_remote_dir, bkpinfo->prefix, g_current_media_number, MNT_CDROM); … … 673 605 **************************************************************************/ 674 606 607 608 /** 609 * Extract mondorestore.cfg and the mountlist from the tape inserted 610 * to the ./tmp/ directory. 611 * @param dev The tape device to read from. 612 * @return 0 for success, nonzero for failure. 613 */ 614 int extract_cfg_file_and_mountlist_from_tape_dev(char *dev) 615 { 616 char *command = NULL; 617 int res = 0; 618 619 if (bkpinfo->use_obdr) { 620 skip_obdr(); 621 } else { 622 // BCO: below 32KB seems to block at least on RHAS 2.1 and MDK 10.0 623 set_tape_block_size_with_mt(bkpinfo->internal_tape_block_size); 624 } 625 626 mr_asprintf(command, "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx ."MINDI_CACHE"/biggielist.txt ."MINDI_CACHE"/filelist.full.gz ."MINDI_CACHE"/i-want-my-lvm", dev, bkpinfo->internal_tape_block_size, 1024L * 1024 * 32 / bkpinfo->internal_tape_block_size); 627 log_msg(2, "command = '%s'", command); 628 res = run_program_and_log_output(command, -1); 629 mr_free(command); 630 631 return (res); 632 } 633 634 635 636 /** 637 * Get the configuration file from the initrd of the backup media 638 * case when calling mondorestore live 639 * @param bkpinfo The backup information structure. Fields used: 640 * - @c bkpinfo->backup_media_type 641 * - @c bkpinfo->media_device 642 * - @c bkpinfo->tmpdir 643 * @return 0 for success, nonzero for failure. 644 */ 645 int get_cfg_file_from_initrd() 646 { 647 /** malloc *****/ 648 char *command = NULL; 649 char *cfg_file = NULL; 650 char *tmp = NULL; 651 char *mountpt = NULL; 652 653 bool try_plan_B; 654 655 assert(bkpinfo != NULL); 656 log_msg(2, "gcffa --- starting"); 657 log_to_screen("I'm thinking..."); 658 mr_asprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir); 659 mr_asprintf(command, "mkdir -p %s", mountpt); 660 run_program_and_log_output(command, FALSE); 661 log_msg(2, "mountpt = %s; ", mountpt); 662 mr_free(command); 663 664 chdir(bkpinfo->tmpdir); 665 666 mr_free(mountpt); 667 668 if (!does_file_exist(cfg_file)) { 669 log_msg(2, "gcffa --- we don't have cfg file yet."); 670 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 671 try_plan_B = TRUE; 672 } else { 673 log_msg(2, "gcffa --- calling mount_media now :)"); 674 if (!mount_media()) { 675 log_msg(2, 676 "gcffa --- managed to mount CD; so, no need for Plan B"); 677 try_plan_B = FALSE; 678 } else { 679 try_plan_B = TRUE; 680 } 681 if (what_number_cd_is_this() > 1) { 682 insist_on_this_cd_number((g_current_media_number = 1)); 683 } 684 } 685 if (try_plan_B) { 686 log_msg(2, "gcffa --- OK, switching to Plan B"); 687 chdir(bkpinfo->tmpdir); 688 run_program_and_log_output("mkdir -p tmp", FALSE); 689 690 if (! bkpinfo->media_device) { 691 mr_asprintf(bkpinfo->media_device, "/dev/st0"); 692 log_msg(2, "media_device is blank; assuming %s", bkpinfo->media_device); 693 } 694 mr_asprintf(tmp, "%s", bkpinfo->media_device); 695 if (extract_cfg_file_and_mountlist_from_tape_dev (bkpinfo->media_device)) { 696 mr_free(bkpinfo->media_device); 697 mr_asprintf(bkpinfo->media_device, "/dev/st0"); 698 if (extract_cfg_file_and_mountlist_from_tape_dev (bkpinfo->media_device)) { 699 mr_free(bkpinfo->media_device); 700 mr_asprintf(bkpinfo->media_device, "/dev/osst0"); 701 if (extract_cfg_file_and_mountlist_from_tape_dev (bkpinfo->media_device)) { 702 mr_free(bkpinfo->media_device); 703 mr_asprintf(bkpinfo->media_device, "/dev/ht0"); 704 if (extract_cfg_file_and_mountlist_from_tape_dev (bkpinfo->media_device)) { 705 log_msg(3, "I tried lots of devices but none worked."); 706 mr_free(bkpinfo->media_device); 707 mr_asprintf(bkpinfo->media_device, "%s", tmp); 708 } 709 } 710 } 711 } 712 mr_free(tmp); 713 714 if (!does_file_exist(MINDI_CACHE_REL"/mondorestore.cfg")) { 715 log_to_screen("Cannot find config info on media"); 716 return (1); 717 } 718 } else { 719 log_msg(2, "gcffa --- Plan B, a.k.a. untarring some file from all.tar.gz"); 720 mr_asprintf(command, "tar -zxvf "MNT_CDROM"/images/all.tar.gz ."MINDI_CACHE"/biggielist.txt ."MINDI_CACHE"/filelist.full.gz ."MINDI_CACHE"/i-want-my-lvm"); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary 721 run_program_and_log_output(command, TRUE); 722 mr_free(command); 723 } 724 } 725 run_program_and_log_output("umount "MNT_CDROM, FALSE); 726 if (!does_file_exist(cfg_file)) { 727 log_it("%s",cfg_file); 728 log_msg(1, "%s not found", cfg_file); 729 log_to_screen("Oh dear. Unable to recover configuration file from boot disk"); 730 return (1); 731 } 732 733 log_to_screen("Recovered mondorestore.cfg"); 734 735 run_program_and_log_output(command, FALSE); 736 mr_free(command); 737 738 mr_asprintf(command, "cp -f etc/raidtab /etc/"); 739 run_program_and_log_output(command, FALSE); 740 mr_free(command); 741 742 g_backup_media_type = bkpinfo->backup_media_type; 743 return (retval); 744 } 675 745 676 746 … … 700 770 // assert_string_is_neither_NULL_nor_zerolength(cfg_file); 701 771 assert(bkpinfo != NULL); 702 703 if (!cfgf) { 704 cfg_file = g_mondo_cfg_file; 705 } else { 706 cfg_file = cfgf; 707 } 772 assert(cfgf != NULL); 708 773 709 774 media_specified_by_user = bkpinfo->backup_media_type; // or 'none', if not specified … … 728 793 if (!is_this_device_mounted("/dev/cdrom")) { 729 794 log_msg(2, "NB: CDROM device not mounted, mounting..."); 730 run_program_and_log_output("mount /dev/cdrom " 731 } 732 if (does_file_exist(MNT_CDROM 795 run_program_and_log_output("mount /dev/cdrom "MNT_CDROM, 1); 796 } 797 if (does_file_exist(MNT_CDROM"/archives/filelist.0")) { 733 798 bkpinfo->backup_media_type = cdr; 734 run_program_and_log_output("umount " 799 run_program_and_log_output("umount "MNT_CDROM, 1); 735 800 log_it 736 801 ("Re-jigging configuration AGAIN. CD-R, not ISO."); … … 951 1016 } 952 1017 953 tmp = read_cfg_var( g_mondo_cfg_file, "please-dont-eject");1018 tmp = read_cfg_var(MINDI_CACHE"/mondorestore.cfg", "please-dont-eject"); 954 1019 tmp1 = call_program_and_get_last_line_of_output("cat " CMDLINE); 955 1020 if (tmp || strstr(tmp1, "donteject")) { … … 971 1036 } else { 972 1037 mr_free(bkpinfo->netfs_mount); 973 bkpinfo->netfs_mount = read_cfg_var( g_mondo_cfg_file, "netfs-server-mount");1038 bkpinfo->netfs_mount = read_cfg_var(MINDI_CACHE"/mondorestore.cfg", "netfs-server-mount"); 974 1039 975 1040 mr_free(bkpinfo->netfs_remote_dir); 976 bkpinfo->netfs_remote_dir = read_cfg_var( g_mondo_cfg_file, "netfs-server-path");1041 bkpinfo->netfs_remote_dir = read_cfg_var(MINDI_CACHE"/mondorestore.cfg", "netfs-server-path"); 977 1042 978 1043 if (bkpinfo->netfs_mount != NULL) { … … 1014 1079 */ 1015 1080 mr_asprintf(old_isodir, "%s", bkpinfo->isodir); 1016 iso_mnt = read_cfg_var( g_mondo_cfg_file, "iso-mnt");1017 iso_path = read_cfg_var( g_mondo_cfg_file, "isodir");1081 iso_mnt = read_cfg_var(MINDI_CACHE"/mondorestore.cfg", "iso-mnt"); 1082 iso_path = read_cfg_var(MINDI_CACHE"/mondorestore.cfg", "isodir"); 1018 1083 mr_free(bkpinfo->isodir); 1019 1084 mr_asprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path); … … 1036 1101 } 1037 1102 mr_free(g_isodir_device); 1038 g_isodir_device = read_cfg_var( g_mondo_cfg_file, "iso-dev");1103 g_isodir_device = read_cfg_var(MINDI_CACHE"/mondorestore.cfg", "iso-dev"); 1039 1104 log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir, g_isodir_device); 1040 1105 … … 1081 1146 1082 1147 if (media_specified_by_user != none) { 1083 if ( g_restoring_live_from_cd) {1148 if (! bkpinfo->disaster_recovery) { 1084 1149 if (bkpinfo->backup_media_type != media_specified_by_user) { 1085 1150 log_msg(2, … … 1087 1152 interactively_obtain_media_parameters_from_user(FALSE); 1088 1153 media_specified_by_user = bkpinfo->backup_media_type; 1089 get_cfg_file_from_archive(); 1090 /* 1091 if (media_specified_by_user != cdr && media_specified_by_user == cdrw) 1092 { g_restoring_live_from_cd = FALSE; } 1093 */ 1154 get_cfg_file_from_initrd(); 1094 1155 } 1095 1156 } … … 1124 1185 struct s_node *filelist; 1125 1186 1126 /** add mallocs**/1127 1187 char *command = NULL; 1128 1188 char *tmp; … … 1130 1190 int res = 0; 1131 1191 pid_t pid; 1132 bool extract_mountlist_stub = FALSE;1133 1192 1134 1193 assert(bkpinfo != NULL); 1135 1194 malloc_string(tmp); 1136 1195 1137 /* If those files already exist, do not overwrite them later on */1138 if (does_file_exist("/"MOUNTLIST_FNAME_STUB)) {1139 extract_mountlist_stub = FALSE;1140 } else {1141 extract_mountlist_stub = TRUE;1142 }1143 1144 if (does_file_exist(g_filelist_full)1145 && does_file_exist(g_biggielist_txt)) {1146 log_msg(1, "%s exists", g_filelist_full);1147 log_msg(1, "%s exists", g_biggielist_txt);1148 log_msg(2,1149 "Filelist and biggielist already recovered from media. Yay!");1150 } else {1151 1196 getcwd(tmp, MAX_STR_LEN); 1152 1197 chdir(bkpinfo->tmpdir); 1153 1198 log_msg(1, "chdir(%s)", bkpinfo->tmpdir); 1154 1199 log_to_screen("Extracting filelist and biggielist from media..."); 1155 unlink("/tmp/filelist.full");1156 unlink(FILELIST_FULL_STUB);1157 1200 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 1158 mr_asprintf(command, "tar -b %ld -zxf %s . /%s ./%s ./%s ./%s ./%s", bkpinfo->internal_tape_block_size, bkpinfo->media_device, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB);1201 mr_asprintf(command, "tar -b %ld -zxf %s ."MINDI_CACHE"/biggielist.txt ."MINDI_CACHE"/filelist.full.gz ."MINDI_CACHE"/i-want-my-lvm", bkpinfo->internal_tape_block_size, bkpinfo->media_device); 1159 1202 log_msg(1, "tarcommand = %s", command); 1160 1203 run_program_and_log_output(command, 1); 1161 1204 mr_free(command); 1162 1205 1163 if (!does_file_exist(FILELIST_FULL_STUB)) {1164 /* Doing that allow us to remain compatible with pre-2.2.5 versions */1165 log_msg(2, "pre-2.2.4 compatible mode on");1166 mr_asprintf(command, "tar -b %ld -zxf %s %s %s %s %s %s", bkpinfo->internal_tape_block_size, bkpinfo->media_device, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB);1167 log_msg(1, "tarcommand = %s", command);1168 run_program_and_log_output(command, 1);1169 mr_free(command);1170 }1171 1206 } else { 1172 1207 log_msg(2, "Calling insist_on_this_cd_number; bkpinfo->isodir=%s", bkpinfo->isodir); … … 1174 1209 log_msg(2, "Back from iotcn"); 1175 1210 run_program_and_log_output("mount", 1); 1176 mr_asprintf(command, "tar -zxf %s/images/all.tar.gz ./%s ./%s ./%s ./%s ./%s", MNT_CDROM, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB);1211 mr_asprintf(command, "tar -zxf "MNT_CDROM"/images/all.tar.gz ."MINDI_CACHE"/biggielist.txt ."MINDI_CACHE"/filelist.full.gz ."MINDI_CACHE"/i-want-my-lvm"); 1177 1212 1178 1213 log_msg(1, "tarcommand = %s", command); … … 1180 1215 mr_free(command); 1181 1216 1182 if (!does_file_exist(FILELIST_FULL_STUB)) { 1183 /* Doing that allow us to remain compatible with pre-2.2.5 versions */ 1184 log_msg(2, "pre-2.2.4 compatible mode on"); 1185 mr_asprintf(command, "tar -zxf %s/images/all.tar.gz %s %s %s %s %s", MNT_CDROM, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB); 1186 1187 log_msg(1, "tarcommand = %s", command); 1188 run_program_and_log_output(command, 1); 1189 mr_free(command); 1190 } 1191 if (!does_file_exist(BIGGIELIST_TXT_STUB)) { 1192 fatal_error 1193 ("all.tar.gz did not include " BIGGIELIST_TXT_STUB); 1194 } 1195 if (!does_file_exist(FILELIST_FULL_STUB)) { 1196 fatal_error 1197 ("all.tar.gz did not include " FILELIST_FULL_STUB); 1198 } 1199 } 1200 mr_asprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB, g_mondo_cfg_file); 1201 run_program_and_log_output(command, FALSE); 1202 mr_free(command); 1203 1204 mr_asprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir, BIGGIELIST_TXT_STUB, g_biggielist_txt); 1205 log_msg(1, "command = %s", command); 1206 paranoid_system(command); 1207 mr_free(command); 1208 1209 mr_asprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir, FILELIST_FULL_STUB, g_filelist_full); 1210 log_msg(1, "command = %s", command); 1211 paranoid_system(command); 1212 mr_free(command); 1213 } 1214 1215 if (am_I_in_disaster_recovery_mode() 1216 && 1217 /* If it was there, do not overwrite it */ 1218 (extract_mountlist_stub) 1219 && 1220 ask_me_yes_or_no("Do you want to retrieve the mountlist as well?")) { 1221 mr_asprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB, bkpinfo->tmpdir); 1222 paranoid_system(command); 1223 mr_free(command); 1224 } 1225 1217 if (!does_file_exist(MINDI_CACHE"/biggielist.txt")) { 1218 fatal_error("all.tar.gz did not include "MINDI_CACHE"/biggielist.txt"); 1219 } 1220 if (!does_file_exist(MINDI_CACHE"/filelist.full.gz")) { 1221 fatal_error("all.tar.gz did not include "MINDI_CACHE"/filelist.full.gz"); 1222 } 1223 } 1226 1224 chdir(tmp); 1227 1228 if (!does_file_exist(g_biggielist_txt)) {1229 log_msg(1, "Warning - %s not found", g_biggielist_txt);1230 }1231 if (!does_file_exist(g_filelist_full)) {1232 log_msg(1, "Warning - %s does not exist", g_filelist_full);1233 }1234 // popup_and_OK("Wonderful.");1235 1225 1236 1226 log_msg(2, "Forking"); … … 1243 1233 case 0: 1244 1234 log_to_screen("Pre-processing filelist"); 1245 if (!does_file_exist(g_biggielist_txt)) { 1246 mr_asprintf(command, "echo -n > %s", g_biggielist_txt); 1247 paranoid_system(command); 1248 mr_free(command); 1249 } 1250 mr_asprintf(command, "grep -E '^/dev/.*' %s > %s", g_biggielist_txt, g_filelist_imagedevs); 1235 mr_asprintf(command, "grep -E '^/dev/.*' "MINDI_CACHE"/biggielist.txt > %s 2> /dev/null", g_filelist_imagedevs); 1251 1236 paranoid_system(command); 1252 1237 mr_free(command); … … 1264 1249 1265 1250 log_msg(3, "loading filelist"); 1266 filelist = load_filelist( g_filelist_full);1251 filelist = load_filelist(MINDI_CACHE"/filelist.full.gz"); 1267 1252 log_msg(3, "deleting original filelist"); 1268 unlink( g_filelist_full);1253 unlink(MINDI_CACHE"/filelist.full.gz"); 1269 1254 if (g_text_mode) { 1270 1255 printf("Restore which directory? --> "); … … 1288 1273 close_evalcall_form(); 1289 1274 1290 // NB: It's not necessary to add g_biggielist_txt to the filelist.full1275 // NB: It's not necessary to add biggielist.txt to the filelist.full 1291 1276 // file. The filelist.full file already contains the filename of EVERY 1292 1277 // file backed up - regular and biggie files. … … 1392 1377 backup_crucial_file(MNT_RESTORING, "/boot/grub/device.map"); 1393 1378 backup_crucial_file(MNT_RESTORING, "/etc/mtab"); 1394 device = read_cfg_var( g_mondo_cfg_file, "bootloader.device");1395 name = read_cfg_var( g_mondo_cfg_file, "bootloader.name");1379 device = read_cfg_var(MINDI_CACHE"/mondorestore.cfg", "bootloader.device"); 1380 name = read_cfg_var(MINDI_CACHE"/mondorestore.cfg", "bootloader.name"); 1396 1381 log_msg(2, "run_boot_loader: device='%s', name='%s'", device, name); 1397 1382 sync(); … … 1908 1893 assert(bkpinfo != NULL); 1909 1894 1910 malloc_string(g_biggielist_txt);1911 malloc_string(g_filelist_full);1912 1895 malloc_string(g_filelist_imagedevs); 1913 1896 malloc_string(g_imagedevs_restthese); 1914 malloc_string(g_mondo_cfg_file);1915 malloc_string(g_mountlist_fname);1916 1897 malloc_string(g_mondo_home); 1917 1898 1918 sprintf(g_biggielist_txt, "%s/%s", bkpinfo->tmpdir, BIGGIELIST_TXT_STUB);1919 sprintf(g_filelist_full, "%s/%s", bkpinfo->tmpdir, FILELIST_FULL_STUB);1920 1899 sprintf(g_filelist_imagedevs, "%s/tmp/filelist.imagedevs", bkpinfo->tmpdir); 1921 1900 sprintf(g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these", bkpinfo->tmpdir); 1922 if (bkpinfo->disaster_recovery) { 1923 sprintf(g_mondo_cfg_file, "/%s", MONDO_CFG_FILE_STUB); 1924 sprintf(g_mountlist_fname, "/%s", MOUNTLIST_FNAME_STUB); 1925 } else { 1926 sprintf(g_mondo_cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB); 1927 sprintf(g_mountlist_fname, "%s/%s", bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB); 1901 if (! bkpinfo->disaster_recovery) { 1902 /* TODO: We need to get mondorestore.cfg and mountlist.txt from initrd.img */ 1903 get_cfg_file_from_initrd() 1928 1904 } 1929 1905 } … … 2127 2103 2128 2104 2129 /**2130 * Extract mondorestore.cfg and the mountlist from the tape inserted2131 * to the ./tmp/ directory.2132 * @param dev The tape device to read from.2133 * @return 0 for success, nonzero for failure.2134 */2135 int extract_cfg_file_and_mountlist_from_tape_dev(char *dev)2136 {2137 char *command = NULL;2138 int res = 0;2139 2140 if (bkpinfo->use_obdr) {2141 skip_obdr();2142 } else {2143 // BCO: below 32KB seems to block at least on RHAS 2.1 and MDK 10.02144 set_tape_block_size_with_mt(bkpinfo->internal_tape_block_size);2145 }2146 2147 mr_asprintf(command, "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx ./%s ./%s ./%s ./%s ./%s", dev, bkpinfo->internal_tape_block_size, 1024L * 1024 * 32 / bkpinfo->internal_tape_block_size, MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB);2148 log_msg(2, "command = '%s'", command);2149 res = run_program_and_log_output(command, -1);2150 mr_free(command);2151 2152 if (res != 0) {2153 if (does_file_exist(MONDO_CFG_FILE_STUB)) {2154 res = 0;2155 } else {2156 /* Doing that allow us to remain compatible with pre-2.2.5 versions */2157 log_msg(2, "pre-2.2.4 compatible mode on");2158 mr_asprintf(command, "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx %s %s %s %s %s", dev, bkpinfo->internal_tape_block_size, 1024L * 1024 * 32 / bkpinfo->internal_tape_block_size, MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB);2159 log_msg(2, "command = '%s'", command);2160 res = run_program_and_log_output(command, -1);2161 mr_free(command);2162 2163 if ((res != 0) && (does_file_exist(MONDO_CFG_FILE_STUB))) {2164 res = 0;2165 }2166 }2167 }2168 return (res);2169 }2170 2171 2172 2173 /**2174 * Get the configuration file from the floppy, tape, or CD.2175 * @param bkpinfo The backup information structure. Fields used:2176 * - @c bkpinfo->backup_media_type2177 * - @c bkpinfo->media_device2178 * - @c bkpinfo->tmpdir2179 * @return 0 for success, nonzero for failure.2180 */2181 int get_cfg_file_from_archive()2182 {2183 int retval = 0;2184 2185 /** malloc *****/2186 char *command = NULL;2187 char *cfg_file = NULL;2188 char *tmp = NULL;2189 char *tmp1 = NULL;2190 char *mountpt = NULL;2191 char *mountlist_file = NULL;2192 bool extract_mountlist_stub = FALSE;2193 bool extract_i_want_my_lvm = FALSE;2194 2195 bool try_plan_B;2196 2197 assert(bkpinfo != NULL);2198 log_msg(2, "gcffa --- starting");2199 log_to_screen("I'm thinking...");2200 mr_asprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);2201 chdir(bkpinfo->tmpdir);2202 mr_asprintf(cfg_file, "%s", MONDO_CFG_FILE_STUB);2203 unlink(cfg_file); // cfg_file[] is missing the '/' at the start, FYI, by intent2204 mr_free(cfg_file);2205 2206 unlink(FILELIST_FULL_STUB);2207 unlink(BIGGIELIST_TXT_STUB);2208 mr_asprintf(command, "mkdir -p %s", mountpt);2209 run_program_and_log_output(command, FALSE);2210 mr_free(command);2211 2212 mr_asprintf(cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB);2213 mr_asprintf(mountlist_file, "%s/%s", bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);2214 log_msg(2, "mountpt = %s; cfg_file=%s", mountpt, cfg_file);2215 mr_free(mountpt);2216 2217 if (!does_file_exist(cfg_file)) {2218 log_msg(2, "gcffa --- we don't have cfg file yet.");2219 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {2220 try_plan_B = TRUE;2221 } else {2222 log_msg(2, "gcffa --- calling mount_media now :)");2223 if (!mount_media()) {2224 log_msg(2,2225 "gcffa --- managed to mount CD; so, no need for Plan B");2226 try_plan_B = FALSE;2227 } else {2228 try_plan_B = TRUE;2229 }2230 if (what_number_cd_is_this() > 1) {2231 insist_on_this_cd_number((g_current_media_number = 1));2232 }2233 }2234 if (try_plan_B) {2235 log_msg(2, "gcffa --- OK, switching to Plan B");2236 chdir(bkpinfo->tmpdir);2237 run_program_and_log_output("mkdir -p tmp", FALSE);2238 2239 if (! bkpinfo->media_device) {2240 mr_asprintf(bkpinfo->media_device, "/dev/st0");2241 log_msg(2, "media_device is blank; assuming %s", bkpinfo->media_device);2242 }2243 mr_asprintf(tmp, "%s", bkpinfo->media_device);2244 if (extract_cfg_file_and_mountlist_from_tape_dev (bkpinfo->media_device)) {2245 mr_free(bkpinfo->media_device);2246 mr_asprintf(bkpinfo->media_device, "/dev/st0");2247 if (extract_cfg_file_and_mountlist_from_tape_dev (bkpinfo->media_device)) {2248 mr_free(bkpinfo->media_device);2249 mr_asprintf(bkpinfo->media_device, "/dev/osst0");2250 if (extract_cfg_file_and_mountlist_from_tape_dev (bkpinfo->media_device)) {2251 mr_free(bkpinfo->media_device);2252 mr_asprintf(bkpinfo->media_device, "/dev/ht0");2253 if (extract_cfg_file_and_mountlist_from_tape_dev (bkpinfo->media_device)) {2254 log_msg(3, "I tried lots of devices but none worked.");2255 mr_free(bkpinfo->media_device);2256 mr_asprintf(bkpinfo->media_device, "%s", tmp);2257 }2258 }2259 }2260 }2261 mr_free(tmp);2262 2263 if (!does_file_exist(MINDI_CACHE_REL"/mondorestore.cfg")) {2264 log_to_screen("Cannot find config info on media");2265 return (1);2266 }2267 } else {2268 if (does_file_exist("/"MOUNTLIST_FNAME_STUB)) {2269 extract_mountlist_stub = FALSE;2270 } else {2271 extract_mountlist_stub = TRUE;2272 }2273 if (does_file_exist("/"IWANTMYLVM_STUB)) {2274 extract_i_want_my_lvm = FALSE;2275 } else {2276 extract_i_want_my_lvm = TRUE;2277 }2278 2279 log_msg(2,2280 "gcffa --- Plan B, a.k.a. untarring some file from all.tar.gz");2281 mr_asprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz ./%s ./%s ./%s ./%s ./%s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary2282 run_program_and_log_output(command, TRUE);2283 mr_free(command);2284 2285 if (!does_file_exist(MONDO_CFG_FILE_STUB)) {2286 /* Doing that allow us to remain compatible with pre-2.2.5 versions */2287 log_msg(2, "pre-2.2.4 compatible mode on");2288 mr_asprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz %s %s %s %s %s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary2289 run_program_and_log_output(command, TRUE);2290 mr_free(command);2291 2292 if (!does_file_exist(MONDO_CFG_FILE_STUB)) {2293 fatal_error2294 ("Please reinsert the disk/CD and try again.");2295 }2296 }2297 }2298 }2299 if (does_file_exist(MONDO_CFG_FILE_STUB)) {2300 log_msg(1, "gcffa --- great! We've got the config file");2301 tmp = call_program_and_get_last_line_of_output("pwd");2302 mr_strcat(tmp, "/%s", MONDO_CFG_FILE_STUB);2303 mr_asprintf(command, "cp -f %s %s", tmp, cfg_file);2304 log_it("%s",command);2305 if (strcmp(tmp, cfg_file) && run_program_and_log_output(command, 1)) {2306 log_msg(1, "... but an error occurred when I tried to move it to %s", cfg_file);2307 } else {2308 log_msg(1, "... and I moved it successfully to %s", cfg_file);2309 }2310 mr_free(command);2311 2312 tmp1 = call_program_and_get_last_line_of_output("pwd");2313 mr_asprintf(command, "cp -f %s/%s %s", tmp1, MOUNTLIST_FNAME_STUB, mountlist_file);2314 mr_free(tmp1);2315 2316 log_it("%s",command);2317 if (extract_mountlist_stub) {2318 if (strcmp(tmp, cfg_file) && run_program_and_log_output(command, 1)) {2319 log_msg(1, "Failed to get mountlist");2320 } else {2321 log_msg(1, "Got mountlist too");2322 2323 mr_free(command);2324 mr_asprintf(command, "cp -f %s %s", mountlist_file, g_mountlist_fname);2325 if (run_program_and_log_output(command, 1)) {2326 log_msg(1, "Failed to copy mountlist to /tmp");2327 } else {2328 log_msg(1, "Copied mountlist to /tmp as well OK");2329 mr_free(command);2330 mr_asprintf(command, "cp -f %s /tmp/",IWANTMYLVM_STUB);2331 run_program_and_log_output(command, 1);2332 }2333 }2334 }2335 mr_free(tmp);2336 mr_free(command);2337 }2338 run_program_and_log_output("umount " MNT_CDROM, FALSE);2339 if (!does_file_exist(cfg_file)) {2340 log_it("%s",cfg_file);2341 log_msg(1, "%s not found", cfg_file);2342 log_to_screen2343 ("Oh dear. Unable to recover configuration file from boot disk");2344 return (1);2345 }2346 2347 log_to_screen("Recovered mondorestore.cfg");2348 if (!does_file_exist(MOUNTLIST_FNAME_STUB)) {2349 log_to_screen("...but not mountlist.txt - a pity, really...");2350 }2351 else {2352 /* Is this code really useful ??? */2353 if (extract_mountlist_stub) {2354 mr_asprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB, bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);2355 run_program_and_log_output(command, FALSE);2356 mr_free(command);2357 }2358 }2359 2360 mr_asprintf(command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB);2361 mr_free(cfg_file);2362 2363 run_program_and_log_output(command, FALSE);2364 mr_free(command);2365 2366 if (extract_mountlist_stub) {2367 mr_asprintf(command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB);2368 run_program_and_log_output(command, FALSE);2369 mr_free(command);2370 }2371 mr_free(mountlist_file);2372 2373 mr_asprintf(command, "cp -f etc/raidtab /etc/");2374 run_program_and_log_output(command, FALSE);2375 mr_free(command);2376 2377 if (extract_i_want_my_lvm) {2378 mr_asprintf(command, "cp -f %s /tmp/",IWANTMYLVM_STUB);2379 run_program_and_log_output(command, FALSE);2380 mr_free(command);2381 }2382 g_backup_media_type = bkpinfo->backup_media_type;2383 return (retval);2384 }2385 2386 2105 /************************************************************************** 2387 2106 *END_GET_CFG_FILE_FROM_ARCHIVE *
Note:
See TracChangeset
for help on using the changeset viewer.