]> git.proxmox.com Git - ceph.git/blob - ceph/doc/rbd/rbd-snapshot.rst
96dec81c87c32fa6ac596e0ca1c8df39797239e7
[ceph.git] / ceph / doc / rbd / rbd-snapshot.rst
1 ===========
2 Snapshots
3 ===========
4
5 .. index:: Ceph Block Device; snapshots
6
7 A snapshot is a read-only logical copy of an image at a particular point in
8 time: a checkpoint. One of the advanced features of Ceph block devices is
9 that you can create snapshots of images to retain point-in-time state history.
10 Ceph also supports snapshot layering, which allows you to clone images (e.g., a
11 VM image) quickly and easily. Ceph block device snapshots are managed using the
12 ``rbd`` command and multiple higher level interfaces, including `QEMU`_,
13 `libvirt`_, `OpenStack`_ and `CloudStack`_.
14
15 .. important:: To use RBD snapshots, you must have a running Ceph cluster.
16
17 .. note:: Because RBD does not know about any filesystem within an image
18 (volume), snapshots are only `crash-consistent` unless they are
19 coordinated within the mounting (attaching) operating system.
20 We therefore recommend that you pause or stop I/O before taking a snapshot.
21 If the volume contains a filesystem, it should be in an internally
22 consistent state before taking a snapshot. Snapshots taken without
23 write quiescing may need an `fsck` pass before subsequent
24 mounting. To quiesce `I/O` you can use `fsfreeze` command. See
25 `fsfreeze(8)` man page for more details.
26 For virtual machines, `qemu-guest-agent` can be used to automatically
27 freeze file systems when creating a snapshot.
28
29 .. ditaa::
30
31 +------------+ +-------------+
32 | {s} | | {s} c999 |
33 | Active |<-------*| Snapshot |
34 | Image | | of Image |
35 | (stop i/o) | | (read only) |
36 +------------+ +-------------+
37
38
39 Cephx Notes
40 ===========
41
42 When `cephx`_ authentication is enabled (it is by default), you must specify a
43 user name or ID and a path to the keyring containing the corresponding key. See
44 :ref:`User Management <user-management>` for details. You may also set the
45 ``CEPH_ARGS`` environment variable to avoid re-entry of these parameters. ::
46
47 rbd --id {user-ID} --keyring=/path/to/secret [commands]
48 rbd --name {username} --keyring=/path/to/secret [commands]
49
50 For example::
51
52 rbd --id admin --keyring=/etc/ceph/ceph.keyring [commands]
53 rbd --name client.admin --keyring=/etc/ceph/ceph.keyring [commands]
54
55 .. tip:: Add the user and secret to the ``CEPH_ARGS`` environment
56 variable so that you don't need to enter them each time.
57
58
59 Snapshot Basics
60 ===============
61
62 The following procedures demonstrate how to create, list, and remove
63 snapshots using the ``rbd`` command.
64
65 Create Snapshot
66 ---------------
67
68 To create a snapshot with ``rbd``, specify the ``snap create`` option, the pool
69 name and the image name. ::
70
71 rbd snap create {pool-name}/{image-name}@{snap-name}
72
73 For example::
74
75 rbd snap create rbd/foo@snapname
76
77
78 List Snapshots
79 --------------
80
81 To list snapshots of an image, specify the pool name and the image name. ::
82
83 rbd snap ls {pool-name}/{image-name}
84
85 For example::
86
87 rbd snap ls rbd/foo
88
89
90 Rollback Snapshot
91 -----------------
92
93 To rollback to a snapshot with ``rbd``, specify the ``snap rollback`` option, the
94 pool name, the image name and the snap name. ::
95
96 rbd snap rollback {pool-name}/{image-name}@{snap-name}
97
98 For example::
99
100 rbd snap rollback rbd/foo@snapname
101
102
103 .. note:: Rolling back an image to a snapshot means overwriting
104 the current version of the image with data from a snapshot. The
105 time it takes to execute a rollback increases with the size of the
106 image. It is **faster to clone** from a snapshot **than to rollback**
107 an image to a snapshot, and is the preferred method of returning
108 to a pre-existing state.
109
110
111 Delete a Snapshot
112 -----------------
113
114 To delete a snapshot with ``rbd``, specify the ``snap rm`` subcommand, the pool
115 name, the image name and the snap name. ::
116
117 rbd snap rm {pool-name}/{image-name}@{snap-name}
118
119 For example::
120
121 rbd snap rm rbd/foo@snapname
122
123
124 .. note:: Ceph OSDs delete data asynchronously, so deleting a snapshot
125 doesn't immediately free up the underlying OSDs' capacity.
126
127 Purge Snapshots
128 ---------------
129
130 To delete all snapshots for an image with ``rbd``, specify the ``snap purge``
131 subcommand and the image name. ::
132
133 rbd snap purge {pool-name}/{image-name}
134
135 For example::
136
137 rbd snap purge rbd/foo
138
139
140 .. index:: Ceph Block Device; snapshot layering
141
142 Layering
143 ========
144
145 Ceph supports the ability to create many copy-on-write (COW) clones of a block
146 device snapshot. Snapshot layering enables Ceph block device clients to create
147 images very quickly. For example, you might create a block device image with a
148 Linux VM written to it; then, snapshot the image, protect the snapshot, and
149 create as many copy-on-write clones as you like. A snapshot is read-only,
150 so cloning a snapshot simplifies semantics--making it possible to create
151 clones rapidly.
152
153
154 .. ditaa::
155
156 +-------------+ +-------------+
157 | {s} c999 | | {s} |
158 | Snapshot | Child refers | COW Clone |
159 | of Image |<------------*| of Snapshot |
160 | | to Parent | |
161 | (read only) | | (writable) |
162 +-------------+ +-------------+
163
164 Parent Child
165
166 .. note:: The terms "parent" and "child" refer to a Ceph block device snapshot (parent),
167 and the corresponding image cloned from the snapshot (child). These terms are
168 important for the command line usage below.
169
170 Each cloned image (child) stores a reference to its parent image, which enables
171 the cloned image to open the parent snapshot and read it.
172
173 A COW clone of a snapshot behaves exactly like any other Ceph block device
174 image. You can read to, write from, clone, and resize cloned images. There are
175 no special restrictions with cloned images. However, the copy-on-write clone of
176 a snapshot depends on the snapshot, so you **MUST** protect the snapshot before
177 you clone it. The following diagram depicts the process.
178
179 .. note:: Ceph only supports cloning of RBD format 2 images (i.e., created with
180 ``rbd create --image-format 2``). The kernel client supports cloned images
181 beginning with the 3.10 release.
182
183 Getting Started with Layering
184 -----------------------------
185
186 Ceph block device layering is a simple process. You must have an image. You must
187 create a snapshot of the image. You must protect the snapshot. Once you have
188 performed these steps, you can begin cloning the snapshot.
189
190 .. ditaa::
191
192 +----------------------------+ +-----------------------------+
193 | | | |
194 | Create Block Device Image |------->| Create a Snapshot |
195 | | | |
196 +----------------------------+ +-----------------------------+
197 |
198 +--------------------------------------+
199 |
200 v
201 +----------------------------+ +-----------------------------+
202 | | | |
203 | Protect the Snapshot |------->| Clone the Snapshot |
204 | | | |
205 +----------------------------+ +-----------------------------+
206
207
208 The cloned image has a reference to the parent snapshot, and includes the pool
209 ID, image ID and snapshot ID. The inclusion of the pool ID means that you may
210 clone snapshots from one pool to images in another pool.
211
212
213 #. **Image Template:** A common use case for block device layering is to create a
214 master image and a snapshot that serves as a template for clones. For example,
215 a user may create an image for a Linux distribution (e.g., Ubuntu 12.04), and
216 create a snapshot for it. Periodically, the user may update the image and create
217 a new snapshot (e.g., ``sudo apt-get update``, ``sudo apt-get upgrade``,
218 ``sudo apt-get dist-upgrade`` followed by ``rbd snap create``). As the image
219 matures, the user can clone any one of the snapshots.
220
221 #. **Extended Template:** A more advanced use case includes extending a template
222 image that provides more information than a base image. For example, a user may
223 clone an image (e.g., a VM template) and install other software (e.g., a database,
224 a content management system, an analytics system, etc.) and then snapshot the
225 extended image, which itself may be updated just like the base image.
226
227 #. **Template Pool:** One way to use block device layering is to create a
228 pool that contains master images that act as templates, and snapshots of those
229 templates. You may then extend read-only privileges to users so that they
230 may clone the snapshots without the ability to write or execute within the pool.
231
232 #. **Image Migration/Recovery:** One way to use block device layering is to migrate
233 or recover data from one pool into another pool.
234
235 Protecting a Snapshot
236 ---------------------
237
238 Clones access the parent snapshots. All clones would break if a user inadvertently
239 deleted the parent snapshot. To prevent data loss, you **MUST** protect the
240 snapshot before you can clone it. ::
241
242 rbd snap protect {pool-name}/{image-name}@{snapshot-name}
243
244 For example::
245
246 rbd snap protect rbd/my-image@my-snapshot
247
248 .. note:: You cannot delete a protected snapshot.
249
250 Cloning a Snapshot
251 ------------------
252
253 To clone a snapshot, specify you need to specify the parent pool, image and
254 snapshot; and, the child pool and image name. You must protect the snapshot
255 before you can clone it. ::
256
257 rbd clone {pool-name}/{parent-image}@{snap-name} {pool-name}/{child-image-name}
258
259 For example::
260
261 rbd clone rbd/my-image@my-snapshot rbd/new-image
262
263 .. note:: You may clone a snapshot from one pool to an image in another pool. For example,
264 you may maintain read-only images and snapshots as templates in one pool, and writeable
265 clones in another pool.
266
267 Unprotecting a Snapshot
268 -----------------------
269
270 Before you can delete a snapshot, you must unprotect it first. Additionally,
271 you may *NOT* delete snapshots that have references from clones. You must
272 flatten each clone of a snapshot, before you can delete the snapshot. ::
273
274 rbd snap unprotect {pool-name}/{image-name}@{snapshot-name}
275
276 For example::
277
278 rbd snap unprotect rbd/my-image@my-snapshot
279
280
281 Listing Children of a Snapshot
282 ------------------------------
283
284 To list the children of a snapshot, execute the following::
285
286 rbd children {pool-name}/{image-name}@{snapshot-name}
287
288 For example::
289
290 rbd children rbd/my-image@my-snapshot
291
292
293 Flattening a Cloned Image
294 -------------------------
295
296 Cloned images retain a reference to the parent snapshot. When you remove the
297 reference from the child clone to the parent snapshot, you effectively "flatten"
298 the image by copying the information from the snapshot to the clone. The time
299 it takes to flatten a clone increases with the size of the snapshot. To delete
300 a snapshot, you must flatten the child images first. ::
301
302 rbd flatten {pool-name}/{image-name}
303
304 For example::
305
306 rbd flatten rbd/new-image
307
308 .. note:: Since a flattened image contains all the information from the snapshot,
309 a flattened image will take up more storage space than a layered clone.
310
311
312 .. _cephx: ../../rados/configuration/auth-config-ref/
313 .. _QEMU: ../qemu-rbd/
314 .. _OpenStack: ../rbd-openstack/
315 .. _CloudStack: ../rbd-cloudstack/
316 .. _libvirt: ../libvirt/