当前位置:网站首页>Redis data migration
Redis data migration
2022-07-07 07:29:00 【Interesting soul_ A secular heart】
Realization way 1: utilize redis Master slave replication features
Install the same version of redis , Synchronize the configuration file to the new server . Add the following information
replicaof 192.168.31.216 6379
Then use the client tools to view keys Whether synchronization is complete
Finally, the backup service redis Set the server as the master server
command
// Link client
redis-cli
// View the current master-slave information
info replication
// Set the current slave server as the master server
slaveof no one
// View the master-slave information of the server after the setting is successful
info replication
The following illustration appears , Server setup succeeded 
Realization way 2 Use persistent file recovery
redis Support two ways of persistence , One is snapshot (snapshotting), Also known as RDB The way ; The other is to append files (append-only file), Also known as AOF The way .RDB The way is redis Default persistence method .
RDB The way
RDB The method is to write a snapshot of the data in memory in a binary way with the name dump.rdb In the file of . We are right. Redis Set it up , Let it automatically save the dataset periodically according to the settings . modify redis.conf file , as follows
######################### SNAPSHOTTING ################################
#Save the DB on disk:
…
#In the example below the behaviour will be to save:
#after 900 sec (15 min) if at least 1 key changed
#after 300 sec (5 min) if at least 10 keys changed
#after 60 sec if at least 10000 keys changed
#Note: you can disable saving completely by commenting out all “save” lines.
#It is also possible to remove all the previously configured save
#points by adding a save directive with a single empty string argument
#llike in the following example:
#save “”
#900 If there is more than 1 individual key If it is modified, the snapshot will be saved
save 900 1
#300 If there is more than 10 individual key If it is modified, the snapshot will be saved
save 300 10
#60 If there is more than 1000 individual key If it is modified, the snapshot will be saved
save 60 10000
dump.rdb Files are generated by default in %REDIS_HOME%etc Under the table of contents ( Such as /usr/local/redis/etc/), You can modify redis.conf In the document dir Appoint dump.rdb The path to save
#The working directory.
#The DB will be written inside this directory, with the filename specified
#above using the ‘dbfilename’ configuration directive.
#The Append Only File will also be created inside this directory.
#Note that you must specify a directory here, not a file name.
dir ./
AOF The way
RDB The way is to persist data periodically , If it is not time for persistence ,Redis Cause a breakdown for some reason , Then the server will lose the most recent writes 、 And the data that hasn't been saved to the snapshot . So from redis 1.1 It's starting to introduce AOF The way ,AOF Persistent records all write commands executed by the server , And when the server starts , Restore the dataset by reexecuting these commands . AOF All commands in the file are as follows Redis The format of the agreement to save , The new command is appended to the end of the file .
AOF There is still the possibility of losing data , Because the write command may not be written to the disk immediately after receiving the write command , So we can modify redis.conf, To configure redis call write Function to write the command to the file . as follows
#######################APPEND ONLY MODE #############################
…
AOF and RDB persistence can be enabled at the same time without problems.
If the AOF is enabled on startup Redis will load the AOF, that is the file
with the better durability guarantees.
Please check http://redis.io/topics/persistence for more information.
# Enable AOF The way
appendonly yes
# Every time a new order is added to AOF Execute the document once fsync : Very slow , It's also very safe
appendfsync always
# Per second fsync once : Fast enough ( And use RDB Persistence is almost ), And it will only be lost in case of failure 1 Seconds of data
appendfsync everysec
# never fsync : Give the data to the operating system to process . faster , It's also a safer option
appendfsync no
From the top three AOF Persistence timing , In order not to lose data ,appendfsync always Is the safest
- Redis The mechanism of recovery
If you just configure AOF , Load on restart AOF File recovery data ;
If it is configured at the same time RDB and AOF , Start is load only AOF File recovery data ;
If you just configure RDB, Start is to load dump File recovery data .
2. from aof Recovering data in
1 Note the following configuration
appendonly yes
dir /home/redis/data_6379/
2 Copy AOF File to Redis Data directory for
cp appendonly.aof /home/redis/data_6379/
3 start-up redis-server
redis-server redis_6379.conf
3. from RDB File recovery data
1 Note the following configuration
appendonly no
dir /home/redis/data_6379/
2 Copy RDB File to Redis Data directory for
cp dump.db /home/redis/data_6379/
3 start-up redis-server
redis-server redis_6379.conf
边栏推荐
- 四、高性能 Go 语言发行版优化与落地实践 青训营笔记
- Non empty verification of collection in SQL
- IP address
- $refs: get the element object or sub component instance in the component:
- Blue Bridge Cup Netizen age (violence)
- "Xiaodeng in operation and maintenance" meets the compliance requirements of gdpr
- Torefs API and toref API
- Advanced level of C language (high level) pointer
- Esxi attaching mobile (Mechanical) hard disk detailed tutorial
- Software acceptance test
猜你喜欢

After 95, the CV engineer posted the payroll and made up this. It's really fragrant

Nesting and splitting of components

四、高性能 Go 语言发行版优化与落地实践 青训营笔记

Pass parent component to child component: props

Bindingexception exception (error reporting) processing

Convolutional neural network -- understanding of pooling

Calculus key and difficult points record part integral + trigonometric function integral

1089: highest order of factorial

Composition API premise

Outsourcing for three years, abandoned
随机推荐
RuntimeError: CUDA error: CUBLAS_ STATUS_ ALLOC_ Failed when calling `cublascreate (handle) `problem solving
js小练习----分时提醒问候、表单密码显示隐藏效果、文本框焦点事件、关闭广告
English translation is too difficult? I wrote two translation scripts with crawler in a rage
Esxi attaching mobile (Mechanical) hard disk detailed tutorial
Talk about seven ways to realize asynchronous programming
Asynchronous components and suspend (in real development)
Model application of time series analysis - stock price prediction
Bindingexception exception (error reporting) processing
虚拟机的作用
【leetcode】1020. Number of enclaves
Paranoid unqualified company
Non empty verification of collection in SQL
[semantic segmentation] - multi-scale attention
IP address
Reflection (II)
At the age of 20, I got the ByteDance offer on four sides, and I still can't believe it
Academic report series (VI) - autonomous driving on the journey to full autonomy
毕设-基于SSM大学生兼职平台系统
Advanced practice of C language (high level) pointer
父组件传递给子组件:Props