Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit 735b1b3

Browse files
feat: evm reth state backup (#582)
* feat: evm reth state backup * Apply suggestions from code review Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * jq + deps --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 5418de0 commit 735b1b3

File tree

2 files changed

+243
-0
lines changed

2 files changed

+243
-0
lines changed

.vitepress/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ function sidebarHome() {
327327
text: "EVM Based Sequencer",
328328
link: "/guides/evm-based",
329329
},
330+
{
331+
text: "EVM reth state backup",
332+
link: "/guides/evm-reth-backup",
333+
},
330334
{
331335
text: "Metrics",
332336
link: "/guides/metrics",

guides/evm-reth-backup.md

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
# Rollkit EVM reth State Backup Guide
2+
3+
## Introduction
4+
5+
This guide covers how to backup the reth state of a Rollkit EVM based blockchain. This implementation provides a production-ready approach to data protection.
6+
7+
## Prerequisites
8+
9+
Before starting, ensure you have:
10+
11+
- A running Rollkit full node - Follow the [Rollkit Full Node Setup Guide](https://rollkit.dev/guides/full-node) to set up your node
12+
- Zstandard (zstd) compression tool installed
13+
- jq JSON processor installed
14+
- Administrative access to the Docker host
15+
- Sufficient disk space for backups (at least 2x the current volume size)
16+
- Access to remote backup storage (optional but recommended)
17+
- Basic understanding of Docker volumes
18+
19+
## Installing Dependencies
20+
21+
For Ubuntu/Debian-based Linux distributions, install the required dependencies:
22+
```bash
23+
# Update package list
24+
sudo apt update
25+
26+
# Install required tools
27+
sudo apt install -y zstd jq
28+
29+
# Verify installations
30+
zstd --version
31+
jq --version
32+
```
33+
34+
## Key Component to Backup
35+
36+
Reth datadir : contains the entire EVM state and node data.
37+
38+
## Performing manual backup
39+
40+
### 1. Verify Node Synchronization
41+
42+
```bash
43+
# Check Rollkit node status
44+
curl -sX POST \
45+
-H "Content-Type: application/json" \
46+
-H "Connect-Protocol-Version: 1" \
47+
-d "{}" \
48+
http://<FULLNODE_IP>:<FULLNODE_RPC_PORT>/rollkit.v1.HealthService/Livez
49+
50+
# Verify reth sync status
51+
curl -sX POST \
52+
-H "Content-Type: application/json" \
53+
-d '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}' \
54+
http://<FULLNODE_RETH_IP>:<FULLNODE_RETH_PORT>
55+
56+
# Expected response for a fully synced node:
57+
# {"jsonrpc":"2.0","id":1,"result":false}
58+
```
59+
60+
### 2. Stop Services Gracefully
61+
62+
You will need to stop both rollkit and reth-rollkit on the fullnode stack, according to your setup.
63+
64+
Example for docker-compose based setup:
65+
```bash
66+
# Stop services in correct order
67+
docker compose stop fullnode
68+
docker compose stop reth-rollkit
69+
70+
# Verify all containers are stopped
71+
docker compose ps
72+
```
73+
74+
### 3. Create Backup
75+
76+
```bash
77+
# Create backup directory
78+
# Create backup directory
79+
# IMPORTANT: Set your backup base directory and reth-rollkit data directory paths
80+
BACKUP_BASE_DIR="/path/to/backups"
81+
RETH_ROLLKIT_DATADIR="/path/to/reth-rollkit/datadir"
82+
mkdir -p "${BACKUP_BASE_DIR}"
83+
84+
# Set backup timestamp
85+
BACKUP_DATE=$(date +%Y%m%d_%H%M%S)
86+
87+
# Backup reth-rollkit datadir using zstandard compression
88+
tar cf - -C "${RETH_ROLLKIT_DATADIR}" . | zstd -3 > "${BACKUP_BASE_DIR}/reth_state_${BACKUP_DATE}.tar.zst"
89+
90+
# Generate checksum
91+
sha256sum "${BACKUP_BASE_DIR}/reth_state_${BACKUP_DATE}.tar.zst" > "${BACKUP_BASE_DIR}/reth_state_${BACKUP_DATE}.tar.zst.sha256"
92+
```
93+
94+
### 4. Restart services
95+
96+
You will need to restart both rollkit and reth-rollkit on the fullnode stack, according to your setup.
97+
98+
Example for docker-compose based setup:
99+
```bash
100+
# Start services
101+
docker compose up -d
102+
103+
# Monitor startup
104+
docker compose logs -f
105+
```
106+
107+
## Automated backup
108+
109+
### 1. Create the Backup Script
110+
111+
```bash
112+
sudo nano /usr/local/bin/rollkit-backup.sh
113+
```
114+
Add the following content
115+
116+
```bash
117+
#!/bin/bash
118+
# Reth-Rollkit Backup Script with Zstandard Compression
119+
120+
set -euo pipefail
121+
122+
# Configuration
123+
RETH_ROLLKIT_DATADIR="" # IMPORTANT: Set this to your reth-rollkit data directory path
124+
BACKUP_BASE_DIR="${BACKUP_BASE_DIR:-/backup/rollkit}"
125+
REMOTE_BACKUP="${REMOTE_BACKUP:-backup-server:/backups/rollkit}"
126+
RETENTION_DAYS="${RETENTION_DAYS:-7}"
127+
COMPOSE_FILE="${COMPOSE_FILE:-docker-compose.yml}"
128+
ZSTD_LEVEL="${ZSTD_LEVEL:-3}"
129+
ZSTD_THREADS="${ZSTD_THREADS:-0}" # 0 = auto-detect
130+
FULLNODE_IP="${FULLNODE_IP:-localhost}"
131+
FULLNODE_RPC_PORT="${FULLNODE_RPC_PORT:-7331}"
132+
FULLNODE_RETH_IP="${FULLNODE_RETH_IP:-localhost}"
133+
FULLNODE_RETH_PORT="${FULLNODE_RETH_PORT:-8545}"
134+
135+
# Functions
136+
log() {
137+
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
138+
}
139+
140+
check_sync_status() {
141+
# Check Rollkit node health
142+
curl -fsX POST \
143+
-H "Content-Type: application/json" \
144+
-H "Connect-Protocol-Version: 1" \
145+
-d "{}" \
146+
"http://${FULLNODE_IP}:${FULLNODE_RPC_PORT}/rollkit.v1.HealthService/Livez" > /dev/null
147+
148+
# Check reth sync status
149+
local sync_status=$(curl -sX POST \
150+
-H "Content-Type: application/json" \
151+
-d '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}' \
152+
http://${FULLNODE_RETH_IP}:${FULLNODE_RETH_PORT} | jq -r '.result')
153+
154+
if [ "$sync_status" != "false" ]; then
155+
log "WARNING: Node is still syncing. Backup may be incomplete."
156+
fi
157+
}
158+
159+
# Main backup process
160+
main() {
161+
log "Starting Rollkit backup process"
162+
163+
# Setup
164+
BACKUP_DATE=$(date +%Y%m%d_%H%M%S)
165+
BACKUP_DIR="${BACKUP_BASE_DIR}"
166+
167+
# Create backup directory
168+
mkdir -p "${BACKUP_DIR}"
169+
170+
# Check sync status
171+
check_sync_status
172+
173+
# Stop services
174+
log "Stopping Rollkit services"
175+
docker compose -f ${COMPOSE_FILE} stop fullnode
176+
docker compose -f ${COMPOSE_FILE} stop reth-rollkit
177+
178+
# Backup reth state using zstandard compression
179+
log "Backing up reth state with zstandard compression"
180+
tar cf - -C ${RETH_ROLLKIT_DATADIR} . | zstd -${ZSTD_LEVEL} -T${ZSTD_THREADS} > "${BACKUP_DIR}/reth_state_${BACKUP_DATE}.tar.zst"
181+
182+
# Generate checksum
183+
sha256sum "${BACKUP_DIR}/reth_state_${BACKUP_DATE}.tar.zst" > "${BACKUP_DIR}/reth_state_${BACKUP_DATE}.tar.zst.sha256"
184+
185+
# Transfer to remote storage
186+
if [ -n "${REMOTE_BACKUP:-}" ]; then
187+
log "Transferring backup to remote storage"
188+
rsync -avz "${BACKUP_DIR}/reth_state_${BACKUP_DATE}.tar.zst*" "${REMOTE_BACKUP}/" || log "WARNING: Remote transfer failed"
189+
fi
190+
191+
# Restart services
192+
log "Restarting services"
193+
docker compose -f ${COMPOSE_FILE} up -d
194+
195+
# Cleanup old backups
196+
log "Cleaning up old backups"
197+
find "${BACKUP_BASE_DIR}" -name "reth_state_*.tar.zst" -mtime +${RETENTION_DAYS} -delete
198+
find "${BACKUP_BASE_DIR}" -name "reth_state_*.tar.zst.sha256" -mtime +${RETENTION_DAYS} -delete
199+
200+
log "Backup completed successfully"
201+
}
202+
203+
# Run backup
204+
main "$@"
205+
```
206+
207+
### 2. Make Script Executable'
208+
209+
```bash
210+
sudo chmod +x /usr/local/bin/rollkit-backup.sh
211+
```
212+
213+
### 3. Schedule Automated Backups
214+
215+
```bash
216+
# Edit crontab
217+
sudo crontab -e
218+
219+
# Add daily backup at 2 AM
220+
0 2 * * * /usr/local/bin/rollkit-backup.sh >> /var/log/rollkit-backup.log 2>&1
221+
```
222+
223+
## Best practices
224+
225+
### Backup Strategy
226+
227+
1. Schedule regular backups - Daily backups during low-activity periods
228+
2. Implement retention policies - Keep x days of local backups, y days remote
229+
3. Test restoration procedures - Monthly restoration drills in test environment
230+
4. Monitor backup jobs - Set up alerts for failed backups
231+
5. Use appropriate compression levels - Balance between compression ratio and speed
232+
233+
### Zstandard Compression Levels
234+
235+
| Level | Speed | Compression Ratio | Use Case |
236+
|-------|---------|-------------------|---------------------|
237+
| 3 | Default | Balanced | Standard backups |
238+
| 9 | Slower | Better | Long-term archives |
239+
| 19 | Slowest | Best | Maximum compression |

0 commit comments

Comments
 (0)