Lab 2.5 - Ceph Operational (RBD Snapshots & Clone)


Preparation

Before you begin, run the nusactl login command to login your account. Credentials for login is same with your registered credentials in this platform (ADINUSA).

student@ceph1:~$ nusactl login

After login, run the nusactl start cpadm-002-5 command. This command runs the start script and pre-configures your lab environment.

student@ceph1:~$ nusactl start cpadm-002-5



Execute on pod-<username>-ceph1 node

1. Create snapshot.

# Manipulate file space
sudo fallocate -l 1G /mnt/block0/test1.img
sudo fallocate -l 1G /mnt/block0/test2.img
sudo fallocate -l 1G /mnt/block0/test3.img
sudo ls -lh /mnt/block0
# To create a snapshot with rbd, specify the snap create option, the pool name and the image name.
sudo rbd snap create pool-test2/block0@snap1-block0
sudo rbd snap create pool-test2/block0@snap2-block0

2. show snapshot.

# To list snapshots of an image, specify the pool name and the image name.
sudo rbd snap ls pool-test2/block0

3. Rollback snapshot.

# Delete file on /mnt/block0
sudo rm -rf /mnt/block0/test3.img
# Check file on /mnt/block0, make sure file test3.img not exist
sudo ls -lh /mnt/block0/
# Unmount RBD Image
sudo umount /dev/rbd0
df -h
sudo rbd unmap pool-test2/block0
# To rollback to a snapshot with rbd, specify the snap rollback option, the pool name, the image name and the snap name.
sudo rbd snap rollback pool-test2/block0@snap1-block0
sudo rbd map pool-test2/block0
sudo mount /dev/rbd0 /mnt/block0
sudo ls -lh /mnt/block0/

4. Protect snapshot.

sudo rbd info pool-test2/block0@snap1-block0
sudo rbd info pool-test2/block0@snap2-block0
# Clones access the parent snapshots. All clones would break if a user inadvertently deleted the parent snapshot. 
# To prevent data loss, you MUST protect the snapshot before you can clone it.
sudo rbd snap protect pool-test2/block0@snap1-block0
sudo rbd snap protect pool-test2/block0@snap2-block0
sudo rbd info pool-test2/block0@snap1-block0

5. Create clone.

# To clone a snapshot, specify you need to specify the parent pool, image and snapshot; and, the child pool and image name. 
# You must protect the snapshot before you can clone it.
sudo rbd clone pool-test2/block0@snap1-block0 pool-test2/clone1-block0
sudo rbd clone pool-test2/block0@snap1-block0 pool-test2/clone2-block0

6. Show children snapshot (clone).

# To list the children of a snapshot, execute the following:
sudo rbd children pool-test2/block0@snap1-block0
sudo rbd info pool-test2/clone2-block0

7. Flatten Cloned Image.

# Cloned images retain a reference to the parent snapshot. 
# When you remove the reference from the child clone to the parent snapshot, 
# you effectively “flatten” the image by copying the information from the snapshot to the clone. 
# The time it takes to flatten a clone increases with the size of the snapshot. To delete a snapshot, you must flatten the child images first.
sudo rbd flatten pool-test2/clone2-block0
sudo rbd info pool-test2/clone2-block0
sudo rbd list pool-test2

8. Set unprotect snapshot.

sudo rbd info pool-test2/block0@snap2-block0
sudo rbd snap rm pool-test2/block0@snap2-block0 # cannot be deteled because protected
# Before you can delete a snapshot, you must unprotect it first. Additionally, you may NOT delete snapshots that have references from clones. 
# You must flatten each clone of a snapshot, before you can delete the snapshot.
sudo rbd snap unprotect pool-test2/block0@snap2-block0
sudo rbd info pool-test2/block0@snap2-block0

9. Delete snapshot.

sudo rbd snap ls pool-test2/block0
# To delete a snapshot with rbd, specify the snap rm subcommand, the pool name, the image name and the snap name.
sudo rbd snap rm pool-test2/block0@snap2-block0

10. Verify it

sudo rbd snap ls pool-test2/block0