mirror of
https://github.com/RGBCube/vmware-to-proxmox-migration-script
synced 2025-07-25 23:47:45 +00:00
switched to key-based auth for proxmox and added gitignore
This commit is contained in:
parent
0b69aaf15f
commit
60f1373b4e
2 changed files with 8 additions and 9 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
*.ova
|
||||||
|
|
|
@ -25,8 +25,6 @@ read -sp "Enter the ESXi server password: " ESXI_PASSWORD
|
||||||
echo
|
echo
|
||||||
PROXMOX_SERVER=$(get_input "Enter the Proxmox server hostname/IP")
|
PROXMOX_SERVER=$(get_input "Enter the Proxmox server hostname/IP")
|
||||||
PROXMOX_USERNAME=$(get_input "Enter the Proxmox server username")
|
PROXMOX_USERNAME=$(get_input "Enter the Proxmox server username")
|
||||||
read -sp "Enter the Proxmox server password: " PROXMOX_PASSWORD
|
|
||||||
echo
|
|
||||||
VM_NAME=$(get_input "Enter the name of the VM to migrate")
|
VM_NAME=$(get_input "Enter the name of the VM to migrate")
|
||||||
|
|
||||||
# Export VM from VMware
|
# Export VM from VMware
|
||||||
|
@ -47,23 +45,22 @@ function export_vmware_vm() {
|
||||||
# Transfer VM to Proxmox
|
# Transfer VM to Proxmox
|
||||||
function transfer_vm() {
|
function transfer_vm() {
|
||||||
echo "Transferring VM to Proxmox..."
|
echo "Transferring VM to Proxmox..."
|
||||||
echo $PROXMOX_PASSWORD | ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "mkdir -p /var/vm-migration"
|
scp $VM_NAME.ova $PROXMOX_USERNAME@$PROXMOX_SERVER:/var/vm-migration/
|
||||||
echo $PROXMOX_PASSWORD | scp $VM_NAME.ova $PROXMOX_USERNAME@$PROXMOX_SERVER:/var/vm-migration/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Convert VM to Proxmox format
|
# Convert VM to Proxmox format
|
||||||
function convert_vm() {
|
function convert_vm() {
|
||||||
echo "Converting VM to Proxmox format..."
|
echo "Converting VM to Proxmox format..."
|
||||||
echo $PROXMOX_PASSWORD | ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "tar -xvf /var/vm-migration/$VM_NAME.ova -C /var/vm-migration/"
|
ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "tar -xvf /var/vm-migration/$VM_NAME.ova -C /var/vm-migration/"
|
||||||
local vmdk_file=$(ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "find /var/vm-migration -name '*.vmdk'")
|
local vmdk_file=$(ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "find /var/vm-migration -name '*.vmdk'")
|
||||||
echo $PROXMOX_PASSWORD | ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "qemu-img convert -f vmdk -O qcow2 $vmdk_file /var/vm-migration/$VM_NAME.qcow2"
|
ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "qemu-img convert -f vmdk -O qcow2 $vmdk_file /var/vm-migration/$VM_NAME.qcow2"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get the next VM ID
|
# Get the next VM ID
|
||||||
function get_next_vm_id() {
|
function get_next_vm_id() {
|
||||||
echo "Getting next VM ID..."
|
echo "Getting next VM ID..."
|
||||||
# Get the list of VMs, sort by VM ID, get the last one, and increment by one
|
# Get the list of VMs, sort by VM ID, get the last one, and increment by one
|
||||||
NEXT_VM_ID=$(echo $PROXMOX_PASSWORD | ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "pvesh get /cluster/resources --type vm" | jq -r '.[].vmid' | sort -n | tail -1)
|
NEXT_VM_ID=$(ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "pvesh get /cluster/resources --type vm" | jq -r '.[].vmid' | sort -n | tail -1)
|
||||||
let "NEXT_VM_ID++"
|
let "NEXT_VM_ID++"
|
||||||
echo $NEXT_VM_ID
|
echo $NEXT_VM_ID
|
||||||
}
|
}
|
||||||
|
@ -76,11 +73,11 @@ function create_proxmox_vm() {
|
||||||
echo "Error: Invalid VM ID '$VM_ID'."
|
echo "Error: Invalid VM ID '$VM_ID'."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo $PROXMOX_PASSWORD | ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "qm create $VM_ID --name $VM_NAME --memory 2048 --cores 2 --net0 virtio,bridge=vmbr0"
|
ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "qm create $VM_ID --name $VM_NAME --memory 2048 --cores 2 --net0 virtio,bridge=vmbr0"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Main process
|
# Main process
|
||||||
export_vmware_vm
|
export_vmware_vm
|
||||||
transfer_vm
|
transfer_vm
|
||||||
convert_vm
|
convert_vm
|
||||||
create_proxmox_vm
|
create_proxmox_vm
|
Loading…
Add table
Add a link
Reference in a new issue