Change-Id: Icadc95ea54e4509dc148f8e84f2eaac5840509f3
13 KiB
Backup and restore a database
You can use Database services to backup a database and store the backup artifact in the Object Storage service. Later on, if the original database is damaged, you can use the backup artifact to restore the database. The restore process creates a new database instance.
The backup data is stored in OpenStack Swift, the user is able to customize which container to store the data. The following ways are described in the order of precedence from greatest to least:
- The container name can be specified when creating backups, this could override either the backup strategy setting or the default setting in Trove configuration.
- Users could create backup strategy either for the project scope or for a particular instance.
- If not configured by the end user, will use the default value in Trove configuration.
Caution
If the objects in the backup container are manually deleted, the database can't be properly restored.
This example shows you how to create backup strategy, create backup and restore instance from the backup.
Before creating backup
Make sure you have created an instance, e.g. in this example, we use the following instance:
$ openstack database instance list +--------------------------------------+--------+-----------+-------------------+--------+-----------+------+ | id | name | datastore | datastore_version | status | flavor_id | size | +--------------------------------------+--------+-----------+-------------------+--------+-----------+------+ | 97b4b853-80f6-414f-ba6f-c6f455a79ae6 | guest1 | mysql | mysql-5.5 | ACTIVE | 10 | 2 | +--------------------------------------+--------+-----------+-------------------+--------+-----------+------+
Optionally, create a backup strategy for the instance. You can also specify a different swift container name (
--swift-container
) when creating the backup.$ openstack database backup strategy create --instance-id 97b4b853-80f6-414f-ba6f-c6f455a79ae6 --swift-container my-trove-backups +-----------------+--------------------------------------+ | Field | Value | +-----------------+--------------------------------------+ | backend | swift | | instance_id | 97b4b853-80f6-414f-ba6f-c6f455a79ae6 | | project_id | 922b47766bcb448f83a760358337f2b4 | | swift_container | my-trove-backups | +-----------------+--------------------------------------+
Backup the database instance
Back up the database instance by using the
openstack database backup create
command. In this example, the backup is calledbackup1
.$ openstack database backup create 97b4b853-80f6-414f-ba6f-c6f455a79ae6 backup1 +-------------+--------------------------------------+ | Property | Value | +-------------+--------------------------------------+ | created | 2014-03-18T17:09:07 | | description | None | | id | 8af30763-61fd-4aab-8fe8-57d528911138 | | instance_id | 97b4b853-80f6-414f-ba6f-c6f455a79ae6 | | locationRef | None | | name | backup1 | | parent_id | None | | size | None | | status | NEW | | updated | 2014-03-18T17:09:07 | +-------------+--------------------------------------+
Later on, use either
openstack database backup list
command oropenstack database backup show
command to check the backup status:$ openstack database backup list +--------------------------------------+--------------------------------------+---------+-----------+-----------+---------------------+ | id | instance_id | name | status | parent_id | updated | +--------------------------------------+--------------------------------------+---------+-----------+-----------+---------------------+ | 8af30763-61fd-4aab-8fe8-57d528911138 | 97b4b853-80f6-414f-ba6f-c6f455a79ae6 | backup1 | COMPLETED | None | 2014-03-18T17:09:11 | +--------------------------------------+--------------------------------------+---------+-----------+-----------+---------------------+ $ openstack database backup show 8af30763-61fd-4aab-8fe8-57d528911138 +-------------+----------------------------------------------------+ | Property | Value | +-------------+----------------------------------------------------+ | created | 2014-03-18T17:09:07 | | description | None | | id | 8af...138 | | instance_id | 97b...ae6 | | locationRef | http://10.0.0.1:.../.../8af...138.xbstream.gz.enc | | name | backup1 | | parent_id | None | | size | 0.17 | | status | COMPLETED | | updated | 2014-03-18T17:09:11 | +-------------+----------------------------------------------------+
Check the backup data in Swift
Check the container is created and the backup data is saved as objects inside the container.
$ openstack container list +------------------+ | Name | +------------------+ | my-trove-backups | +------------------+ $ openstack object list my-trove-backups +--------------------------------------------------+ | Name | +--------------------------------------------------+ | 8af30763-61fd-4aab-8fe8-57d528911138.xbstream.gz | +--------------------------------------------------+
Restore a database instance
Now assume that the
guest1
database instance is damaged and you need to restore it. In this example, you use theopenstack database instance create
command to create a new database instance calledguest2
.- Specify that the new
guest2
instance has the same flavor (10
) and the same root volume size (2
) as the originalguest1
instance. - Use the
--backup
argument to indicate that this new instance is based on the backup artifact identified byBACKUP_ID
. In this example, replaceBACKUP_ID
with8af30763-61fd-4aab-8fe8-57d528911138
.
$ openstack database instance create guest2 --flavor 10 --size 2 --nic net-id=$network_id --backup BACKUP_ID +-------------------+----------------------------------------------+ | Property | Value | +-------------------+----------------------------------------------+ | created | 2014-03-18T17:12:03 | | datastore | {u'version': u'mysql-5.5', u'type': u'mysql'}| |datastore_version | mysql-5.5 | | flavor | {u'id': u'10', u'links': [{u'href': ...]} | | id | ac7a2b35-a9b4-4ff6-beac-a1bcee86d04b | | name | guest2 | | status | BUILD | | updated | 2014-03-18T17:12:03 | | volume | {u'size': 2} | +-------------------+----------------------------------------------+
- Specify that the new
Verify backup
Now check that the new
guest2
instance has the same characteristics as the originalguest1
instance.Start by getting the ID of the new
guest2
instance.$ openstack database instance list +-----------+--------+-----------+-------------------+--------+-----------+------+ | id | name | datastore | datastore_version | status | flavor_id | size | +-----------+--------+-----------+-------------------+--------+-----------+------+ | 97b...ae6 | guest1 | mysql | mysql-5.5 | ACTIVE | 10 | 2 | | ac7...04b | guest2 | mysql | mysql-5.5 | ACTIVE | 10 | 2 | +-----------+--------+-----------+-------------------+--------+-----------+------+
Use the
openstack database instance show
command to display information about the new guest2 instance. Pass in guest2'sINSTANCE_ID
, which isac7a2b35-a9b4-4ff6-beac-a1bcee86d04b
.$ openstack database instance show INSTANCE_ID +-------------------+--------------------------------------+ | Property | Value | +-------------------+--------------------------------------+ | created | 2014-03-18T17:12:03 | | datastore | mysql | | datastore_version | mysql-5.5 | | flavor | 10 | | id | ac7a2b35-a9b4-4ff6-beac-a1bcee86d04b | | ip | 10.0.0.3 | | name | guest2 | | status | ACTIVE | | updated | 2014-03-18T17:12:06 | | volume | 2 | | volume_used | 0.18 | +-------------------+--------------------------------------+
Note that the data store, flavor ID, and volume size have the same values as in the original
guest1
instance.Use the
openstack database db list
command to check that the original databases (db1
anddb2
) are present on the restored instance.$ openstack database db list INSTANCE_ID +--------------------+ | name | +--------------------+ | db1 | | db2 | | performance_schema | | test | +--------------------+
Use the
openstack database user list
command to check that the original user (user1
) is present on the restored instance.$ openstack database user list INSTANCE_ID +--------+------+-----------+ | name | host | databases | +--------+------+-----------+ | user1 | % | db1, db2 | +--------+------+-----------+
Notify users
Tell the users who were accessing the now-disabled
guest1
database instance that they can now accessguest2
. Provide them withguest2
's name, IP address, and any other information they might need. (You can get this information by using theopenstack database instance show
command.)Clean up
At this point, you might want to delete the disabled
guest1
instance, by using theopenstack database instance delete
command.$ openstack database instance delete INSTANCE_ID
Create incremental backups
Incremental backups let you chain together a series of backups. You start with a regular backup. Then, when you want to create a subsequent incremental backup, you specify the parent backup.
Restoring a database instance from an incremental backup is the same as creating a database instance from a regular backup. the Database service handles the process of applying the chain of incremental backups.
Create an incremental backup based on a parent backup:
$ openstack database backup create INSTANCE_ID backup1.1 --parent BACKUP_ID
+-------------+--------------------------------------+
| Property | Value |
+-------------+--------------------------------------+
| created | 2014-03-19T14:09:13 |
| description | None |
| id | 1d474981-a006-4f62-b25f-43d7b8a7097e |
| instance_id | 792a6a56-278f-4a01-9997-d997fa126370 |
| locationRef | None |
| name | backup1.1 |
| parent_id | 6dc3a9b7-1f3e-4954-8582-3f2e4942cddd |
| size | None |
| status | NEW |
| updated | 2014-03-19T14:09:13 |
+-------------+--------------------------------------+