ZStack allows user to create snapshots from VM's root volume and data volumes. Unlike majority of IaaS software only allowing users to create at most one snapshot chain, ZStack allows users to create a snapshot tree that each branch is a snapshot chain.
In this example, we will create a snapshot tree with two branches from a VM's root volume.
We assume you have followed Quick Installation Guide to install ZStack on a single Linux machine, and the ZStack management node is up and running. To use the command line tool, type below command in your shell terminal:
#zstack-cli
To make things simple, we assume you have only one Linux machine with one network card that can access the internet; besides, there are some other requirements:
sudo su
passwd root
Based on those requirements, we assume below setup information:
open zstack-cli and login with admin/password:
>>> LogInByAccount accountName=admin password=password
create a zone with name 'ZONE1' and description 'zone 1':
>>> CreateZone name=ZONE1 description='zone 1'
create a cluster with name 'CLUSTER1' and hypervisorType 'KVM' under zone 'ZONE1':
QueryZone fields=uuid, name=ZONE1
>>> CreateCluster name=CLUSTER1 hypervisorType=KVM zoneUuid=b5ba18197f7843308cd26f87eab933c5
add KVM Host 'HOST1' under 'CLUSTER1' with correct host IP address and root username and password:
QueryCluster fields=uuid, name=CLUSTER1
>>> AddKVMHost name=HOST1 managementIp=172.20.11.34 username=root password=password clusterUuid=e630ebdb5f7742f3818fd998e91d35a8
add Primary Storage 'PRIMAYR-STORAGE1' with NFS URI '/zstack_ps' under zone 'ZONE1':
QueryZone fields=uuid, name=ZONE1
>>> AddLocalPrimaryStorage name=PRIMARY-STORAGE1 url=/zstack_ps zoneUuid=b5ba18197f7843308cd26f87eab933c5
attach 'PRIMARY-STORAGE1' to 'CLUSTER1':
QueryCluster fields=uuid, name=CLUSTER1
QueryPrimaryStorage fields=uuid, name=PRIMARY-STORAGE1
>>> AttachPrimaryStorageToCluster primaryStorageUuid=1b952f1e74a747dfb89ef3bdb9e8a821 clusterUuid=e630ebdb5f7742f3818fd998e91d35a8
add sftp Backup Storage 'BACKUP-STORAGE1' with backup storage host IP address('172.20.11.34'), root username('root'), password('password') and sftp folder path('/zstack_bs'):
>>> AddSftpBackupStorage name=BACKUP-STORAGE1 hostname=172.20.11.34 username=root password=password url=/zstack_bs
attach new created Backup Storage('BACKUP-STORAGE1') to zone('ZONE1'):
QueryZone fields=uuid, name=ZONE1
QueryBackupStorage fields=uuid, name=BACKUP-STORAGE1
>>> AttachBackupStorageToZone backupStorageUuid=ccc8214bfc2344e5a58c2ec23de3b348 zoneUuid=b5ba18197f7843308cd26f87eab933c5
add Image('image') with format 'qcow2', 'RootVolumeTemplate' type, 'Linux' platform and image URL('http://cdn.zstack.io/product_downloads/images/zstack-image.qcow2') to backup storage ('BACKUP-STORAGE1'):
QueryBackupStorage fields=uuid, name=BACKUP-STORAGE1
>>> AddImage name=image mediaType=RootVolumeTemplate platform=Linux url=http://192.168.200.100/mirror/diskimages/zstack-image-1.4.qcow2 backupStorageUuids=ccc8214bfc2344e5a58c2ec23de3b348 format=qcow2
this image will be used as user VM image.
Add another Image('VRImage') with format 'qcow2' and image URL('http://cdn.zstack.io/product_downloads/images/zstack-image.qcow2') to backup storage ('BACKUP-STORAGE1'):
QueryBackupStorage fields=uuid, name=BACKUP-STORAGE1
http://cdn.zstack.io/product_downloads/vrouter/zstack-vrouter-2.0.0.qcow2
>>> AddImage name=VRImage url=http://192.168.200.100/mirror/diskimages/zstack-vrouter-latest.qcow2 backupStorageUuids=ccc8214bfc2344e5a58c2ec23de3b348 format=qcow2
create No Vlan L2 Network 'FLAT-L2' with physical interface as 'eth0' under 'ZONE1':
QueryZone fields=uuid, name=ZONE1
>>> CreateL2NoVlanNetwork name=FLAT-L2 physicalInterface=eth0 zoneUuid=b5ba18197f7843308cd26f87eab933c5
attach 'FLAT-L2' to 'CLUSTER1':
QueryCluster fields=uuid, name=CLUSTER1
QueryL2Network fields=uuid, name=FLAT-L2
>>> AttachL2NetworkToCluster l2NetworkUuid=ea5d8266bd4e4c2bb3ebf5cf5509b136 clusterUuid=e630ebdb5f7742f3818fd998e91d35a8
create 'FLAT-L3' L3 network on FLAT-L2 L2 network:
QueryL2Network fields=uuid, name=FLAT-L2
>>> CreateL3Network name=FLAT-L3 l2NetworkUuid=ea5d8266bd4e4c2bb3ebf5cf5509b136
create IP Range for 'FLAT-L3':
QueryL3Network fields=uuid, name=FLAT-L3
>>> AddIpRange name=FLAT-IP-RANGE l3NetworkUuid=23f3a0fde8744a699f86b27899be3183 startIp=10.0.101.100 endIp=10.0.101.150 netmask=255.255.255.0 gateway=10.0.101.1
add DNS for 'FLAT-L3':
QueryL3Network fields=uuid, name=FLAT-L3
>>> AddDnsToL3Network l3NetworkUuid=23f3a0fde8744a699f86b27899be3183 dns=8.8.8.8
we need to get available network service provider UUID, before add any virtual router service to L3 network:
>>> QueryNetworkServiceProvider
there are 2 available network service providers. The 'VirtualRouter' could provide 'DHCP', 'SNAT', 'DNS', 'PortForwarding' and 'Eip' services. The 'SecurityGroup' could provide 'SecurityGroup' service.
attach VirtualRouter services 'DHCP', 'DNS' to 'FLAT-L3':
QueryL3Network fields=uuid, name=FLAT-L3
QueryNetworkServiceProvider fields=uuid, name=VirtualRouter
>>> AttachNetworkServiceToL3Network networkServices="{'1b93ca42c7bb47d9a6295e58ad8ef1b7':['Userdata','DHCP','Eip']}" l3NetworkUuid=23f3a0fde8744a699f86b27899be3183
create a guest VM instance offering 'small-instance' with 1 512Mhz CPU and 128MB memory:
>>> CreateInstanceOffering name=small-instance memorySize=134217728 cpuNum=1
create a new guest VM instance with instance offering 'small-instance', image 'zs-sample-image', L3 network 'FLAT-L3', name 'VM1' and hostname 'vm1'
QueryInstanceOffering fields=uuid, name=small-instance
QueryImage fields=uuid, name=zs-sample-image
QueryL3Network fields=uuid, name=FLAT-L3
>>> CreateVmInstance name=VM1 instanceOfferingUuid=ce994286008d41f6be75e0f804bce47c imageUuid=6874474809df4d2292d3503884e0096e l3NetworkUuids=23f3a0fde8744a699f86b27899be3183
from VM creation result, you can get the new created VM IP address is 10.0.101.140
first of all, we are going to create a flag file in VM1, so later on we can use this file to confirm that we revert
to the correct snapshot. You can ssh to Login onto it through any machine that can reach subnet 10.0.101.0/24 and
use touch flag1
to create the flag:
QueryVmNic fields=ip vmInstance.name=VM1
# ssh root@10.0.101.138 'touch flag1'
then, since we are using CentOS6.x, we need to stop VM1, before create snapshot:
QueryVmInstance fields=uuid, name=VM1
>>> StopVmInstance uuid=c55dc43bd0344c48931cbf08102647a9
create snapshot 'sp1' for VM1's root volume: 81732342589546e9b80363e504556fdc:
QueryVolume fields=uuid vmInstance.name=VM1
>>> CreateVolumeSnapshot name=sp1 volumeUuid=81732342589546e9b80363e504556fdc
repeat above step to create two more snapshots: sp2 and sp3:
use VM1's volume uuid to query Volume Snapshot Tree, we can see 3 snapshots' details:
QueryVolume fields=uuid vmInstance.name=VM1
>>> QueryVolumeSnapshotTree volumeUuid=81732342589546e9b80363e504556fdc
start VM1, before doing later operations:
QueryVmInstance fields=uuid name=VM1
>>> StartVmInstance uuid=c55dc43bd0344c48931cbf08102647a9
use instructions in the beginning of this section to ssh VM1 and delete the flag file 'flag1':
# ssh root@10.0.101.138 '/bin/rm -f flag1; ls'
to revert the root volume to a prior snapshot, we need to stop the VM1 again:
QueryVmInstance fields=uuid name=VM1
>>> StopVmInstance uuid=c55dc43bd0344c48931cbf08102647a9
revert volume to snapshot 1:
QueryVolumeSnapshot fields=uuid name=sp1
>>> RevertVolumeFromSnapshot uuid=9c2ab564bbe04181997f2cce64b46a27
now start the VM again:
QueryVmInstance fields=uuid name=VM1
>>> StartVmInstance uuid=c55dc43bd0344c48931cbf08102647a9
once VM1 startup, use ssh to check the flag file 'flag1', you should see the file we deleted before now comes back, which confirms we have successfully reverted the root volume to the snapshot 'sp1':
# ssh root@10.0.101.138 'ls flag*'
stop VM1:
QueryVmInstance fields=uuid name=VM1
>>> StopVmInstance uuid=c55dc43bd0344c48931cbf08102647a9
use former instructions to create two more snapshots: 'sp1.1' and 'sp1.2':
QueryVolume fields=uuid vmInstance.name=VM1
>>> CreateVolumeSnapshot name=sp1.1 volumeUuid=81732342589546e9b80363e504556fdc
QueryVolume fields=uuid vmInstance.name=VM1
>>> CreateVolumeSnapshot name=sp1.2 volumeUuid=81732342589546e9b80363e504556fdc
query the snapshot tree again, now you should see two branches that are both derived from snapshot 'sp1':
In this tutorial, we showed you how to create volume snapshot in ZStack. Besides reverting a volume to an old snapshot, you can also create image template and volumes from snapshots. For details, please visit Volume Snapshot in user manual.