summaryrefslogtreecommitdiff
path: root/doc/source/user/backup-db.rst
blob: 9a1a10e5b50aa4d6ea99d4c24b1cd77f4494a28d (plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
=============================
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:

1. The container name can be specified when creating backups, this could
   override either the backup strategy setting or the default setting in Trove
   configuration.

2. Users could create backup strategy either for the project scope or for a
   particular instance.

3. 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**

   1. Make sure you have created an instance, e.g. in this example, we use the following instance:

      .. code-block:: console

          $ 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   |
          +--------------------------------------+--------+-----------+-------------------+--------+-----------+------+

   2. Optionally, create a backup strategy for the instance. You can also specify a different swift container name (``--swift-container``) when creating the backup.

      .. code-block:: console

          $ 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 :command:`openstack database backup create`
   command. In this example, the backup is called ``backup1``.

   .. code-block:: console

      $ 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 :command:`openstack database backup list` command or
   :command:`openstack database backup show` command to check the backup
   status:

   .. code-block:: console

      $ 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.

   .. code-block:: console

      $ 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 the :command:`openstack database instance create`
   command to create a new database instance called ``guest2``.

   -  Specify that the new ``guest2`` instance has the same flavor
      (``10``) and the same root volume size (``2``) as the original
      ``guest1`` instance.

   -  Use the ``--backup`` argument to indicate that this new
      instance is based on the backup artifact identified by
      ``BACKUP_ID``. In this example, replace ``BACKUP_ID`` with
      ``8af30763-61fd-4aab-8fe8-57d528911138``.

   .. code-block:: console

      $ 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}                     |
      +-------------------+----------------------------------------------+

#. **Verify backup**

   Now check that the new ``guest2`` instance has the same
   characteristics as the original ``guest1`` instance.

   Start by getting the ID of the new ``guest2`` instance.

   .. code-block:: console

      $ 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 :command:`openstack database instance show` command to display information about the new
   guest2 instance. Pass in guest2's ``INSTANCE_ID``, which is
   ``ac7a2b35-a9b4-4ff6-beac-a1bcee86d04b``.

   .. code-block:: console

      $ 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 :command:`openstack database db list` command to check that the original
   databases (``db1`` and ``db2``) are present on the restored instance.

   .. code-block:: console

      $ openstack database db list INSTANCE_ID
      +--------------------+
      |        name        |
      +--------------------+
      |        db1         |
      |        db2         |
      | performance_schema |
      |        test        |
      +--------------------+

   Use the :command:`openstack database user list` command to check that the original user
   (``user1``) is present on the restored instance.

   .. code-block:: console

      $ 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 access ``guest2``. Provide them
   with ``guest2``'s name, IP address, and any other information they
   might need. (You can get this information by using the
   :command:`openstack database instance show` command.)

#. **Clean up**

   At this point, you might want to delete the disabled ``guest1``
   instance, by using the :command:`openstack database instance delete` command.

   .. code-block:: console

      $ 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:

.. code-block:: console

    $ 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          |
    +-------------+--------------------------------------+