2022-07-27 07:38:03 -05:00
|
|
|
---
|
|
|
|
title: Backup & Restore
|
|
|
|
---
|
|
|
|
|
2022-07-28 11:00:12 -05:00
|
|
|
**Keep secure backups of your keystore and password!**
|
2022-07-27 07:38:03 -05:00
|
|
|
|
|
|
|
## Data Directory
|
|
|
|
|
2022-07-28 11:00:12 -05:00
|
|
|
All data relating to a specific Geth instance gets written inside a data directory.
|
|
|
|
The default data directory locations are platform specific:
|
2022-07-27 07:38:03 -05:00
|
|
|
|
|
|
|
* Mac: `~/Library/Ethereum`
|
|
|
|
* Linux: `~/.ethereum`
|
|
|
|
* Windows: `%LOCALAPPDATA%\Ethereum`
|
|
|
|
|
|
|
|
Accounts are stored in the `keystore` subdirectory. The contents of this directories
|
2022-07-28 11:00:12 -05:00
|
|
|
should be transportable between nodes, platforms, and client implementations.
|
2022-07-27 07:38:03 -05:00
|
|
|
|
|
|
|
To configure the location of the data directory, the `--datadir` parameter can be
|
|
|
|
specified. See [CLI Options](../interface/command-line-options) for more details.
|
2022-07-28 11:00:12 -05:00
|
|
|
There may exist multiple data directories for multiple networks (e.g. a separate directory
|
|
|
|
for Ethereum Mainnet and the Goerli testnet). Each would have subdirectories for their
|
|
|
|
blockchain data and keystore.
|
2022-07-27 07:38:03 -05:00
|
|
|
|
2022-07-28 11:00:12 -05:00
|
|
|
It is important to backup the files in the keystore securely. These files are encrypted
|
|
|
|
using an account password. This needs to be securely backed up too. There is no way to
|
|
|
|
decrypt the keys without the password!
|
2022-07-27 07:38:03 -05:00
|
|
|
|
|
|
|
## Cleanup
|
|
|
|
|
|
|
|
Geth's blockchain and state databases can be removed with:
|
|
|
|
|
2022-07-28 11:00:12 -05:00
|
|
|
```sh
|
2022-07-27 07:38:03 -05:00
|
|
|
geth removedb
|
|
|
|
```
|
|
|
|
|
|
|
|
This is useful for deleting an old chain and sync'ing to a new one. It only affects data
|
|
|
|
directories that can be re-created on synchronisation and does not touch the keystore.
|
|
|
|
|
|
|
|
## Blockchain Import/Export
|
|
|
|
|
|
|
|
Export the blockchain in binary format with:
|
|
|
|
|
2022-07-28 11:00:12 -05:00
|
|
|
```sh
|
2022-07-27 07:38:03 -05:00
|
|
|
geth export <filename>
|
|
|
|
```
|
|
|
|
|
|
|
|
Or if you want to back up portions of the chain over time, a first and last block can be
|
|
|
|
specified. For example, to back up the first epoch:
|
|
|
|
|
2022-07-28 11:00:12 -05:00
|
|
|
```sh
|
2022-07-27 07:38:03 -05:00
|
|
|
geth export <filename> 0 29999
|
|
|
|
```
|
|
|
|
|
|
|
|
Note that when backing up a partial chain, the file will be appended rather than
|
|
|
|
truncated.
|
|
|
|
|
|
|
|
Import binary-format blockchain exports with:
|
|
|
|
|
2022-07-28 11:00:12 -05:00
|
|
|
```sh
|
2022-07-27 07:38:03 -05:00
|
|
|
geth import <filename>
|
|
|
|
```
|
|
|
|
|
|
|
|
And finally: **REMEMBER YOUR PASSWORD** and **BACKUP YOUR KEYSTORE**
|