Zum Inhalt springen

How to clone a VM via CLI

Diese Seite ist noch nicht in deiner Sprache verfügbar. Englische Seite aufrufen

This tutorial will show you how to make a clone of an existing Virtual Machine.

  • Switch over to where you have installed the STACKIT CLI
  • First use the cli to Authenticate to the API and set the project ID
$ stackit auth login
Successfully logged into STACKIT CLI.
$ stackit config set --project-id xxx
$ PROJECTID=xxx
  • List your servers. In the list you should be able to find the server you want to clone.
stackit server list
IDNAMESTATUSAVAILABILITY ZONES
8ce0f20c-8234-4732-a023-6d8034c342femy-serverACTIVEeu01-1
  • To get more detailed information of the server you want to clone, use the describe command.
Terminal window
stackit server describe 8ce0f20c-8234-4732-a023-6d8034c342fe

Server

FIELDVALUE
ID8ce0f20c-8234-4732-a023-6d8034c342fe
NAMEmy-server
STATEACTIVE
AVAILABILITY ZONEeu01-1
BOOT VOLUMEb4c68c72-6130-443e-8cb2-d5db753280d6
POWER STATUSRUNNING
MACHINE TYPEg1.1
LABELSstackit_project_id: 7af69b99-cf67-4ad8-8026-e332489a6d03
VOLUMESb4c68c72-6130-443e-8cb2-d5db753280d6

Attached Network Interfaces

IDNETWORK IDNETWORK NAMEPUBLIC IP
78153ab0-766c-4fc2-8cd2-37c207a6f13ab30d582c-063f-4712-bd85-5d3ef929bb71defaultxxx
  • now you need to get detailed information of the drive you want to clone and create a duplicate (e.g. minimum is the same amount of storage etc.)
    stackit volume describe
Terminal window
stackit volume describe b4c68c72-6130-443e-8cb2-d5db753280d6
FIELDVALUE
IDb4c68c72-6130-443e-8cb2-d5db753280d6
NAME
STATEATTACHED
VOLUME SIZE (GB)20
PERFORMANCE CLASSstorage_premium_perf1
AVAILABILITY ZONEeu01-1
SOURCE260b040a-fee8-4002-845c-79abac2b801c
SERVER8ce0f20c-8234-4732-a023-6d8034c342fe
LABELSattached_mode: rw
  • Create a new volume which uses the old volume as its source, this creates a clone.
Terminal window
stackit volume create --availability-zone eu01-1 --source-type volume --source-id b4c68c72-6130-443e-8cb2-d5db753280d6 --name clone-volume
  • After the creation is complete you can check it with the describe command
    stackit volume describe
Terminal window
stackit volume describe e431ec98-1b92-4006-9a8c-9e4b4174fe54
FIELDVALUE
IDe431ec98-1b92-4006-9a8c-9e4b4174fe54
NAMEclone-volume
STATEAVAILABLE
VOLUME SIZE (GB)20
PERFORMANCE CLASSstorage_premium_perf1
AVAILABILITY ZONEeu01-1
SOURCEb4c68c72-6130-443e-8cb2-d5db753280d6
stackit server create --machine-type g1.1 --boot-volume-source-type volume --boot-volume-source-id ee546eb0-4d5f-49c4-a8fb-98472e79060e --name cloned-server
stackit server list
IDNAMESTATUSAVAILABILITY ZONES
5ae38747-1feb-4ff1-b480-2210561fed74cloned-serverACTIVEeu01-1
8ce0f20c-8234-4732-a023-6d8034c342femy-serverACTIVEeu01-1

(Optional) Transferring fixed IP addresses

Section titled “(Optional) Transferring fixed IP addresses”

To begin the IP transfer, you can start with listing your VMs and Network Interfaces. Note down the network-interface ID.

Terminal window
stackit server describe <Server-ID>

Server

FIELDVALUE
ID[Server-ID]
NAMEnic-transfer
STATEACTIVE
AVAILABILITY ZONEeu01-m
BOOT VOLUME08c27697-8679-4dce-8895-4300d8f6469c
POWER STATUSRUNNING
MACHINE TYPEg1.1
VOLUMES08c27697-8679-4dce-8895-4300d8f6469c

Attached Network Interfaces

IDNETWORK IDNETWORK NAMEPUBLIC IP
314e22c3-fa5c-45d2-96a2-c628ec5af6a8[Network-ID]default
Terminal window
stackit network-interface describe 314e22c3-fa5c-45d2-96a2-c628ec5af6a8 --network-id $NETWORKID
FIELDVALUE
ID314e22c3-fa5c-45d2-96a2-c628ec5af6a8
NETWORK ID[Network-ID]
IPV410.1.0.128
MACfa:16:3f:74:7e:c5
NIC SECURITYtrue
STATUSACTIVE
TYPEserver
SECURITY GROUPS78286e55-33d2-43fa-b56d-fd5607ac7277

Now you can remove the network-interface from the server.

Terminal window
stackit curl -X DELETE https://iaas.api.eu01.stackit.cloud/v1/projects/$PROJECTID/servers/$SERVERID/nics/314e22c3-fa5c-45d2-96a2-c628ec5af6a8

To check if the nic was removed successfully you can use the network-interfaces list command and confirm that status column is set to DOWN.

Terminal window
stackit network-interface list --network-id $NETWORKID
IDNAMENIC SECURITYSTATUSTYPE
77ead02b-1f58-4e27-97c4-b0b866b21e30falseACTIVEgateway
314e22c3-fa5c-45d2-96a2-c628ec5af6a8trueDOWNserver
05e90efb-16b5-4427-8625-64db4f9c450efalseDOWNmetadata
3d203603-fed2-4d71-9b58-e2cc379e7305trueACTIVEserver

Now you can attach the nic to the 2nd server.

Terminal window
stackit curl -X PUT https://iaas.api.eu01.stackit.cloud/v1/projects/$PROJECTID/servers/$server/nics/$nic

Again you can use the list and describe command to check if the transfer was successful.

Terminal window
stackit server describe <Server-ID>

Server

FIELDVALUE
ID[Server-ID]
NAMEnic-transfer-target
STATEACTIVE
AVAILABILITY ZONEeu01-1
BOOT VOLUMEee546eb0-4d5f-49c4-a8fb-98472e79060e
POWER STATUSRUNNING
MACHINE TYPEg1.1
VOLUMESee546eb0-4d5f-49c4-a8fb-98472e79060e

Attached Network Interfaces

IDNETWORK IDNETWORK NAMEPUBLIC IP
314e22c3-fa5c-45d2-96a2-c628ec5af6a8[Network-ID]default

To transfer the public IP to the another VM, you can start with listing your public IPs.

Terminal window
stackit public-ip list

The next step is to detach the public IP from the old VM.

Terminal window
stackit server public-ip detach <PublicIP-ID> --server-id <Server-ID>

Now the public IP can be attached to your new VM.

Terminal window
stackit server public-ip attach <PublicIP-ID> --server-id <Server2-ID>

If you want to see that everything went well you can again list your public IPs see that the IP moved to the other VM.

Terminal window
stackit public-ip list
IDIP ADDRESSUSED BY
28d04b49-b1ed-44ae-b58b-b2b9d2e1219dxx.xx.xx.xx[Server2-ID]