> For the complete documentation index, see [llms.txt](https://www.docszh.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.docszh.com/berachain-docs/nodes/node-guides/snapshots.md).

# 从快照同步节点

本节将演示使用节点快照，快速同步节点。

### 快照提供者

节点快照由社区提供和管理。

你可以在这里[Berachain bArtio V2 Snapshots](https://github.com/berachain/beacon-kit/blob/main/testing/networks/80084/snapshots.md)找到最新快照。以下将示例同步[Berachain基金会](https://storage.googleapis.com/bartio-snapshot/index.html)提供的节点快照。

### 什么是节点快照？

快照是一种快速同步节点的方法，无需同步整条链的数据。如果没有快照，节点必须从创世区块开始，下载每个区块的数据，快照可以节省数天甚至数周的同步时间。

快照仍需要一定的时间同步，它们只是特定时间点的链上副本。请务必检查快照的时间戳，确保是最新快照，以便有效使用。

### 快照有哪些类型？

#### 不同的客户端类型

在Berachain中，共识客户端和执行客户端均有快照。运行节点只需要共识客户端的快照，因为执行客户端可以从其对应的共识客户端重构链历史消息。但如果已有执行客户端快照，建议跳过重构步骤，以减少同步时间。

#### 共识客户端快照

* **共识数据库**

Beacon-Kit允许使用不同的数据库运行节点。默认数据库是`pebbledb`，但也支持使用其他数据库 (可以通过初始化客户端实现，[config.toml](https://github.com/berachain/beacon-kit/blob/2cc8a07618f51edb228c4ee753bbcb970f28ed35/testing/networks/80084/config.toml#L51)文件中可以找到完整的数据库列表)。

#### 执行客户端快照

* **选择执行客户端**

每个[执行客户端](/berachain-docs/learn/help/glossary.md#execution-client-zhi-xing-ke-hu-duan)保存数据的方式不同，请务必确保使用的快照资源与节点执行客户端相匹配。如果没有可用的执行客户端快照，可以随时从已配对的共识客户端同步执行客户端快照。

### 快照大小和类型

快照一般包括以下两种类型：

| 快照类型             | 历史数据   | 快照大小  | 优点      |
| ---------------- | ------ | ----- | ------- |
| 存档 (**Archive)** | 全链历史数据 | 数据容量大 | 支持历史查询  |
| 修剪 (**Pruned)**  | 最新区块数据 | 数据容量小 | 快速同步和验证 |

### 导入节点快照

不同快照提供商可能有不同的快照使用说明，以下将示例同步[Berachain基金会](https://storage.googleapis.com/bartio-snapshot/index.html)提供的节点快照。

#### 第 1 步：下载快照

根据所在地区和快照类型，从Berachain基金会快照列表中选择信标客户端快照。以下选项可供选择：

| 所在地区   | 快照类型             | 快照链接                                                                 |
| ------ | ---------------- | -------------------------------------------------------------------- |
| **北美** | Archive / Pruned | [Link](https://storage.googleapis.com/bartio-snapshot/index.html)    |
| **欧洲** | Archive / Pruned | [Link](https://storage.googleapis.com/bartio-snapshot-eu/index.html) |
| **亚洲** | Archive / Pruned | [Link](https://storage.googleapis.com/bartio-snapshot-as/index.html) |

1. **下载Beacon客户端快照**

在快照文件夹中，信标快照在以下文件路径：

* `beacon/pruned/`
* `beacon/full/`

运行以下代码，下载快照：

```bash
# $SNAPSHOT_URL example: https://storage.googleapis.com/bartio-snapshot/beacon/full/snapshot_beacond_full_20240913200045.tar.lz4
wget $SNAPSHOT_URL;
```

其中，`$SNAPSHOT_URL`后所示链接，便是你选择的快照。

{% hint style="info" %}
`curl、aria2c`等下载工具也可以用于下载快照。
{% endhint %}

2. **下载执行客户端快照**

在快照文件夹中，执行客户端快照在以下文件路径：

* `exec/geth/pruned/`
* `exec/geth/archive/`
* 其他类型，适配不同执行客户端

{% hint style="info" %}
执行客户端快照即将推出，它们不需要运行节点。
{% endhint %}

#### 第 2 步：验证快照 (可选操作)

根据checksum验证快照，确保下载的快照有效。Checksum是快照文件的哈希，用于验证快照的完整性。

Checksum文件由Berachain基金会提供，文件类型为`.sha256`，将其添加至快照文件名末尾。例如，如果想获得上述快照文件的sha256sum，则文件名为`https://storage.googleapis.com/bartio-snapshot/beacon/full/snapshot_beacond_full_20240913200045.tar.lz4.sha256`。

以下是下载并验证信标快照checksum的示例：

```bash
# Download the checksum file
# $SNAPSHOT_URL example: https://storage.googleapis.com/bartio-snapshot/beacon/pruned/beacond-pruned-snapshot-202408292106.tar.lz4
wget $SNAPSHOT_URL.sha256;

# Verify the checksum
# The following command will check the hash against the snapshot file as long as the filename matches
# $SNAPSHOT_CHECKSUM_FILE example: beacond-pruned-snapshot-202408292106.tar.lz4.sha256
sha256sum -c $SNAPSHOT_CHECKSUM_FILE;

# [Expected Equivalent Output]:
# beacond-pruned-snapshot-202408292106.tar.lz4: OK
```

其中`$SNAPSHOT_CHECKSUM_FILE`后所示内容，便是你下载的checksum文件名称。

{% hint style="danger" %}
**警告**：快照文件文件名与checksum文件文件名务必相同，否则`sha256sum`将无法验证快照。此外，快照文件及其checksum文件必须位于同一文件目录中。
{% endhint %}

#### 第 3 步：导出快照

{% hint style="danger" %}
**警告**：如果节点正在运行，在导出快照操作前，务必停止运行。否则，有可能导致数据损坏。
{% endhint %}

导出的快照文件和文件夹格式如下：

```bash
# $EXTRACTED_SNAPSHOT_DIR example: /root/beacon-snapshot
tree $EXTRACTED_SNAPSHOT_DIR;

# [Expected Equivalent Output]:
# /root/beacon-snapshot
# ├── data
#     ├── application.db
#     │   ├── 000056.sst
#     │   ├── ...
#     │   ├── CURRENT
#     │   ├── LOCK
#     │   ├── MANIFEST-014039
#     │   ├── MANIFEST-014065
#     │   └── OPTIONS-014066
#     ├── blockstore.db
#     │   ├── 002506.sst
#     │   ├── ...
#     │   ├── CURRENT
#     │   ├── LOCK
#     │   ├── MANIFEST-047787
#     │   ├── MANIFEST-047831
#     │   └── OPTIONS-047832
#     ├── deposits.db
#     │   ├── 001142.log
#     │   ├── ...
#     │   ├── CURRENT
#     │   ├── LOCK
#     │   ├── MANIFEST-001125
#     │   ├── MANIFEST-001131
#     │   └── OPTIONS-001132
#     ├── evidence.db
#     │   ├── 000075.sst
#     │   ├── 000076.sst
#     │   ├── 000077.log
#     │   ├── CURRENT
#     │   ├── LOCK
#     │   ├── MANIFEST-000073
#     │   ├── MANIFEST-000078
#     │   └── OPTIONS-000079
#     ├── priv_validator_state.json
#     ├── state.db
#         ├── 001750.sst
#         ├── ...
#         ├── CURRENT
#         ├── LOCK
#         ├── MANIFEST-008554
#         ├── MANIFEST-008576
#         └── OPTIONS-008577
#
# 13 directories, 4804 files
```

1. **共识客户端快照配置**

首先，运行以下代码，提取Beacon-Kit快照。

```bash
# Ensure that you have `lz4` installed on your system
# $BEACOND_SNAPSHOT_FILE example: beacond-pruned-snapshot-202408292106.tar.lz4
# $BEACOND_HOME example: /root/.beacond/
lz4 -d $BEACOND_SNAPSHOT_FILE | tar -xvf - --strip-components=2 -C $BEACOND_HOME;
```

检查上述代码，`$BEACOND_SNAPSHOT_FILE`后所示内容，应指向已下载的信标快照文件名；`$BEACOND_HOME`后所示内容，应指向信标快照文件配置目录。

2. **执行客户端快照配置 (可选操作)**

操作步骤取决于使用的执行客户端类型，但总体流程相同。

例如，如果你正在使用`geth`客户端，则会出现以下类似代码：

```bash
# $GETH_SNAPSHOT_FILE example: geth-pruned-snapshot-202408292106.tar.lz4
# $GETH_DATA_DIR example: /root/.ethereum/data/geth
lz4 -c -d $GETH_SNAPSHOT_FILE | tar -x -C $GETH_DATA_DIR;
```

检查上述代码，`$GETH_SNAPSHOT_FILE`后所示内容，应指向已下载的geth快照文件名；`$GETH_DATA_DIR`后所示内容，应指向geth快照文件配置目录。

#### 第 4 步：启动节点 <a href="#step-4-start-your-node" id="step-4-start-your-node"></a>

现在，你可以重启节点了！运行相应的代码、systemd服务或其他自定义配置，重启信标节点和执行客户端。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.docszh.com/berachain-docs/nodes/node-guides/snapshots.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
