1. 程式人生 > 實用技巧 >rbd的刪除回收站功能

rbd的刪除回收站功能

前言

rbd 提供了一個回收站功能,這個是屬於防呆設計,防止誤操作刪除rbd引起無法恢復的情況,rbd正常情況下的刪除是馬上會在後臺回收空間的,這個也聽說過有人做過誤刪除的操作,那麼這個設計就是從操作邏輯上來儘量避免這個失誤的

相關操作

命令比較簡單就幾條命令,luminous版本就支援了,提供幾個命令

  • trash list (trash ls) 列出回收站的rbd
  • trash move (trash mv)通過回收介面刪除rbd
  • trash remove (trash rm)刪除回收站裡面的rbd
  • trash restore 還原回收站的rbd

其中move操作裡面是支援delay的

[root@lab201 ~]# rbd  help  trash move |grep delay
usage: rbd trash move [--pool <pool>] [--image <image>] [--delay <delay>] 
  --delay arg          time delay in seconds until effectively remove the image

這個delay不是說delay多久後會刪除,而是設定進入回收站以後,在多長時間之後是可以去刪除回收站的rbd的,如果沒到這個delay的時間是不能直接刪除的,需要加上force強制命令的,這個地方也就是可以設定一個時間,比如一天,今天刪除的,今天不能正常清理回收站,明天再清理,也提供了強制命令,但是操作邏輯上面是預設有個寬限期的

相關的測試

建立rbd

rbd create test --size 8G

刪除到回收站並設定延時時間

rbd    trash move test --delay  7200

查看回收站列表

[root@lab201 ~]# rbd trash list
166a16b8b4567 test

刪除回收站的rbd

[root@lab201 ~]# rbd    trash remove 166a16b8b4567
Deferment time has not expired, please use --force if you really want to remove the image
Removing image: 0% complete...failed.
2020-09-09 11:40:15.571122 7f51d7677d40 -1 librbd: error: deferment time has not expired.

強制刪除回收站的rbd

[root@lab201 ~]# rbd    trash remove 166a16b8b4567 --force
Removing image: 100% complete...done.

還原操作

[root@lab201 ~]# rbd    trash restore 166a76b8b4567

總結

回收站的功能能夠比較好的去避免誤操作,這樣即使誤刪除了,也留了一定的時間可以去處理,從而從邏輯上更安全了一些

變更記錄

Why Who When
建立 武漢-運維-磨渣 2020-09-09