当前位置: 代码迷 >> 综合 >> redis 数据迁移 restore
  详细解决方案

redis 数据迁移 restore

热度:10   发布时间:2023-12-16 00:46:57.0
#!/bin/bash
#redis数据迁移脚本,将其他库的数据迁移到0号库
ip='localhost'
port=6379
dest_db=0for ((db=1;db<16;db++))
doredis-cli -h $ip -p $port  -n $db keys "*" | while read keydoif [ -n "$key" ];thenredis-cli -h $ip -p $port  -n $db ttl $key | while read kdoif [ $k -gt -1 ];thenredis-cli -h $ip -p $port  -n $db --raw dump $key | perl -pe 'chomp if eof' | redis-cli -h $ip -p $port -n $dest_db -x restore $key $((k*1000))echo "[$(date "+%Y-%m-%d %H:%M:%S")] migrate key $key from db$db to db$dest_db ttl is $k" >> migrate-redis.logelseredis-cli -h $ip -p $port  -n $db --raw dump $key | perl -pe 'chomp if eof' | redis-cli -h $ip -p $port -n $dest_db -x restore $key 0echo "[$(date "+%Y-%m-%d %H:%M:%S")] migrate key $key from db$db to db$dest_db"  >> migrate-redis.logfidonefidone
done
  相关解决方案