Pre-requisite: EWC - OpenStack Command-Line client |
Before restoring resources in OpenStack, it's important to understand the difference between three primary methods:
Choose the appropriate method based on your recovery needs: instance snapshots for full system recovery or replication, volume snapshots for accident prevention and recovery or volume backups for full data security and recovery.
Furthermore, there are two different restoration methods, according to whether the restoration replaces an existing resource or not:
| Before starting make sure you are in the machine where you configured openstack client, have the required openstack credentials and you can run openstack commands as described in EWC - OpenStack Command-Line client |
| The restoration of backups or snapshots of VMs and volumes must be run outside from said VMs and volumes, specially in the case of in-place restoration, as the existing resource is completely replaced. |
In-place restoration of VM snapshots can be performed with OpenStack by replacing the underlying disk of an existing VM with an image. In this way it is not necessary to create a new VM instance, but rather replace an existing one. This can be achieve by running:
openstack server rebuild <instance> --image <image_snapshot> |
where
<instance> : The name or id of the existing VM<image_snapshot> : Name or id of the snapshot image of the VM previously createdInstead of performing an in-place restoration, it is possible to create a new VM using the image snapshot. This is done in the same manner as for creating a new instance, see EWC - How to create a VM using the Openstack CLI, using the command
openstack server create --flavor <flavor_name> --image <image_snapshot> --key-name <keyname> --network <network_name> --security-group <security_group_name> <vm_name> |
where here the <image_name> is the name or id of the image snapshot. It is worth noting that the image snapshot does not contain information about the flavor, networks or security groups, and therefore these need to be manually provided. Restoring a snapshot onto a flavor of smaller size than the original will result in a failure.
| An important consequence of restoring a VM in this manner, either in-place or not, is that the image snapshot becomes the underlying image of the VM, instead of the original, e.g. Ubuntu or Rocky OS, and therefore the image can no longer be removed from the list of images available in the cloud. |
The restoration of a volume snapshot can also be done in-place, or by creating a new volume. To restore an existing volume from a snapshot, one needs to use the command
openstack volume revert <snapshot> |
where: <snapshot> : name or id of the snapshot to restore. Since in-place restoration replaces an existing volume, it is necessary to detach the volume from the instance first and reattach it after the restoration. One can detach a volume from an instance with
openstack server remove volume <server> <volume> |
with <server> and <volume> the name or id of the instance or volume, respectively. And it can be reattached after restoration with
openstack server add volume <server> <volume> |
To restore a volume snapshot to a new volume, a new volume must be created, with the snapshot as the source. This can be done with the command
openstack volume create --snapshot <snapshot> <name> |
with <snapshot> the name or id of the snapshot to restore, and <name> the name of the new volume.
The restoration of a volume backup can also be done in-place, or by creating a new volume. Irrespective of the method, one can restore a volume backup with the command
openstack volume backup restore [--force] <backup> <volume> |
where:
--force : optional argument to force a restoration of an existing volume.<snapshot> : name or id of the backup to restore<volume> : name or id of the existing volume to replace, or the name of a new volume to createIn the case of an in-place restoration, it is necessary to detach the volume first and reattach it after the restoration. Detaching and reattaching the volume to an instance can be done in the same way as for Volume Snapshots.
WIP
WIP