---
# System prepended metadata

title: Rancher 清除異常的 snapshot
tags: [rancher]

---

# Rancher 清除異常的 snapshot

* 在 Rancher ui 上看到異常的 snapshot，或是想要清除 snapshot 可以參考以下步驟

![image](https://hackmd.io/_uploads/BkMTchHMC.png)


## 清除異常的 snapshot
1. 在 rke2 downstream cluster 執行以下命令
```
$ kubectl get etcdsnapshotfile
NAME                                         SNAPSHOTNAME                    NODE   LOCATION                                                                         SIZE       CREATIONTIME
local-etcd-snapshot-rke2-1714910403-6638ce   etcd-snapshot-rke2-1714910403   rke2   file:///var/lib/rancher/rke2/server/db/snapshots/etcd-snapshot-rke2-1714910403   11157536   2024-05-05T12:00:03Z
local-etcd-snapshot-rke2-1714924804-52f2e3   etcd-snapshot-rke2-1714924804   rke2   file:///var/lib/rancher/rke2/server/db/snapshots/etcd-snapshot-rke2-1714924804   11157536   2024-05-05T16:00:04Z
local-etcd-snapshot-rke2-1714942802-2ec53f   etcd-snapshot-rke2-1714942802   rke2   file:///var/lib/rancher/rke2/server/db/snapshots/etcd-snapshot-rke2-1714942802   11526176   2024-05-05T21:00:02Z
local-etcd-snapshot-rke2-1714960801-d7d826   etcd-snapshot-rke2-1714960801   rke2   file:///var/lib/rancher/rke2/server/db/snapshots/etcd-snapshot-rke2-1714960801   10973216   2024-05-06T02:00:01Z
local-on-demand-rke2-1713234954-4f8f15       on-demand-rke2-1713234954       rke2   file:///var/lib/rancher/rke2/server/db/snapshots/on-demand-rke2-1713234954       14549024   2024-04-16T02:35:54Z
local-on-demand-rke2-1714960421-3e457a       on-demand-rke2-1714960421       rke2   file:///var/lib/rancher/rke2/server/db/snapshots/on-demand-rke2-1714960421       7413792    2024-05-06T01:53:41Z
s3-etcd-snapshot-rke2-1714892404-7302a4      etcd-snapshot-rke2-1714892404   rke2   s3://rke2/rke2-resotre/etcd-snapshot-rke2-1714892404                             0          2024-05-05T07:00:04Z
s3-etcd-snapshot-rke2-1714910403-801b7f      etcd-snapshot-rke2-1714910403   rke2   s3://rke2/rke2-resotre/etcd-snapshot-rke2-1714910403                             0          2024-05-05T12:00:03Z
s3-etcd-snapshot-rke2-1714924804-61030f      etcd-snapshot-rke2-1714924804   rke2   s3://rke2/rke2-resotre/etcd-snapshot-rke2-1714924804                             0          2024-05-05T16:00:04Z
s3-etcd-snapshot-rke2-1714942802-e3ad6c      etcd-snapshot-rke2-1714942802   rke2   s3://rke2/rke2-resotre/etcd-snapshot-rke2-1714942802                             0          2024-05-05T21:00:02Z
s3-etcd-snapshot-rke2-1714960801-ce611f      etcd-snapshot-rke2-1714960801   rke2   s3://rke2/rke2-resotre/etcd-snapshot-rke2-1714960801                             10973216   2024-05-06T02:00:01Z
s3-on-demand-rke2-1714960421-449dcf          on-demand-rke2-1714960421       rke2   s3://rke2/rke2-resotre/on-demand-rke2-1714960421                                 7413792    2024-05-06T01:53:41Z
```
2. 清除 snapshot
```
$ kubectl delete etcdsnapshotfile s3-etcd-snapshot-rke2-1714892404-7302a4 s3-etcd-snapshot-rke2-1714910403-801b7f s3-etcd-snapshot-rke2-1714924804-61030f s3-etcd-snapshot-rke2-1714942802-e3ad6c
```

3. 等待後，到 rancher ui 檢查 snapshot 是否已被刪除

![image](https://hackmd.io/_uploads/rJGgh2BfC.png)


## 正常清除 snapshot

* 目標刪除 `etcd-snapshot-rke2-1731031204` snapshot

![image](https://hackmd.io/_uploads/S1c3fNiZ1l.png)

1. 在 downstream cluster 執行刪除本機 etcd 檔案
```
# 檢查本機 snapshots
$ ls -l /var/lib/rancher/rke2/server/db/snapshots/
total 589988
-rw------- 1 root root 47173664 Nov  7 15:00 etcd-snapshot-rke2-1730962803
-rw------- 1 root root 47173664 Nov  7 20:00 etcd-snapshot-rke2-1730980802
-rw------- 1 root root 47173664 Nov  8 00:00 etcd-snapshot-rke2-1730995203
-rw------- 1 root root 47173664 Nov  8 05:00 etcd-snapshot-rke2-1731013203
-rw------- 1 root root 47173664 Nov  8 10:00 etcd-snapshot-rke2-1731031204   # 刪除這個
-rw------- 1 root root 13475872 Aug 19 11:27 on-demand-rke2-1724038056
-rw------- 1 root root 13475872 Aug 19 11:28 on-demand-rke2-1724038086
-rw------- 1 root root 13475872 Aug 19 11:28 on-demand-rke2-1724038115
-rw------- 1 root root 20676640 Aug 19 17:13 on-demand-rke2-1724058807
-rw------- 1 root root 20676640 Aug 19 17:13 on-demand-rke2-1724058836
-rw------- 1 root root 20676640 Aug 19 17:14 on-demand-rke2-1724058870
-rw------- 1 root root  7811104 Aug 20 08:57 on-demand-rke2-1724115431
-rw------- 1 root root  7962656 Aug 20 08:57 on-demand-rke2-1724115460
-rw------- 1 root root  8138784 Aug 20 08:58 on-demand-rke2-1724115494
-rw------- 1 root root 15826976 Aug 27 13:40 on-demand-rke2-1724737241
-rw------- 1 root root 15826976 Aug 27 13:40 on-demand-rke2-1724737244
-rw------- 1 root root 15826976 Aug 27 13:41 on-demand-rke2-1724737264
-rw------- 1 root root 26656800 Aug 30 11:43 on-demand-rke2-1724989385
-rw------- 1 root root 29270048 Sep 24 11:30 on-demand-rke2-1727148605
-rw------- 1 root root 29712416 Oct  7 09:04 on-demand-rke2-1728263094
-rw------- 1 root root 34197536 Oct 23 10:33 on-demand-rke2-1729650784
-rw------- 1 root root 39714848 Oct 23 15:26 on-demand-rke2-1729668399
-rw------- 1 root root 34783264 Oct 23 15:49 on-demand-rke2-1729669789

$ rm /var/lib/rancher/rke2/server/db/snapshots/etcd-snapshot-rke2-1731031204
```

2. 在 downstream cluster 執行刪除 CRD
```
$ kubectl get etcdsnapshotfile |grep 1731031204
local-etcd-snapshot-rke2-1731031204-28cd02      etcd-snapshot-rke2-1731031204      rke2      file:///var/lib/rancher/rke2/server/db/snapshots/etcd-snapshot-rke2-1731031204      47173664   2024-11-08T02:00:04Z

$ kubectl delete etcdsnapshotfile local-etcd-snapshot-rke2-1731031204-28cd02
```

3. 在 local 集群執行刪除 CRD
```
$ kubectl -n fleet-default get etcdsnapshots.rke.cattle.io |grep rke2-1731031204
rke2-etcd-snapshot-rke2-1731031204-local          4h46m

$ kubectl -n fleet-default delete etcdsnapshots.rke.cattle.io rke2-etcd-snapshot-rke2-1731031204-local
```
4. 檢查 rancher ui 已刪除 snapshot

![image](https://hackmd.io/_uploads/SJ0UVEjWJl.png)
