33Script to snapshot the ` ev-reth ` MDBX database while the node keeps running and
44record the block height contained in the snapshot.
55
6+ The script supports two execution modes:
7+
8+ - ** local** : Backup a reth instance running directly on the host machine
9+ - ** docker** : Backup a reth instance running in a Docker container
10+
611## Prerequisites
712
8- - Docker access to the container running ` ev-reth ` (defaults to the service name
9- ` ev-reth ` from ` docker-compose ` ).
10- - The ` mdbx_copy ` binary available inside that container. If it is not provided
11- by the image, compile it once inside the container (see [ libmdbx
13+ ### Common requirements
14+
15+ - The ` mdbx_copy ` binary available in the target environment (see [ libmdbx
1216 documentation] ( https://libmdbx.dqdkfa.ru/ ) ).
1317- ` jq ` installed on the host to parse the JSON output.
1418
19+ ### Docker mode
20+
21+ - Docker access to the container running ` ev-reth ` (defaults to the service name
22+ ` ev-reth ` from ` docker-compose ` ).
23+
24+ ### Local mode
25+
26+ - Direct filesystem access to the reth datadir.
27+ - Sufficient permissions to read the database files.
28+
1529## Usage
1630
31+ ### Local mode
32+
33+ When reth is running directly on your machine:
34+
35+ ``` bash
36+ ./scripts/reth-backup/backup.sh \
37+ --mode local \
38+ --datadir /var/lib/reth \
39+ --mdbx-copy /usr/local/bin/mdbx_copy \
40+ /path/to/backups
41+ ```
42+
43+ ### Docker mode
44+
45+ When reth is running in a Docker container:
46+
1747``` bash
1848./scripts/reth-backup/backup.sh \
49+ --mode docker \
1950 --container ev-reth \
2051 --datadir /home/reth/eth-home \
2152 --mdbx-copy /tmp/libmdbx/build/mdbx_copy \
2253 /path/to/backups
2354```
2455
25- This creates a timestamped folder under ` /path/to/backups ` with:
56+ ### Output structure
57+
58+ Both modes create a timestamped folder under ` /path/to/backups ` with:
2659
2760- ` db/mdbx.dat ` – consistent MDBX snapshot.
2861- ` db/mdbx.lck ` – placeholder lock file (empty).
@@ -33,39 +66,64 @@ This creates a timestamped folder under `/path/to/backups` with:
3366Additional flags:
3467
3568- ` --tag LABEL ` to override the timestamped folder name.
36- - ` --keep-remote ` to leave the temporary snapshot inside the container (useful
37- for debugging).
69+ - ` --keep-remote ` to leave the temporary snapshot in the target environment
70+ (useful for debugging).
3871
3972The script outputs the height at the end so you can coordinate other backups
4073with the same block number.
4174
42- ## End-to-end workflow with ` apps/evm/single `
75+ ## Architecture
76+
77+ The backup script is split into two components:
78+
79+ - ** ` backup-lib.sh ` ** : Abstract execution layer providing a common interface for
80+ different execution modes (local, docker). This library defines functions like
81+ ` exec_remote ` , ` copy_from_remote ` , ` copy_to_remote ` , and ` cleanup_remote `
82+ that are implemented differently for each backend.
83+ - ** ` backup.sh ` ** : Main script that uses the library and orchestrates the backup
84+ workflow. It's mode-agnostic and works with any backend that implements the
85+ required interface.
86+
87+ This separation allows easy extension to support additional execution
88+ environments (SSH, Kubernetes, etc.) without modifying the core backup logic.
89+
90+ ## End-to-end workflow with ` apps/evm/single ` (Docker mode)
4391
4492The ` evm/single ` docker-compose setup expects the backup image to reuse the
4593` ghcr.io/evstack/ev-reth:latest ` tag. To capture both the MDBX and ev-node
4694Badger backups end-to-end:
4795
48961 . Build the helper image so ` ev-reth ` has the MDBX tooling preinstalled.
97+
4998 ``` bash
5099 docker build -t ghcr.io/evstack/ev-reth:latest scripts/reth-backup
51100 ```
101+
521022 . Build the ` ev-node-evm-single ` image so it includes the latest CLI backup
53103 command (optional if you already pushed the binary and re-tagged it).
104+
54105 ``` bash
55106 docker build -t ghcr.io/evstack/ev-node-evm-single:main -f apps/evm/single/Dockerfile .
56107 ```
108+
571093 . Start the stack.
110+
58111 ``` bash
59112 (cd apps/evm/single && docker compose up -d)
60113 ```
114+
611154 . Run the MDBX snapshot script (adjust the destination as needed).
116+
62117 ``` bash
63- ./scripts/reth-backup/backup.sh backups/full-run/reth
118+ ./scripts/reth-backup/backup.sh --mode docker backups/full-run/reth
64119 ```
120+
65121 The script prints the generated tag (for example ` 20251013-104816 ` ) and the
66122 captured height (stored under
67123 ` backups/full-run/reth/<TAG>/height.txt ` ).
124+
681255 . Align the ev-node datastore to that height and take the Badger backup:
126+
69127 ``` bash
70128 HEIGHT=$( cat backups/full-run/reth/< TAG> /height.txt)
71129 BACKUP_ROOT=" $( pwd) /backups/full-run"
@@ -123,12 +181,16 @@ EOF
123181 -c " /tmp/evnode_backup.sh /host-backup/evnode-backup-aligned.badger ${HEIGHT} " )
124182
125183 rm /tmp/evnode_backup.sh
184+
126185 # Bring the managed container back with its usual supervisor.
127186 (cd apps/evm/single && docker compose start ev-node-evm-single)
128187 ```
188+
129189 The CLI will report the streamed metadata, and the backup lands at
130190 ` backups/full-run/ev-node/evnode-backup-aligned.badger ` .
191+
1311926 . When finished, tear the stack down.
193+
132194 ``` bash
133195 (cd apps/evm/single && docker compose down)
134196 ```
0 commit comments