# Backup and Restore Database
This chapter introduces how to store data with TOPIO and manage the database.
After the miner joined the network, TOPIO will synchronize the data on the chain automatically.
The db command is shown in the following table.
Command | Description |
---|---|
topio db backup | Backup miner's local database. |
topio db listBackups | List all backups. |
topio db restore | Restore database. |
# Database Directory
WARNING
It is recommended that you do not modify the directory name and file name under the database directory, otherwise some of the TOPIO functions will not be able to be used properly!
TOPIO database directory shown as below.

db: Store all the data on the chain.
log: Store the logs during TOPIO running.
keystore: Store keystore file.
# Backup Database
Note:
- The first backup of the database is a full backup. For subsequent incremental backups, please use the first backup path. If you use a different path than the first backup, it may make your backup database unavailable!
- It is recommended that you backup the testnet network database and the mainnet database in different directories.
Request
topio db backup
Request Parameters
Parameter Name | Required | Default Value | Type | Description |
---|---|---|---|---|
backupdir | Yes | - | String | Database backup directory. |
Options
Option Name | Value | Type | Description |
---|---|---|---|
-h, --help | - | - | Check the command's help information. |
-d, --dir | - | String | Database source directory, the default is the current data directory. |
Request Sample
In the following request sample, the database source directory is "/home/lily/Topnetwork", and the database backup directory is "/home/cathy".
topio db backup -d /home/lily/Topnetwork /home/cathy
Response Schema
- Successful
Database backup operating successfully.
DBversion : 1
- Failed
Backup failed
Error: the /home/db or /home/pdb does not exist.
# List Backups
Request
topio db listBackups
Request Parameters
Parameter Name | Required | Default Value | Type | Description |
---|---|---|---|---|
backupdir | Yes | - | String | Database backup target directory. |
Options
Option Name | Value | Type | Description |
---|---|---|---|
-h, --help | - | - | Check the command's help information. |
Request Sample
Check the backed up database version in the "/home/cathy" directory.
topio db listBackups /home/cathy
Response Schema
- Successful
[root@localhost topio-0.0.0.0-debug]# topio db listBackups /home/cathy
DBversion:1,timestamp:2020-06-05 07:04:02.
DBversion:2,timestamp:2020-06-05 07:07:29.
- Failed
None.
# Restore Database
Execute the command topio DB list_dbVersion
to retrieve all database versions under the backup directory before restoring the database.
Select a version and restore to an empty directory. If no version is specified, the latest version is restored by default.
Request
topio db restore
Request Parameters
Parameter Name | Required | Default Value | Type | Description |
---|---|---|---|---|
backupdir | Yes | - | String | The backup directory of the database. |
Options
Option Name | Value | Type | Description |
---|---|---|---|
-h, --help | - | - | Check the command's help information. |
-d, --dir | - | String | The target directory for the database restore, and must be empty. |
-D, --DBversion | - | Integer | The backed up database version, if not specified, restores the latest version by default. |
Request Sample
Restore the database version "2" in the path "/home/cathy" to the path "/home/peter".
topio db restore -d /home/peter /home/cathy -D 2
Response Schema
- Successful
Database restore operating successfully.
- Failed
Restore failed
Error: The target dir for restore is not empty, please input a empty one.