# Backup & restore

**Keep secure backups of your keystore and password!**

## Data Directory <a href="#data-directory" id="data-directory"></a>

All data relating to a specific Etn-sc instance gets written inside a data directory. The default data directory locations are platform specific:

* Mac: \~/Library/Electroneum-sc
* Linux: \~/.electroneum-sc
* Windows: %LOCALAPPDATA%\Electroneum-sc

Accounts are stored in the keystore subdirectory. The contents of this directories should be transportable between nodes, platforms, and client implementations.

To configure the location of the data directory, the `--datadir` parameter can be specified. See [CLI Options](https://developer.electroneum.com/etn-sc-client/fundamentals/command-line-options) for more details. There may exist multiple data directories for multiple networks (e.g. a separate directory for Electroneum Mainnet and testnet). Each would have subdirectories for their blockchain data and keystore.

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!

## Cleanup <a href="#cleanup" id="cleanup"></a>

Etn-sc's blockchain and state databases can be removed with:

```sh
etn-sc 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. Specifically, passing the `removedb` command with no arguments removes the full node state database, ancient database and light node database.

## Blockchain Import/Export <a href="#blockchain-import-export" id="blockchain-import-export"></a>

Export the blockchain in binary format with:

```sh
etn-sc 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:

```sh
etn-sc 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:

```sh
etn-sc import <filename>
```

And finally: **REMEMBER YOUR PASSWORD** and **BACKUP YOUR KEYSTORE**!


---

# Agent Instructions: 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://developer.electroneum.com/etn-sc-client/fundamentals/backup-and-restore.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.
