Ceph RGW誤刪index物件恢復

2023-02-13 18:02:14

版本

[root@control1 ~]# ceph -v
ceph version 14.2.22 (ca74598065096e6fcbd8433c8779a2be0c889351) nautilus (stable)

問題

RGW將物件的索引資訊儲存在 <zone>.rgw.buckets.index pool中,在不分片的情況下,一個物件就對應一個bucket,分片的情況下,多個物件對應同一個bucket,在該物件的omap中儲存這bucket的索引資訊,如果將這個物件誤刪除,那麼就無法看到該bucket中都有哪些物件,但是物件的真實資料是儲存在 <zone>.rgw.buckets.data pool中的,只要data中的資料沒有被刪除,那麼仍然可以正常get到該物件,此時只要object rewrite或者重新向該bucket中上傳這些物件就可以自動修復index。

範例

1. 準備測試資料

[root@control1 ~]# s3cmd mb s3://nice
Bucket 's3://nice/' created
[root@control1 ~]#
[root@control1 ~]#
[root@control1 ~]# s3cmd  ls s3://nice
[root@control1 ~]#
[root@control1 ~]# s3cmd put pushgateway-1.4.2.linux-amd64.tar.gz  s3://nice
[root@control1 ~]# s3cmd put node_exporter-1.1.2.linux-amd64.tar.gz s3://nice
[root@control1 ~]#
[root@control1 ~]#
[root@control1 ~]# s3cmd ls s3://nice
2023-02-13 06:12      9246179  s3://nice/node_exporter-1.1.2.linux-amd64.tar.gz
2023-02-13 06:09      9189846  s3://nice/pushgateway-1.4.2.linux-amd64.tar.gz

2. 檢視底層資料結構

2.1 找到bucket對應的id

[root@control1 ~]# radosgw-admin bucket stats --bucket nice
{
    "bucket": "nice",
    "num_shards": 0,
    "tenant": "",
    "zonegroup": "cc0580a9-21d5-4377-b64b-fabf1f55fb4e",
    "placement_rule": "default-placement",
    "explicit_placement": {
        "data_pool": "",
        "data_extra_pool": "",
        "index_pool": ""
    },
    "id": "8c065d13-f5f0-4923-9ea0-7518b7760495.45180186.2",
    "marker": "8c065d13-f5f0-4923-9ea0-7518b7760495.45180186.2",
    "index_type": "Normal",
    "owner": "1034c29d7fec46e897aa531f832b6e5c",
    "ver": "0#3",
    "master_ver": "0#0",
    "mtime": "2023-02-13 06:07:37.785853Z",
    "max_marker": "0#",
    "usage": {
        "rgw.main": {
            "size": 18436025,
            "size_actual": 18440192,
            "size_utilized": 18436025,
            "size_kb": 18004,
            "size_kb_actual": 18008,
            "size_kb_utilized": 18004,
            "num_objects": 2
        }
    },
    "bucket_quota": {
        "enabled": false,
        "check_on_raw": false,
        "max_size": -1,
        "max_size_kb": 0,
        "max_objects": -1
    }
}

2.2 在index pool中檢視該物件的資訊

[root@control1 ~]# rados ls -p cn-1.rgw.buckets.index  | grep 8c065d13-f5f0-4923-9ea0-7518b7760495.45180186.2
.dir.8c065d13-f5f0-4923-9ea0-7518b7760495.45180186.2
 
[root@control1 ~]# rados -p cn-1.rgw.buckets.index listomapkeys .dir.8c065d13-f5f0-4923-9ea0-7518b7760495.45180186.2
node_exporter-1.1.2.linux-amd64.tar.gz
pushgateway-1.4.2.linux-amd64.tar.gz
[root@control1 ~]#
[root@control1 ~]#
[root@control1 ~]# rados -p cn-1.rgw.buckets.index listomapvals .dir.8c065d13-f5f0-4923-9ea0-7518b7760495.45180186.2
node_exporter-1.1.2.linux-amd64.tar.gz
value (293 bytes) :
00000000  08 03 1f 01 00 00 26 00  00 00 6e 6f 64 65 5f 65  |......&...node_e|
00000010  78 70 6f 72 74 65 72 2d  31 2e 31 2e 32 2e 6c 69  |xporter-1.1.2.li|
00000020  6e 75 78 2d 61 6d 64 36  34 2e 74 61 72 2e 67 7a  |nux-amd64.tar.gz|
00000030  03 00 00 00 00 00 00 00  01 07 03 91 00 00 00 01  |................|
00000040  e3 15 8d 00 00 00 00 00  ea d4 e9 63 7b eb 01 07  |...........c{...|
00000050  20 00 00 00 36 31 65 32  62 39 36 33 66 36 36 66  | ...61e2b963f66f|
00000060  31 65 30 30 36 34 39 63  38 65 34 64 31 66 34 37  |1e00649c8e4d1f47|
00000070  32 39 65 35 20 00 00 00  31 30 33 34 63 32 39 64  |29e5 ...1034c29d|
00000080  37 66 65 63 34 36 65 38  39 37 61 61 35 33 31 66  |7fec46e897aa531f|
00000090  38 33 32 62 36 65 35 63  05 00 00 00 61 64 6d 69  |832b6e5c....admi|
000000a0  6e 12 00 00 00 61 70 70  6c 69 63 61 74 69 6f 6e  |n....application|
000000b0  2f 78 2d 67 7a 69 70 e3  15 8d 00 00 00 00 00 00  |/x-gzip.........|
000000c0  00 00 00 08 00 00 00 53  54 41 4e 44 41 52 44 00  |.......STANDARD.|
000000d0  00 00 00 00 00 00 00 00  01 01 02 00 00 00 0c 03  |................|
000000e0  02 32 00 00 00 38 63 30  36 35 64 31 33 2d 66 35  |.2...8c065d13-f5|
000000f0  66 30 2d 34 39 32 33 2d  39 65 61 30 2d 37 35 31  |f0-4923-9ea0-751|
00000100  38 62 37 37 36 30 34 39  35 2e 34 35 31 39 38 33  |8b7760495.451983|
00000110  37 37 2e 33 35 36 37 00  00 00 00 00 00 00 00 00  |77.3567.........|
00000120  00 00 00 00 00                                    |.....|
00000125

pushgateway-1.4.2.linux-amd64.tar.gz
value (291 bytes) :
00000000  08 03 1d 01 00 00 24 00  00 00 70 75 73 68 67 61  |......$...pushga|
00000010  74 65 77 61 79 2d 31 2e  34 2e 32 2e 6c 69 6e 75  |teway-1.4.2.linu|
00000020  78 2d 61 6d 64 36 34 2e  74 61 72 2e 67 7a 0b 00  |x-amd64.tar.gz..|
00000030  00 00 00 00 00 00 01 07  03 91 00 00 00 01 d6 39  |...............9|
00000040  8c 00 00 00 00 00 0a d4  e9 63 7f a9 85 1b 20 00  |.........c.... .|
00000050  00 00 38 35 63 33 62 39  61 30 30 36 36 37 66 34  |..85c3b9a00667f4|
00000060  38 36 32 64 37 62 38 36  31 36 35 66 63 64 30 34  |862d7b86165fcd04|
00000070  39 33 20 00 00 00 31 30  33 34 63 32 39 64 37 66  |93 ...1034c29d7f|
00000080  65 63 34 36 65 38 39 37  61 61 35 33 31 66 38 33  |ec46e897aa531f83|
00000090  32 62 36 65 35 63 05 00  00 00 61 64 6d 69 6e 12  |2b6e5c....admin.|
000000a0  00 00 00 61 70 70 6c 69  63 61 74 69 6f 6e 2f 78  |...application/x|
000000b0  2d 67 7a 69 70 d6 39 8c  00 00 00 00 00 00 00 00  |-gzip.9.........|
000000c0  00 08 00 00 00 53 54 41  4e 44 41 52 44 00 00 00  |.....STANDARD...|
000000d0  00 00 00 00 00 00 01 01  02 00 00 00 0c 0b 01 32  |...............2|
000000e0  00 00 00 38 63 30 36 35  64 31 33 2d 66 35 66 30  |...8c065d13-f5f0|
000000f0  2d 34 39 32 33 2d 39 65  61 30 2d 37 35 31 38 62  |-4923-9ea0-7518b|
00000100  37 37 36 30 34 39 35 2e  34 35 31 39 38 33 37 37  |7760495.45198377|
00000110  2e 33 35 35 33 00 00 00  00 00 00 00 00 00 00 00  |.3553...........|
00000120  00 00 00                                          |...|
00000123

可以看到index物件通過omap的方式儲存了該bucket跟該bucket中物件的索引關係,以及物件的一些後設資料資訊,比如修改時間,檔案型別等,可以通過下面命令來檢視:

[root@control1 ~]# radosgw-admin bucket list --bucket nice
[
    {
        "name": "node_exporter-1.1.2.linux-amd64.tar.gz",
        "instance": "",
        "ver": {
            "pool": 12,
            "epoch": 3
        },
        "locator": "",
        "exists": "true",
        "meta": {
            "category": 1,
            "size": 9246179,
            "mtime": "2023-02-13 06:12:58.117566Z",
            "etag": "61e2b963f66f1e00649c8e4d1f4729e5",
            "storage_class": "STANDARD",
            "owner": "1034c29d7fec46e897aa531f832b6e5c",
            "owner_display_name": "admin",
            "content_type": "application/x-gzip",
            "accounted_size": 9246179,
            "user_data": "",
            "appendable": "false"
        },
        "tag": "8c065d13-f5f0-4923-9ea0-7518b7760495.45198377.3567",
        "flags": 0,
        "pending_map": [],
        "versioned_epoch": 0
    },
    {
        "name": "pushgateway-1.4.2.linux-amd64.tar.gz",
        "instance": "",
        "ver": {
            "pool": 12,
            "epoch": 11
        },
        "locator": "",
        "exists": "true",
        "meta": {
            "category": 1,
            "size": 9189846,
            "mtime": "2023-02-13 06:09:14.461744Z",
            "etag": "85c3b9a00667f4862d7b86165fcd0493",
            "storage_class": "STANDARD",
            "owner": "1034c29d7fec46e897aa531f832b6e5c",
            "owner_display_name": "admin",
            "content_type": "application/x-gzip",
            "accounted_size": 9189846,
            "user_data": "",
            "appendable": "false"
        },
        "tag": "8c065d13-f5f0-4923-9ea0-7518b7760495.45198377.3553",
        "flags": 0,
        "pending_map": [],
        "versioned_epoch": 0
    }
]

2.3 檢視data pool中該bucket的資料物件

[root@control1 ~]# rados -p cn-1.rgw.buckets.data ls | grep 8c065d13-f5f0-4923-9ea0-7518b7760495.45180186.2
8c065d13-f5f0-4923-9ea0-7518b7760495.45180186.2_pushgateway-1.4.2.linux-amd64.tar.gz
8c065d13-f5f0-4923-9ea0-7518b7760495.45180186.2_node_exporter-1.1.2.linux-amd64.tar.gz
8c065d13-f5f0-4923-9ea0-7518b7760495.45180186.2__shadow_.QjFsBiV-vhyjfGzwpTcBBjO7G6rm5Ld_2
8c065d13-f5f0-4923-9ea0-7518b7760495.45180186.2__shadow_.QjFsBiV-vhyjfGzwpTcBBjO7G6rm5Ld_1
8c065d13-f5f0-4923-9ea0-7518b7760495.45180186.2__shadow_.QU-DyeqL4u3CQLe3KkKlMsDVqde1wK3_2
8c065d13-f5f0-4923-9ea0-7518b7760495.45180186.2__shadow_.QU-DyeqL4u3CQLe3KkKlMsDVqde1wK3_1

可以看到從data中物件的命名上,可以找到index和其中物件的關聯關係,即8c065d13-f5f0-4923-9ea0-7518b7760495.45180186.2這個索引中有2個tar.gz物件,其他中間帶 shadow 關鍵字的物件是上傳的檔案太大的情況下,做的資料分片。

3. 誤刪index物件

[root@control1 ~]# rados -p cn-1.rgw.buckets.index rm .dir.8c065d13-f5f0-4923-9ea0-7518b7760495.45180186.2
[root@control1 ~]#
[root@control1 ~]# s3cmd ls s3://nice
ERROR: S3 error: 404 (NoSuchKey)
[root@control1 ~]#
[root@control1 ~]# radosgw-admin bucket list --bucket nice
ERROR: store->list_objects(): (2) No such file or directory
[root@control1 ~]#
[root@control1 ~]# s3cmd get s3://nice/pushgateway-1.4.2.linux-amd64.tar.gz
download: 's3://nice/pushgateway-1.4.2.linux-amd64.tar.g

可以看到要列出該bucket中有哪些物件的操作,都是失敗了的,但是如果知道檔名的話,仍然可以單獨下載某個物件,即可以做get操作。

4. 恢復index物件

方法一:rewrite object

[root@control1 ~]# radosgw-admin object rewrite --bucket nice --object node_exporter-1.1.2.linux-amd64.tar.gz
[root@control1 ~]# s3cmd ls s3://nice
2023-02-13 06:12      9246179  s3://nice/node_exporter-1.1.2.linux-amd64.tar.gz
[root@control1 ~]#
[root@control1 ~]# rados -p cn-1.rgw.buckets.index ls | grep dir.8c065d13-f5f0-4923-9ea0-7518b7760495.45180186.2
.dir.8c065d13-f5f0-4923-9ea0-7518b7760495.45180186.2

方法二:重新上傳

[root@control1 ~]# s3cmd put pushgateway-1.4.2.linux-amd64.tar.gz s3://nice
upload: 'pushgateway-1.4.2.linux-amd64.tar.gz' -> 's3://nice/pushgateway-1.4.2.linux-amd64.tar.gz'  [1 of 1]
 
[root@control1 ~]# rados -p cn-1.rgw.buckets.index ls | grep dir.8c065d13-f5f0-4923-9ea0-7518b7760495.45180186.2
.dir.8c065d13-f5f0-4923-9ea0-7518b7760495.45180186.2
 
[root@control1 ~]# rados -p cn-1.rgw.buckets.index listomapkeys .dir.8c065d13-f5f0-4923-9ea0-7518b7760495.45180186.2
pushgateway-1.4.2.linux-amd64.tar.gz
 
[root@control1 ~]# s3cmd ls s3://nice
2023-02-13 06:42      9189846  s3://nice/pushgateway-1.4.2.linux-amd64.tar.gz

方法一比較簡單,不需要將該檔案下載下來再上傳,只需要指定object的名字,重新rewrite一遍就可以了。