如需为一个 CSV 文件中的虚拟机运行客机发现,请使用 Migrate to Containers GitHub 代码库中的 collection 脚本。
对上一步生成的每个 CSV 文件重复此步骤。
url_regex='^https?://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]\.[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]$'read-r-p"CSV file name: "CSV_FILE
if[[!-r"$CSV_FILE"]];thenecho"The file $CSV_FILE does not exist or can not be accessed."exit1firead-r-p"vSphere URL: "VSPHERE_URL
if![[$VSPHERE_URL=~$url_regex]];thenecho"vSphere URL $VSPHERE_URL IS not a valid URL"exit1firead-r-p"vSphere username: "VSPHERE_USER
read-r-s-p"vSphere password: "VSPHERE_PASSWORD
echo""read-r-p"Default username: "DEFAULT_USER
read-r-s-p"Default password: "DEFAULT_PASSWORD
echo""# CSV fields#NAME;PLATFORM VM ID;OS;IP;USERNAME;PASSWORDwhileIFS=";"read-rvm_namevm_idosipusernamepassword
doif[-z"$username"]thenusername=$DEFAULT_USERfiif[-z"$password"]thenpassword=$DEFAULT_PASSWORDfiif[!-z"$vm_id"]then# Note that the below only works for VMWare VMs# vm_id after the last slash if prefixed by vSphere IPmod_vm_id=$(echo"$vm_id"|sed's/.*\///')mcdcdiscovervsphereguest--url$VSPHERE_URL-u$VSPHERE_USER-p$VSPHERE_PASSWORD--vm-user$username--vm-password$password$mod_vm_idelseecho"Skipping VM: $vm_name because it has no VM ID"fidone < <(tail-n+1$CSV_FILE)
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-30。"],[],[],null,["# Batching guest discovery and data collection\n\n*** ** * ** ***\n\nThis tutorial walks you through the process of discovering and collecting data\non a batch of VMware virtual machine (VM) instances using the\nMigration Center discovery client CLI guest discovery. Large batches of VMs may be difficult\nto monitor and troubleshoot. We recommend batching into smaller groups of less\nthan 1,000.\n\nObjectives\n----------\n\nIn this tutorial, you will learn how to:\n\n- Download the `mcdc` CLI.\n- Run a VMWare inventory discovery.\n- Generate a CSV file with all the discovered VMs.\n- Split the CSV file into multiple CSV files containing a subset of the VMs.\n- Run guest discovery on all the VMs in a CSV file.\n- Generate an offline assessment report.\n\nCosts\n-----\n\nThis tutorial uses on-premises resources and incurs no Google Cloud\ncosts.\n\nBefore you begin\n----------------\n\n1. Prepare a Linux machine to install and run the\n `mcdc` CLI. The Linux machine must have the\n following minimum requirements:\n\n - `glibc` version 2.25 or later\n - 4 GB RAM and 10 GB disk space\n - Network connectivity to vCenter and ESX hosts\n2. Ensure that you have a vSphere user with the necessary permissions:\n\n - Read privileges to VMs\n - Read privileges to all the ESX hosts\n - Guest operation modifications\n - Guest operation program execution\n- Guest operation queries \n\nDownload the `mcdc` CLI\n-----------------------\n\n1. Connect to the Linux machine: \n\n ```bash\n ssh MACHINE_IP\n ```\n\n Replace \u003cvar translate=\"no\"\u003eMACHINE_IP\u003c/var\u003e with the IP address of your Linux machine.\n2. Download the latest version of the `mcdc` CLI and make it executable: \n\n ```bash\n curl -O \"https://mcdc-release.storage.googleapis.com/$(curl -s https://mcdc-release.storage.googleapis.com/latest)/mcdc\"\n chmod +x mcdc\n ```\n3. Add the `mcdc` CLI to your shell path: \n\n ```bash\n PATH=$PATH:`pwd`\n ```\n\nPerform a VMware inventory discovery\n------------------------------------\n\n- Run the inventory discovery:\n\n ./mcdc discover vsphere -u \u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e --url https://\u003cvar translate=\"no\"\u003eVSPHERE_URL\u003c/var\u003e\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e: your vCenter username\n - \u003cvar translate=\"no\"\u003eVSPHERE_URL\u003c/var\u003e: the URL for your vCenter Server instance or the vSphere Client\n\n The output of the `discover` command looks like the following: \n\n ```\n [+] Found 528 VMs\n Collecting data...\n 528 / 528 [---------------------------------------------------] 100.00% 5 p/s\n [✓] Collection completed.\n ```\n\nGenerate a CSV file with all the discovered VMs\n-----------------------------------------------\n\nTo generate a CSV file, use the `export` script from the Migrate to Containers\nrepository on GitHub. \n\n\n vms=$(mcdc report --format csv | tail -n +2 | awk -F ',' '{; print $2\";\"$3\";\"$4\";;;\"}')\n printf \"%s\\n\" \"Name;Platform VM ID;OS Family;IP;USERNAME;PASSWORD\"\n printf \"%s\\n\" \"$vms\"\n\nThe script uses the `report` command to generate a CSV file containing all the\nVMs that were discovered in the previous step.\n\n1. Download the script:\n\n curl -O https://raw.githubusercontent.com/GoogleCloudPlatform/migrate-to-containers/main/scripts/mcdc/mcdc_discovery_export_guest_tools.sh\n chmod +x mcdc_discovery_export_guest_tools.sh\n\n2. Run the script and save the output to a file:\n\n ./mcdc_discovery_export_guest_tools.sh \u003e \u003cvar translate=\"no\"\u003eVMS_CSV_FILE\u003c/var\u003e\n\n Replace \u003cvar translate=\"no\"\u003eVMS_CSV_FILE\u003c/var\u003e with the name you want for the CSV file.\n\nSplit the CSV file into multiple CSV files with a subset of the VMs\n-------------------------------------------------------------------\n\nTo split the large CSV file into smaller CSV files, use the `splitter` script\nfrom the Migrate to Containers repository on GitHub. \n\n tail -n +2 $1 | split -d -l $num_of_lines - $2\n for file in $2*\n do\n head -n 1 $1 \u003e tmp_file\n cat \"$file\" \u003e\u003e tmp_file\n mv -f tmp_file \"$file\"\n done\n\n1. Download the script:\n\n curl -O https://raw.githubusercontent.com/GoogleCloudPlatform/migrate-to-containers/main/scripts/mcdc/csv_splitter.sh\n chmod +x csv_splitter.sh\n\n2. Run the script:\n\n ./csv_splitter.sh \u003cvar translate=\"no\"\u003eVMS_CSV_FILE\u003c/var\u003e \u003cvar translate=\"no\"\u003eCSV_FILES_PREFIX\u003c/var\u003e \u003cvar translate=\"no\"\u003eLINES_PER_FILE\u003c/var\u003e \u003cvar translate=\"no\"\u003eVMS_CSV_FILE\u003c/var\u003e \u003cvar translate=\"no\"\u003eCSV_FILES_PREFIX\u003c/var\u003e\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eVMS_CSV_FILE\u003c/var\u003e: the input CSV file to split.\n - \u003cvar translate=\"no\"\u003eCSV_FILES_PREFIX\u003c/var\u003e: the prefix for the generated CSV files.\n - \u003cvar translate=\"no\"\u003eLINES_PER_FILE\u003c/var\u003e: the number of lines per generated CSV file. The default value is `10`.\n\n The script generates various CSV files.\n3. View the list of generated CSV files:\n\n ls -lrt \u003cvar translate=\"no\"\u003eCSV_FILES_PREFIX\u003c/var\u003e*\n\nRun guest discovery on all the VMs in a CSV files\n-------------------------------------------------\n\nTo run the guest discovery for the VMs in a CSV file, use the\n`collection` script from the Migrate to Containers GitHub repository.\n\nRepeat this step for each CSV file generated in the previous step. \n\n\n url_regex='^https?://[-A-Za-z0-9\\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\\+&@#/%=~_|]\\.[-A-Za-z0-9\\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\\+&@#/%=~_|]$'\n\n read -r -p \"CSV file name: \" CSV_FILE\n if [[ ! -r \"$CSV_FILE\" ]]; then\n echo \"The file $CSV_FILE does not exist or can not be accessed.\"\n exit 1\n fi\n\n read -r -p \"vSphere URL: \" VSPHERE_URL\n if ! [[ $VSPHERE_URL =~ $url_regex ]]; then\n echo \"vSphere URL $VSPHERE_URL IS not a valid URL\"\n exit 1\n fi\n read -r -p \"vSphere username: \" VSPHERE_USER\n read -r -s -p \"vSphere password: \" VSPHERE_PASSWORD\n echo \"\"\n read -r -p \"Default username: \" DEFAULT_USER\n read -r -s -p \"Default password: \" DEFAULT_PASSWORD\n\n echo \"\"\n\n # CSV fields\n #NAME;PLATFORM VM ID;OS;IP;USERNAME;PASSWORD\n while IFS=\";\" read -r vm_name vm_id os ip username password\n do\n if [ -z \"$username\" ]\n then\n username=$DEFAULT_USER\n fi\n if [ -z \"$password\" ]\n then\n password=$DEFAULT_PASSWORD\n fi\n\n if [ ! -z \"$vm_id\" ]\n then\n # Note that the below only works for VMWare VMs\n # vm_id after the last slash if prefixed by vSphere IP\n mod_vm_id=$(echo \"$vm_id\" | sed 's/.*\\///')\n mcdc discover vsphere guest --url $VSPHERE_URL -u $VSPHERE_USER -p $VSPHERE_PASSWORD --vm-user $username --vm-password $password $mod_vm_id\n else\n echo \"Skipping VM: $vm_name because it has no VM ID\"\n fi\n done \u003c \u003c(tail -n +1 $CSV_FILE)\n\nThe script uses the `discover vsphere guest` command to upload and execute the\nguest collection script on the VM.\n\nIt's best to execute this script in the background and direct the output to a\nlog file. To do so, you need to create a text file which is passed as input to\nthe script.\n\n1. Create the text file:\n\n cat \u003c\u003cEOF \u003e\u003e \u003cvar translate=\"no\"\u003eINPUT_FILE\u003c/var\u003e\n \u003cvar translate=\"no\"\u003eCSV_FILES_PREFIX\u003c/var\u003e\u003cvar translate=\"no\"\u003eCSV_FILE_SUFFIX\u003c/var\u003e\n \u003cvar translate=\"no\"\u003eVSPHERE_URL\u003c/var\u003e\n \u003cvar translate=\"no\"\u003eVSPHERE_USER\u003c/var\u003e\n \u003cvar translate=\"no\"\u003eVSPHERE_PASSWORD\u003c/var\u003e\n \u003cvar translate=\"no\"\u003eVM_USER\u003c/var\u003e\n \u003cvar translate=\"no\"\u003eVM_PASSWORD\u003c/var\u003e\n EOF\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eINPUT_FILE\u003c/var\u003e: input filename\n - \u003cvar translate=\"no\"\u003eCSV_FILES_PREFIX\u003c/var\u003e: CSV filename prefix\n - \u003cvar translate=\"no\"\u003eCSV_FILE_SUFFIX\u003c/var\u003e: CSV filename suffix\n - \u003cvar translate=\"no\"\u003eVSPHERE_URL\u003c/var\u003e: the URL for your vCenter Server instance or the vSphere Client\n - \u003cvar translate=\"no\"\u003eVSPHERE_USER\u003c/var\u003e: vCenter username\n - \u003cvar translate=\"no\"\u003eVSPHERE_PASSWORD\u003c/var\u003e: vCenter password\n - \u003cvar translate=\"no\"\u003eVM_USER\u003c/var\u003e: VM username\n - \u003cvar translate=\"no\"\u003eVM_PASSWORD\u003c/var\u003e: VM password\n2. Run the guest collection script:\n\n nohup ./mcdc_collect_vms_guest_tools.sh \u003c\u003cvar translate=\"no\"\u003eINPUT_FILE\u003c/var\u003e \u003e /tmp/mcdc.out 2\u003e&1 &\n\n3. Repeat steps 1 and 2 for each CSV file generated in the previous step.\n\nGenerate an offline assessment report\n-------------------------------------\n\n- After all the data is collected, you can produce a detailed HTML report:\n\n ```bash\n ./mcdc report --format html --full \u003e REPORT_NAME.html\n \n ```\n\nWhat's next\n-----------\n\n- Learn how to [collect guest data from EC2 instances](/migrate/containers/docs/mcdc-aws-collection-tutorial).\n- Learn more about the [`mcdc` CLI](/migration-center/docs/discovery-client-cli-overview).\n- Look [through scripts samples](https://github.com/GoogleCloudPlatform/migrate-to-containers/tree/main/scripts/mcdc)."]]