ceph官网的ceph块设备(二)——快照相关

时间:2023-12-24 13:11:07
一)快照基础命令
1. 创建快照
# rbd snap create yhcpool/yhctest@yhctestsnap
2.查询rbd镜像
# rbd snap ls yhcpool/yhctest
SNAPID NAME SIZE
4 yhctestsnap 512 MB
命令:
rbd snap rollback {pool-name}/{image-name}@{snap-name}
验证:
# rbd snap create yhcpool/yhctest@yhctestsnap2
# rbd snap ls yhcpool/yhctest
SNAPID NAME SIZE
4 yhctestsnap 512 MB
5 yhctestsnap2 512 MB
# rbd snap rollback yhcpool/yhctest@yhctestsnap
Rolling back to snapshot: 99% complete...2017-01-04 16:30:24.041936 7fdd93fff700 -1 librbd::object_map::LockRequest: failed to lock object map: (17) File exists
Rolling back to snapshot: 100% complete...done.
4.删除快照
命令:
rbd snap rm {pool-name}/{image-name}@{snap-name}
验证:
# rbd snap ls yhcpool/yhctest
SNAPID NAME SIZE
4 yhctestsnap 512 MB
5 yhctestsnap2 512 MB
# rbd snap rm yhcpool/yhctest@yhctestsnap
# rbd snap ls yhcpool/yhctest
SNAPID NAME SIZE
5 yhctestsnap2 512 MB
5.清除快照
删除某个rbd镜像的所有快照。
命令:
rbd snap purge {pool-name}/{image-name}
验证:
# rbd snap ls yhcpool/yhctest
SNAPID NAME SIZE
5 yhctestsnap2 512 MB
7 yhctestsnap3 512 MB
# rbd snap purge yhcpool/yhctest
Removing all snapshots: 100% complete...done.
# rbd snap ls yhcpool/yhctest
二)分层
1.保护快照
命令:
rbd snap protect {pool-name}/{image-name}@{snapshot-name}
验证:
# rbd snap protect yhcpool/yhctest@yhctestsnap1
注意:快照被保护后,不能被删除
# rbd snap rm yhcpool/yhctest@yhctestsnap1
rbd: snapshot 'yhctestsnap1' is protected from removal.
2017-01-04 17:02:20.966119 7f7ef6402700 -1 librbd::Operations: snapshot is protected
2.克隆快照
命令:
rbd clone {pool-name}/{parent-image}@{snap-name} {pool-name}/{child-image-name}
验证:
#rbd clone yhcpool/yhctest@yhctestsnap1 yhcpool/yhctestclone
3.取消快照保护
命令:
rbd snap unprotect {pool-name}/{image-name}@{snapshot-name}
验证:
# rbd snap unprotect yhcpool/yhctest@yhctestsnap1
4.查看快照的子孙
命令:
rbd children {pool-name}/{image-name}@{snapshot-name}
验证:
# rbd children yhcpool/yhctest@yhctestsnap1
yhcpool/yhctestclone
5.拍平克隆镜像
命令:
rbd flatten {pool-name}/{image-name}
验证:
# rbd info yhcpool/yhctestclone
rbd image 'yhctestclone':
size 512 MB in 128 objects
order 22 (4096 kB objects)
block_name_prefix: rbd_data.3f0cd2eb141f2
format: 2
features: layering, exclusive-lock, object-map, fast-diff, deep-flatten
flags:
parent: yhcpool/yhctest@yhctestsnap1
overlap: 512 MB
# rbd flatten yhcpool/yhctestclone
Image flatten: 100% complete...done.
# rbd info yhcpool/yhctestclone
rbd image 'yhctestclone':
size 512 MB in 128 objects
order 22 (4096 kB objects)
block_name_prefix: rbd_data.3f0cd2eb141f2
format: 2
features: layering, exclusive-lock, object-map, fast-diff, deep-flatten
flags: