ssdb cluster + keepalived build actual combat -5. backup and restore
surroundings
Operating system: CentOS Linux release 7.6.1810 (Core)
ssdb: 1.9.7
keepalived: keepalived-2.0.16
IP:
master: 10.11.100.87
slave: 10.11.100.88
vip:10.11.100.89
Backup and Restore
Reference: Backup SSDB data (export / import)
ssdb official provides 2 backup solutions: export and ssdb-dump
export backup
Export backup is to use the built-in ssdb-cli tool to connect to the ssdb server, and then perform the backup work. You can filter the content to be exported according to the key interval:
1. Create data
[root@localhost ssdb]# ./ssdb-cli -h 10.11.100.87 -p 8888
ssdb (cli) - ssdb command line tool.
Copyright (c) 2012-2016 ssdb.io
'h' or 'help' for help, 'q' to quit.
ssdb-server 1.9.7
ssdb 10.11.100.87:8888> set a 1
ok
(0.001 sec)
ssdb 10.11.100.87:8888> set b 2
ok
(0.001 sec)
ssdb 10.11.100.87:8888> set c 3
ok
(0.002 sec)
ssdb 10.11.100.87:8888> q
bye.
2. Perform a backup
Directly execute the backup script
ssdb 10.11.100.87:8888> export backup.ssdb
100%
done.
View the generated file:
[root@localhost ssdb]# ls
api deps ssdb_cli ssdb.conf ssdb-server var_slave
backup.ssdb log.txt ssdb-cli ssdb-dump ssdb_slave.conf
_cpy_ ssdb-bench ssdb-cli.cpy ssdb-repair var
[root@localhost ssdb]# cat backup.ssdb
set a 1
set b 2
set c 3
The original export statement is to save the data through the set statement.
In addition, if you need to export the database by key interval, you need to use the -i option:
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):
The command export -i backup.ssdb will export KV in the interval [a, z], all HASH, ZSET, QUEUE.
3. Data modification
Modify the data, delete a, add d:
[root@localhost ssdb]# ./ssdb-cli -h 10.11.100.87 -p 8888
ssdb (cli) - ssdb command line tool.
Copyright (c) 2012-2016 ssdb.io
'h' or 'help' for help, 'q' to quit.
ssdb-server 1.9.7
ssdb 10.11.100.87:8888> get a
1
(0.001 sec)
ssdb 10.11.100.87:8888> del a
ok
(0.002 sec)
ssdb 10.11.100.87:8888> set d 4
ok
(0.001 sec)
4. Import
Import the backup script into the database:
ssdb 10.11.100.87:8888> import backup.ssdb
33%
66%
100%
done.
5. Verification
Verification status:
ssdb 10.11.100.87:8888> get a
1
(0.001 sec)
ssdb 10.11.100.87:8888> get d
4
(0.001 sec)
The previously deleted a has been restored, but the d added after the backup still exists. . .
Explain that this kind of export-import command will only convert the data into a set statement during backup, which is equivalent to executing a set statement during recovery. In this case, the newly added data will not be deleted after backup.
If you want to completely restore the state at the time of backup, you need to completely empty the database.
ssdb-dump backup
The ssdb database will bring its own ssdb-dump command after the installation is completed, stored in the tools directory, usage:
./tools/ssdb-dump ip port output_folder
Options:
- ip-the IP address monitored by the ssdb server
- port-the port number on which the ssdb server listens
- output_folder-local directory where backup data will be created
Examples:
./tools/ssdb-dump 127.0.0.1 8888 ./output_folder
The directory output_folder must not exist, because ssdb-dump will create this directory. After the export, there will be two subdirectories in this directory, the data directory contains the data, and an empty meta directory.
1. Create data
Also generate initial data:
[root@localhost ssdb]# ./ssdb-cli -h 10.11.100.87 -p 8888
ssdb (cli) - ssdb command line tool.
Copyright (c) 2012-2016 ssdb.io
'h' or 'help' for help, 'q' to quit.
ssdb-server 1.9.7
ssdb 10.11.100.87:8888> set a 1
ok
(0.001 sec)
ssdb 10.11.100.87:8888> set b 2
ok
(0.001 sec)
ssdb 10.11.100.87:8888> set c 3
ok
(0.001 sec)
2. Perform a backup
Export:
[root@localhost ssdb]# ./ssdb-dump 10.11.100.87 8888 ./backup.ssdb
ssdb-dump - SSDB backup command
Copyright (c) 2012-2015 ssdb.io
recv begin...
received 1 entry(s)
received 3 entry(s)
recv end
total dumped 3 entry(s)
Compactions
Level Files Size(MB) Time(sec) Read(MB) Write(MB)
--------------------------------------------------
compacting data...
Compactions
Level Files Size(MB) Time(sec) Read(MB) Write(MB)
--------------------------------------------------
2 1 0 0 0 0
backup has been made to folder: ./backup.ssdb
A backup.ssdb folder is generated, the data directory contains data, and the meta directory is an empty directory
[root@localhost ssdb]# cd backup.ssdb/
[root@localhost backup.ssdb]# ls
data meta
[root@localhost backup.ssdb]# ls data/
000004.log 000005.ldb CURRENT LOCK LOG MANIFEST-000002
[root@localhost backup.ssdb]# ls meta/
3. Data modification
Modify the data, delete a, add d:
ssdb 10.11.100.87:8888> del a
ok
(0.001 sec)
ssdb 10.11.100.87:8888> set d 4
ok
(0.001 sec)
4. Import
Replace work_dir and restart the service:
[root@localhost ssdb]# ./ssdb-server ssdb.conf -s stop
ssdb-server 1.9.7
Copyright (c) 2012-2015 ssdb.io
[root@localhost ssdb]# mv var var.bak
[root@localhost ssdb]# mv backup.ssdb var
[root@localhost ssdb]# ./ssdb-server -d ssdb.conf
ssdb-server 1.9.7
Copyright (c) 2012-2015 ssdb.io
5. Verification
ssdb 10.11.100.87:8888> get a
1
(0.002 sec)
ssdb 10.11.100.87:8888> get d
not_found
(0.002 sec)
Fully restore to backup state