SSDB backup data (export/import)


Use ssdb-cli

Use ssdb-cli to connect to the SSDB server.

Export

Export the entire database:

# backup current database into file backup.ssdbssdb 127.0.0.1:8888> export backup.ssdb

Export the database according to the Key interval (interactive mode):

ssdb 127.0.0.1:8888> export -i backup.ssdb
input KV range[start, end]:
  start(inclusive, default none): a
    end(inclusive, default none): z
input HASH range:
  start(inclusive, default none):
    end(inclusive, default none):
input ZSET range:
  start(inclusive, default none):
    end(inclusive, default none):
input QUEUE range:
  start(inclusive, default none):
    end(inclusive, default none):

Command export -i backup.ssdb will export the KV and all HASH in the interval [a, z] , ZSET, QUEUE.

Import

# import backup.ssdb into current databasessdb 127.0.0.1:8888> import backup.ssdb

Note The import command will replace the same key in the database.

Use ssdb-dump

The tool used to back up SSDB data is ssdb-dump.

Export

Usage:

./tools/ssdb-dump ip port output_folder

Options:

  • ip - the IP address where the ssdb server listens
  • port - the port number that the ssdb server listens on
  • output_folder - the local directory where the backup data will be created

Example:

./tools/ssdb-dump 127.0.0.1 8888 ./output_folder

Directory output_folder must not exist, because ssdb-dump will create this directory. After export, there will be two subdirectories in this directory, data The directory contains data, and There is an empty meta directory.

Restore

Copy the output_folder directory to your server. You may need to rename it. Then modify your ssdb.conf configuration file and change work_dir Point to the output_folder directory, and then restart ssdb-server.