How to perform various operation using rbd in ceph ?

In this article I am going to show you the various snapshot options which can be performed on rados block device image. Not all the options are covered in this article.

Step 1 : I have created one image of size 1GB inside the pool foo.

[root@mon3 ~]# rbd create –pool pool2 –size 1024 foo

[root@mon3 ~]# rbd snap ls pool2/foo
2 snap1 1024 MB

I was able to create the snapshot successfully using below command.

[root@mon3 ~]# rbd snap create pool2/foo@snap1

But while creating the clone from snapshot was getting error.

[root@mon3 ~]# rbd -p pool2 clone pool2/foo@snap1 foo_cl
rbd: clone error: (22) Invalid argument
2015-04-23 11:22:43.641888 7fd11a4857c0 -1 librbd: parent image must be in new form

Step 2 : When we are creating images inside the pool they can be format 1 or of format 2 type. For the snapshot to work we need image of foramt type 2.

I created new image by specifying the format 2 option.

[root@mon3 ~]# rbd create –image-format 2 -p pool2 foonew –size 500
[root@mon3 ~]# rbd -p pool2 ls

I have create snapshot with name snap2.

[root@mon3 ~]# rbd snap create pool2/foonew@snap2

We can check the snapshot for the image using below command.

[root@mon3 ~]# rbd snap ls pool2/foonew
3 snap2 500 MB

Step 3 : We have created snapshot now lets try to create clone from that snapshot. While doing that again I am getting the error that snapshot is not protected. But we need not to worry about this error like in step 1.

[root@mon3 ~]# rbd -p pool2 clone pool2/foonew@snap2 foo_cl
rbd: clone error: (22) Invalid argument
2015-04-23 11:25:51.851418 7f0d414577c0 -1 librbd: parent snapshot must be protected
I protect the snapshot from any kind of accidental deletion.

[root@mon3 ~]# rbd snap protect pool2/foonew@snap2

After protecting the snapshot, I am able to perform the clone from snapshot successfully.

[root@mon3 ~]# rbd -p pool2 clone pool2/foonew@snap2 foo_cl

[root@mon3 ~]# rbd -p pool2 ls

Step 4 : I was trying to locate the clone created in previous step. I found that it got created in default rbd pool because I have not specified the pool name while creating the clone.

[root@mon3 ~]# rbd -p rbd ls

Created clone by specifying the pool name pool3.

[root@mon3 ~]# rbd -p pool2 clone pool2/foonew@snap2 pool3/foo_cl
[root@mon3 ~]# rbd -p pool3 ls

Step 5 : After the creation of clones from the snapshot. We can check how many children snapshot is having. We have create two clones from snapshot, we are getting same count with pool name and image name.

[root@mon3 ~]# rbd children pool2/foonew@snap2

Now if we want to delete the snapshot, it will not allow us. Remember, we have protect the snapshot.

[root@mon3 ~]# rbd snap rm pool2/foonew@snap2
rbd: snapshot ‘snap2’ is protected from removal.
2015-04-23 11:29:48.619637 7fa036b517c0 -1 librbd: removing snapshot from header failed: (16) Device or resource busy

Step 6 : To remove the dependency between the snapshot and image, we need to flatten the image using below command.

[root@mon3 ~]# rbd -p rbd flatten –image foo_cl
Image flatten: 100% complete…done.

Once again check the children for the snapshot. You will see only one in output this time because we have performed the flatten  operation for other.

[root@mon3 ~]# rbd children pool2/foonew@snap2
[root@mon3 ~]#

In similar way we can perform the flatten operation for other clone as well then we can unprotect the snapshot for removal.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s