How to back up volumes with image copy
This guide describes how to create an offsite backup from a VM volume. We will create an image from the volume attached to a virtual machine, download it to the server as a file, create an offsite copy of this file, and then upload it back as a new image in case of any failure. For this purpose, we will be using vinfra, the command-line interface for Virtuozzo Infrastructure.
1. Create a new VM called backup-test with a single boot volume. If your real VM has multiple volumes, all volume IDs will be shown here too.
2. Find out the volume ID:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
| # vinfra service compute server show backup-test
+-----------------+--------------------------------------------+
| Field | Value |
+-----------------+--------------------------------------------+
| config_drive | |
| created | 2022-09-10T17:23:16Z |
| description | |
| fault | |
| flavor | disk: 0 |
| | ephemeral: 0 |
| | extra_specs: {} |
| | original_name: small |
| | ram: 2048 |
| | swap: 0 |
| | vcpus: 1 |
| ha_enabled | True |
| has_pci_devices | False |
| host | vhc-ams-compute06.vstoragedomain |
| host_status | UP |
| id | 6accee37-b829-41ad-a1b0-ba6e28259604 |
| key_name | test_sshkey |
| max_mem | |
| max_vcpu | |
| metadata | {} |
| name | backup-test |
| networks | - id: 93e34234-1530-464c-9e40-6406d103cfc0 |
| | ipam_enabled: true |
| | ips: |
| | - 192.168.11.220 |
| | mac_addr: fa:16:3e:59:73:e8 |
| | name: VHC_Services_NET_test |
| | spoofing_protection: true |
| orig_hostname | vhc-ams-compute06.vstoragedomain |
| placements | [] |
| power_state | RUNNING |
| project_id | 05ce56b6ec2349398d41bd5a77c90a84 |
| status | ACTIVE |
| task_state | |
| updated | 2022-09-10T17:58:02Z |
| user_data | |
| vm_state | active |
| volumes | - delete_on_termination: true |
| | id: e36c4956-9d60-451e-aa64-9c873ede8750 |
| | size: 10 |
| | storage_policy_name: default |
+-----------------+--------------------------------------------+
|
In this command output, the ID of the required volume is e36c4956-9d60-451e-aa64-9c873ede8750.
3. Create a snapshot from the volume:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| # vinfra service compute volume snapshot create --volume e36c4956-9d60-451e-aa64-9c873ede8750 backup-test-snap
+-------------+--------------------------------------+
| Field | Value |
+-------------+--------------------------------------+
| created_at | 2022-09-10T18:13:05.548009+00:00 |
| description | |
| id | 9adc1e1e-2861-4ba3-9107-9e580c8a9624 |
| metadata | {} |
| name | backup-test-snap |
| project_id | 05ce56b6ec2349398d41bd5a77c90a84 |
| size | 10 |
| status | creating |
| volume_id | e36c4956-9d60-451e-aa64-9c873ede8750 |
+-------------+--------------------------------------+
|
4. Create an image from the snapshot:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| # vinfra service compute volume snapshot upload-to-image --name backup-test-image backup-test-snap
+------------------+--------------------------------------+
| Field | Value |
+------------------+--------------------------------------+
| checksum | |
| container_format | bare |
| created_at | |
| disk_format | qcow2 |
| hw_firmware_type | |
| id | 7f2b9db0-5421-491d-8bd6-88153f61656a |
| min_disk | |
| min_ram | |
| name | backup-test-image |
| os_distro | linux |
| os_type | linux |
| placements | [] |
| project_id | |
| protected | False |
| public | False |
| size | 10 |
| status | uploading |
| tags | |
| updated_at | 2022-09-10T18:09:45.061733 |
| virtual_size | |
+------------------+--------------------------------------+
|
In this command output, the ID of the required image is 7f2b9db0-5421-491d-8bd6-88153f61656a.
5. Download the image to the server:
1
2
| # vinfra service compute image save --file backup-test-image.qcow2 7f2b9db0-5421-491d-8bd6-88153f61656a
Operation successful.
|
6. List the files:
1
2
| # ls -la | grep backup-test-image
-rw-r--r-- 1 root root 2937061376 Sep 10 18:18 backup-test-image.qcow2
|
7. Copy the image file to the backup server. We can copy this file to any third-party storage or server by using scp or any other copy tool.
In case of any issues with the VM, we need to copy the image file back to the server and upload it as an image to the Virtuozzo Infrastructure cluster.
8. Create a new image from the backup image file:
1
2
3
4
5
6
7
| # vinfra service compute image create --min-disk 3 --os-distro linux --unprotected --private --disk-format qcow2 --container-format bare --file backup-test-image.qcow2 backup-image-restored
Uploading image to server [elapsed time: 0:00:09]... |
+---------+--------------------------------------+
| Field | Value |
+---------+--------------------------------------+
| task_id | b1748e42-e079-47e9-9210-184b9efef427 |
+---------+--------------------------------------+
|
Let’s check that the new image is successfully created:
1
2
| # vinfra service compute image list | grep backup-image-restored
| 5f81103d-47ee-4680-85cc-357af060fda3 | backup-image-restored | 2937061376 | active | qcow2 |
|
Now, we can create a new VM from this image in the Virtuozzo Infrastructure admin panel, or by using the OpenStack or vinfra command-line interface.
Enjoy!