Redis持久化之AOF的异常恢复演示-----Redis

[root@localhost ~]# cd /myredis
[root@localhost myredis]# ll
总用量 108
drwxr-xr-x. 2 root root    103 1月  18 11:34 appendonlydir
drwxr-xr-x. 2 root root     26 1月  18 11:33 dumpfiles
-rw-r--r--. 1 root root 107531 1月  18 11:33 redis.conf
[root@localhost myredis]# ll
总用量 112
drwxr-xr-x. 2 root root    103 1月  18 11:34 appendonlydir
-rw-r--r--. 1 root root    107 1月  18 11:35 dump6379.rdb
drwxr-xr-x. 2 root root     26 1月  18 11:33 dumpfiles
-rw-r--r--. 1 root root 107531 1月  18 11:33 redis.conf
[root@localhost myredis]# cd appendonlydir
[root@localhost appendonlydir]# ll
总用量 12
-rw-r--r--. 1 root root  88 1月  18 11:34 appendonly.aof.1.base.rdb
-rw-r--r--. 1 root root 110 1月  18 11:35 appendonly.aof.1.incr.aof
-rw-r--r--. 1 root root  88 1月  18 11:34 appendonly.aof.manifest
[root@localhost appendonlydir]# cd ..
[root@localhost myredis]# pwd
/myredis
[root@localhost myredis]# ll
总用量 112
drwxr-xr-x. 2 root root    103 1月  18 11:34 appendonlydir
-rw-r--r--. 1 root root    107 1月  18 11:35 dump6379.rdb
-rw-r--r--. 1 root root 107531 1月  18 11:33 redis.conf
[root@localhost myredis]# rm -f dump6379.rdb
[root@localhost myredis]# ll
总用量 108
drwxr-xr-x. 2 root root    103 1月  18 11:34 appendonlydir
-rw-r--r--. 1 root root 107531 1月  18 11:33 redis.conf
[root@localhost myredis]# cp -r appendonlydir/ appendonlydir.bak
[root@localhost myredis]# ll
总用量 108
drwxr-xr-x. 2 root root    103 1月  18 11:34 appendonlydir
drwxr-xr-x. 2 root root    103 1月  18 11:38 appendonlydir.bak
-rw-r--r--. 1 root root 107531 1月  18 11:33 redis.conf
[root@localhost myredis]# ll
总用量 112
drwxr-xr-x. 2 root root    103 1月  18 11:34 appendonlydir
drwxr-xr-x. 2 root root    103 1月  18 11:38 appendonlydir.bak
-rw-r--r--. 1 root root     88 1月  18 11:39 dump6379.rdb
-rw-r--r--. 1 root root 107531 1月  18 11:33 redis.conf
[root@localhost myredis]# rm -f dump6379.rdb
[root@localhost myredis]# ll
总用量 108
drwxr-xr-x. 2 root root    103 1月  18 11:34 appendonlydir
drwxr-xr-x. 2 root root    103 1月  18 11:38 appendonlydir.bak
-rw-r--r--. 1 root root 107531 1月  18 11:33 redis.conf
[root@localhost myredis]# ll
总用量 112
drwxr-xr-x. 2 root root    103 1月  18 11:34 appendonlydir
drwxr-xr-x. 2 root root    103 1月  18 11:38 appendonlydir.bak
-rw-r--r--. 1 root root     88 1月  18 11:40 dump6379.rdb
-rw-r--r--. 1 root root 107531 1月  18 11:33 redis.conf
[root@localhost myredis]# rm -f dump6379.rdb
[root@localhost myredis]# ll
总用量 108
drwxr-xr-x. 2 root root    103 1月  18 11:34 appendonlydir
drwxr-xr-x. 2 root root    103 1月  18 11:38 appendonlydir.bak
-rw-r--r--. 1 root root 107531 1月  18 11:33 redis.conf
[root@localhost myredis]# rm -rf appendonlydir
[root@localhost myredis]# ll
总用量 108
drwxr-xr-x. 2 root root    103 1月  18 11:38 appendonlydir.bak
-rw-r--r--. 1 root root 107531 1月  18 11:33 redis.conf
[root@localhost myredis]# mv appendonlydir.bak appendonlydir
[root@localhost myredis]# ll
总用量 108
drwxr-xr-x. 2 root root    103 1月  18 11:38 appendonlydir
-rw-r--r--. 1 root root 107531 1月  18 11:33 redis.conf
[root@localhost myredis]# cd appendonlydir
[root@localhost appendonlydir]# ll
总用量 12
-rw-r--r--. 1 root root  88 1月  18 11:38 appendonly.aof.1.base.rdb
-rw-r--r--. 1 root root 110 1月  18 11:38 appendonly.aof.1.incr.aof
-rw-r--r--. 1 root root  88 1月  18 11:38 appendonly.aof.manifest
[root@localhost appendonlydir]# ll
总用量 12
-rw-r--r--. 1 root root  88 1月  18 11:38 appendonly.aof.1.base.rdb
-rw-r--r--. 1 root root 162 1月  18 11:44 appendonly.aof.1.incr.aof
-rw-r--r--. 1 root root  88 1月  18 11:38 appendonly.aof.manifest
[root@localhost appendonlydir]# ll
总用量 12
-rw-r--r--. 1 root root  88 1月  18 11:38 appendonly.aof.1.base.rdb
-rw-r--r--. 1 root root 162 1月  18 11:44 appendonly.aof.1.incr.aof
-rw-r--r--. 1 root root  88 1月  18 11:38 appendonly.aof.manifest
[root@localhost appendonlydir]# ll
总用量 12
-rw-r--r--. 1 root root  88 1月  18 11:38 appendonly.aof.1.base.rdb
-rw-r--r--. 1 root root 191 1月  18 14:41 appendonly.aof.1.incr.aof
-rw-r--r--. 1 root root  88 1月  18 11:38 appendonly.aof.manifest
[root@localhost appendonlydir]# vim appendonly.aof.1.incr.aof 
[root@localhost appendonlydir]# ll
总用量 12
-rw-r--r--. 1 root root  88 1月  18 11:38 appendonly.aof.1.base.rdb
-rw-r--r--. 1 root root 236 1月  18 14:42 appendonly.aof.1.incr.aof
-rw-r--r--. 1 root root  88 1月  18 11:38 appendonly.aof.manifest
[root@localhost appendonlydir]# redis-check-aof appendonly.aof.1.incr.aof
Start checking Old-Style AOF
AOF appendonly.aof.1.incr.aof format error
AOF analyzed: filename=appendonly.aof.1.incr.aof, size=236, ok_up_to=191, ok_up_to_line=46, diff=45
AOF appendonly.aof.1.incr.aof is not valid. Use the --fix option to try fixing it.
[root@localhost appendonlydir]# vim appendonly.aof.1.incr.aof 
[root@localhost appendonlydir]# redis-check-aof --fix appendonly.aof.1.incr.aof
Start checking Old-Style AOF
AOF appendonly.aof.1.incr.aof format error
AOF analyzed: filename=appendonly.aof.1.incr.aof, size=236, ok_up_to=191, ok_up_to_line=46, diff=45
This will shrink the AOF appendonly.aof.1.incr.aof from 236 bytes, with 45 bytes, to 191 bytes
Continue? [y/N]: y                   
Successfully truncated AOF appendonly.aof.1.incr.aof
[root@localhost appendonlydir]# vim appendonly.aof.1.incr.aof 

[root@localhost ~]# cd /myredis
[root@localhost myredis]# ll
总用量 108
drwxr-xr-x. 2 root root    103 1月  18 11:34 appendonlydir
drwxr-xr-x. 2 root root     26 1月  18 11:33 dumpfiles
-rw-r--r--. 1 root root 107531 1月  18 11:33 redis.conf
[root@localhost myredis]# ll
总用量 112
drwxr-xr-x. 2 root root    103 1月  18 11:34 appendonlydir
-rw-r--r--. 1 root root    107 1月  18 11:35 dump6379.rdb
drwxr-xr-x. 2 root root     26 1月  18 11:33 dumpfiles
-rw-r--r--. 1 root root 107531 1月  18 11:33 redis.conf
[root@localhost myredis]# cd appendonlydir
[root@localhost appendonlydir]# ll
总用量 12
-rw-r--r--. 1 root root  88 1月  18 11:34 appendonly.aof.1.base.rdb
-rw-r--r--. 1 root root 110 1月  18 11:35 appendonly.aof.1.incr.aof
-rw-r--r--. 1 root root  88 1月  18 11:34 appendonly.aof.manifest
[root@localhost appendonlydir]# cd ..
[root@localhost myredis]# pwd
/myredis
[root@localhost myredis]# ll
总用量 112
drwxr-xr-x. 2 root root    103 1月  18 11:34 appendonlydir
-rw-r--r--. 1 root root    107 1月  18 11:35 dump6379.rdb
-rw-r--r--. 1 root root 107531 1月  18 11:33 redis.conf
[root@localhost myredis]# rm -f dump6379.rdb
[root@localhost myredis]# ll
总用量 108
drwxr-xr-x. 2 root root    103 1月  18 11:34 appendonlydir
-rw-r--r--. 1 root root 107531 1月  18 11:33 redis.conf
[root@localhost myredis]# cp -r appendonlydir/ appendonlydir.bak
[root@localhost myredis]# ll
总用量 108
drwxr-xr-x. 2 root root    103 1月  18 11:34 appendonlydir
drwxr-xr-x. 2 root root    103 1月  18 11:38 appendonlydir.bak
-rw-r--r--. 1 root root 107531 1月  18 11:33 redis.conf
[root@localhost myredis]# ll
总用量 112
drwxr-xr-x. 2 root root    103 1月  18 11:34 appendonlydir
drwxr-xr-x. 2 root root    103 1月  18 11:38 appendonlydir.bak
-rw-r--r--. 1 root root     88 1月  18 11:39 dump6379.rdb
-rw-r--r--. 1 root root 107531 1月  18 11:33 redis.conf
[root@localhost myredis]# rm -f dump6379.rdb
[root@localhost myredis]# ll
总用量 108
drwxr-xr-x. 2 root root    103 1月  18 11:34 appendonlydir
drwxr-xr-x. 2 root root    103 1月  18 11:38 appendonlydir.bak
-rw-r--r--. 1 root root 107531 1月  18 11:33 redis.conf
[root@localhost myredis]# ll
总用量 112
drwxr-xr-x. 2 root root    103 1月  18 11:34 appendonlydir
drwxr-xr-x. 2 root root    103 1月  18 11:38 appendonlydir.bak
-rw-r--r--. 1 root root     88 1月  18 11:40 dump6379.rdb
-rw-r--r--. 1 root root 107531 1月  18 11:33 redis.conf
[root@localhost myredis]# rm -f dump6379.rdb
[root@localhost myredis]# ll
总用量 108
drwxr-xr-x. 2 root root    103 1月  18 11:34 appendonlydir
drwxr-xr-x. 2 root root    103 1月  18 11:38 appendonlydir.bak
-rw-r--r--. 1 root root 107531 1月  18 11:33 redis.conf
[root@localhost myredis]# rm -rf appendonlydir
[root@localhost myredis]# ll
总用量 108
drwxr-xr-x. 2 root root    103 1月  18 11:38 appendonlydir.bak
-rw-r--r--. 1 root root 107531 1月  18 11:33 redis.conf
[root@localhost myredis]# mv appendonlydir.bak appendonlydir
[root@localhost myredis]# ll
总用量 108
drwxr-xr-x. 2 root root    103 1月  18 11:38 appendonlydir
-rw-r--r--. 1 root root 107531 1月  18 11:33 redis.conf
[root@localhost myredis]# cd appendonlydir
[root@localhost appendonlydir]# ll
总用量 12
-rw-r--r--. 1 root root  88 1月  18 11:38 appendonly.aof.1.base.rdb
-rw-r--r--. 1 root root 110 1月  18 11:38 appendonly.aof.1.incr.aof
-rw-r--r--. 1 root root  88 1月  18 11:38 appendonly.aof.manifest
[root@localhost appendonlydir]# ll
总用量 12
-rw-r--r--. 1 root root  88 1月  18 11:38 appendonly.aof.1.base.rdb
-rw-r--r--. 1 root root 162 1月  18 11:44 appendonly.aof.1.incr.aof
-rw-r--r--. 1 root root  88 1月  18 11:38 appendonly.aof.manifest
[root@localhost appendonlydir]# ll
总用量 12
-rw-r--r--. 1 root root  88 1月  18 11:38 appendonly.aof.1.base.rdb
-rw-r--r--. 1 root root 162 1月  18 11:44 appendonly.aof.1.incr.aof
-rw-r--r--. 1 root root  88 1月  18 11:38 appendonly.aof.manifest
[root@localhost appendonlydir]# ll
总用量 12
-rw-r--r--. 1 root root  88 1月  18 11:38 appendonly.aof.1.base.rdb
-rw-r--r--. 1 root root 191 1月  18 14:41 appendonly.aof.1.incr.aof
-rw-r--r--. 1 root root  88 1月  18 11:38 appendonly.aof.manifest
[root@localhost appendonlydir]# vim appendonly.aof.1.incr.aof 
[root@localhost appendonlydir]# ll
总用量 12
-rw-r--r--. 1 root root  88 1月  18 11:38 appendonly.aof.1.base.rdb
-rw-r--r--. 1 root root 236 1月  18 14:42 appendonly.aof.1.incr.aof
-rw-r--r--. 1 root root  88 1月  18 11:38 appendonly.aof.manifest
[root@localhost appendonlydir]# redis-check-aof appendonly.aof.1.incr.aof
Start checking Old-Style AOF
AOF appendonly.aof.1.incr.aof format error
AOF analyzed: filename=appendonly.aof.1.incr.aof, size=236, ok_up_to=191, ok_up_to_line=46, diff=45
AOF appendonly.aof.1.incr.aof is not valid. Use the --fix option to try fixing it.
[root@localhost appendonlydir]# vim appendonly.aof.1.incr.aof 
[root@localhost appendonlydir]# redis-check-aof --fix appendonly.aof.1.incr.aof
Start checking Old-Style AOF
AOF appendonly.aof.1.incr.aof format error
AOF analyzed: filename=appendonly.aof.1.incr.aof, size=236, ok_up_to=191, ok_up_to_line=46, diff=45
This will shrink the AOF appendonly.aof.1.incr.aof from 236 bytes, with 45 bytes, to 191 bytes
Continue? [y/N]: y                   
Successfully truncated AOF appendonly.aof.1.incr.aof
[root@localhost appendonlydir]# vim appendonly.aof.1.incr.aof 
 

127.0.0.1:6379> flushdb
OK
127.0.0.1:6379> keys *
(empty array)
127.0.0.1:6379> shutdown
not connected> quit
[root@localhost myredis]# redis-server /myredis/redis.conf
[root@localhost myredis]# redis-cli -a abc123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> keys *
1) "k1"
2) "k3"
3) "k2"
127.0.0.1:6379> set k4 v4
OK
127.0.0.1:6379> get k4
"v4"
127.0.0.1:6379> set k4 v4
OK
127.0.0.1:6379> get k4
"v4"
127.0.0.1:6379> keys *
1) "k4"
2) "k1"
3) "k3"
4) "k2"
127.0.0.1:6379> shutdown
not connected> quit
[root@localhost myredis]# redis-server /myredis/redis.conf
[root@localhost myredis]# redis-cli -a abc123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected> quit
[root@localhost myredis]# ps -ef|grep redis
root       8651   2635  0 14:48 pts/0    00:00:00 grep --color=auto redis
[root@localhost myredis]# lsof -i 6379
lsof: unknown protocol name (379) in: -i 6379
lsof 4.87
 latest revision: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/
 latest FAQ: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ
 latest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man
 usage: [-?abhKlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-f[gG]] [+|-e s]
 [-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]] [-p s]
[+|-r [t]] [-s [p:s]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [-Z [Z]] [--] [names]
Use the ``-h'' option to get more help information.
[root@localhost myredis]# lsof -i:6379
[root@localhost myredis]# cd /usr/local/bin
[root@localhost bin]# pwd
/usr/local/bin
[root@localhost bin]# ll
总用量 29240
-rwxr-xr-x. 1 root root  6900280 1月  16 17:02 redis-benchmark
lrwxrwxrwx. 1 root root       12 1月  16 17:02 redis-check-aof -> redis-server
lrwxrwxrwx. 1 root root       12 1月  16 17:02 redis-check-rdb -> redis-server
-rwxr-xr-x. 1 root root  7620152 1月  16 17:02 redis-cli
lrwxrwxrwx. 1 root root       12 1月  16 17:02 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 15416160 1月  16 17:02 redis-server
[root@localhost bin]# redis-server /myredis/redis.conf
[root@localhost bin]# redis-cli -a abc123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

 127.0.0.1:6379> flushdb
OK
127.0.0.1:6379> keys *
(empty array)
127.0.0.1:6379> shutdown
not connected> quit
[root@localhost myredis]# redis-server /myredis/redis.conf
[root@localhost myredis]# redis-cli -a abc123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> keys *
1) "k1"
2) "k3"
3) "k2"
127.0.0.1:6379> set k4 v4
OK
127.0.0.1:6379> get k4
"v4"
127.0.0.1:6379> set k4 v4
OK
127.0.0.1:6379> get k4
"v4"
127.0.0.1:6379> keys *
1) "k4"
2) "k1"
3) "k3"
4) "k2"
127.0.0.1:6379> shutdown
not connected> quit
[root@localhost myredis]# redis-server /myredis/redis.conf
[root@localhost myredis]# redis-cli -a abc123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected> quit
[root@localhost myredis]# ps -ef|grep redis
root       8651   2635  0 14:48 pts/0    00:00:00 grep --color=auto redis
[root@localhost myredis]# lsof -i 6379
lsof: unknown protocol name (379) in: -i 6379
lsof 4.87
 latest revision: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/
 latest FAQ: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ
 latest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man
 usage: [-?abhKlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-f[gG]] [+|-e s]
 [-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]] [-p s]
[+|-r [t]] [-s [p:s]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [-Z [Z]] [--] [names]
Use the ``-h'' option to get more help information.
[root@localhost myredis]# lsof -i:6379
[root@localhost myredis]# cd /usr/local/bin
[root@localhost bin]# pwd
/usr/local/bin
[root@localhost bin]# ll
总用量 29240
-rwxr-xr-x. 1 root root  6900280 1月  16 17:02 redis-benchmark
lrwxrwxrwx. 1 root root       12 1月  16 17:02 redis-check-aof -> redis-server
lrwxrwxrwx. 1 root root       12 1月  16 17:02 redis-check-rdb -> redis-server
-rwxr-xr-x. 1 root root  7620152 1月  16 17:02 redis-cli
lrwxrwxrwx. 1 root root       12 1月  16 17:02 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 15416160 1月  16 17:02 redis-server
[root@localhost bin]# redis-server /myredis/redis.conf
[root@localhost bin]# redis-cli -a abc123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值