Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Several ways of redis data Export and Import

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Several ways of redis data Export and Import

1 Environment description: 192.168.1.101 node1 redis source instance 192.168.1.102 node2 redis target instance 192.168.1.103 node3 any linux system 2 redis-dump mode 2.1 install RVM

Redis-dump this tool needs to use Ruby, and the yum tool in the centos environment can install up to 2.0 version of Ruby, and the current Redis version 4.0 requires the use of Ruby > = 2.2 version, so we need to install Ruby first, and install Ruby has a good command line tool to help us, this tool is RVM,RVM can provide a convenient multi-version Ruby environment management and switching.

First, go to tmp and store the downloaded installation file cd / tmpmkdir rvmcd rvm# to install RVMgpg-- keyserver hkp://keys.gnupg.net-- recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 curl-O https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer curl-O https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer.asc gpg-- verify rvm-installer.asc bash rvm-installer stable source / etc/profile.d/rvm.sh2.2 install Ruby

View the version of Ruby that can be installed

Rvm list known

Here we install 2.4.1

Rvm install ruby 2.4.1

Set the default ruby

Rvm use 2.4.1-default

View ruby version

Ruby-version2.3 installs the redis-dump tool

Remove gem built-in sources (slow downloading of US servers)

Gem sources-- remove https://rubygems.org/

Add domestic sources

Gem sources-a https://gems.ruby-china.com

View warehouse source

Gem sources-lame http://gems.ruby-china.com/ * CURRENT SOURCES * *

Install redis-dump

Gem install redis-dump-V

Install the gem package included in redis-dump

Drydock-0.6.9.gemuri-redis-0.4.2.gemyajl-ruby-1.4.1.gemredis-dump-0.4.0.gem2.4 redis-dump export

Redis-dump help command

[root@node3] # redis-dump-- help Try: / usr/local/bin/redis-dump show-commandsUsage: / usr/local/bin/redis-dump [global options] COMMAND [command options]-u,-- uri=S Redis URI (e.g. Redis://hostname [: port])-d,-- database=S Redis database (e.g.-d 15)-a -- password=S Redis password (e.g.-a 'my@pass/word')-s,-- sleep=S Sleep for S seconds after dumping (for debugging)-c,-- count=S Chunk size (default: 10000)-f,-- filter=S Filter selected keys (passed directly to redis' KEYS command)-b -- base64 Encode key values as base64 (useful for binary values)-O,-- without_optimizations Disable run time optimizations-V,-- version Display version-D,-- debug-- nosafe [root@node3 ~] #

Export command

Redis-dump-u 192.168.1.101 6379 > 192.168.1.101.json

Export specified database data

Redis-dump-u 192.168.1.101 6379-d 5 > 192.168.1.101.json

If redis has a password

Redis-dump-u: password@192.168.1.101:6379 > 192.168.1.101.json

Redis-dump exports all keys; of the current node when the redis is cluster, you need to export the keys of all master separately

2.5 redis-load import command [root@node3 ~] # redis-load-- help Try: / usr/local/bin/redis-load show-commandsUsage: / usr/local/bin/redis-load [global options] COMMAND [command options]-u,-- uri=S Redis URI (e.g. Redis://hostname [: port])-d,-- database=S Redis database (e.g.-d 15)-a -- password=S Redis password (e.g.-a 'my@pass/word')-s,-- sleep=S Sleep for S seconds after dumping (for debugging)-b,-- base64 Decode key values from base64 (used with redis-dump-b)-n,-- no_check_utf8-V,-- version Display version-D -- debug-- nosafe [root@node3] #

Redis-load Import

| cat 192.168.1.101.json | redis-load-u 192.168.1.102 aof 637mm or < 192.168.1.101.json redis-load-u 192.168.1.102 aof Import method 3.1 Source instance generates aof data # Clean all data of the above target instance [root@node1 ~] # redis-cli-h 192.168.1.102-a password flushallOK# source instance enables aof function The appendonly.aof file [root@node1 ~] # redis-cli-h 192.168.1.101-a password config set appendonly yesOK3.2 target instance will be generated in the dir directory and imported into aof data # assuming that appendonly.aof is in the current path [root@node1 ~] # redis-cli-h 192.168.1.102-a password-- pipe < appendonly.aofAll data transferred. Waiting for the last reply...Last reply received from server.errors: 0, replies: disable aof function for source instance [root@node1 ~] # redis-cli-h 192.168.1.101-a password config set appendonly noOK4 rdb file migration method

Temporary outline

5 the source instance db0 is migrated to the destination instance db1 [root@node1 ~] # cat redisplacementmv.shroud migration to the target instance BASHREDILEI-h 192.168.1.101-p 6379-a password-n 0 keys "*" | while read keydo redis-cli-h 192.168.1.101-p 6379-a password-n 0-- raw dump $key | perl-pe 'chomp if eof' | redis-cli-h 192.168.1.102-p 6379-a password-n 1-x key 0 echo "migrate key $key" done

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report