redis误操作flushall或者flushdb

redis是基于内容的nosql,在平时使用中,如果不小心执行了FLUSHALL或者FLUSHDB,那么是否意味着会丢失所有数据?其实不一定,如果开启了appendonly数据备份,还是能够找回相关数据的。


命令介绍:

FLUSHALL [ASYNC]

Delete all the keys of all the existing databases, not just the currently selected one. This command never fails.

The time-complexity for this operation is O(N), N being the number of keys in all existing databases.











FLUSHDB [ASYNC]

Delete all the keys of the currently selected DB. This command never fails.

The time-complexity for this operation is O(N), N being the number of keys in the database.








假设我们已经开启了appendonly数据备份机制。

删除数据前:

192.168.18.247:6489> keys *
1) "gdbbwy20170915112124299"
2) "key1"
3) "gdbbwy20170913711534690"
4) "xorDest"
5) "andDest"
6) "key:__rand_int__"
7) "key2"


192.168.18.247:6489> FLUSHALL
OK
192.168.18.247:6489> keys *
(empty list or set)


在appendonly文件中查看命令执行记录:

[root@rd2DevServer13 6489]# tail appendonly6489.aof 
$7
andDest
*2
$6
SELECT
$1
0
*1
$8
FLUSHALL


紧急恢复方式:

1)关闭redis服务

192.168.18.247:6489> SHUTDOWN

2)删除appendonly中的删除语句

sed -i 's/FLUSHALL//g' appendonly.aof

3)重启服务


192.168.18.247:6489> keys *
1) "gdbbwy20170915112124299"
2) "key1"
3) "gdbbwy20170913711534690"
4) "xorDest"
5) "andDest"
6) "key:__rand_int__"
7) "key2"


原来数据原封不动回来了。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值