Redis之-aof恢復

aof恢復簡講過程:redis

[root@ZFRC-YW-YJF-TEST-370123 redis]# pkill -9 redis
[root@ZFRC-YW-YJF-TEST-370123 ~]# cd /var/dir
[root@ZFRC-YW-YJF-TEST-370123 ~]# rm -rf *
清除掉現有環境備份文件;而後啓動服務器進程,添加新數據vim

[root@ZFRC-YW-YJF-TEST-370123 redis]# ./bin/redis-server ./redis.conf
[root@ZFRC-YW-YJF-TEST-370123 redis]# ./bin/redis-server ./redis6380.conf
[root@ZFRC-YW-YJF-TEST-370123 redis]# ./bin/redis-server ./redis6381.conf
[root@ZFRC-YW-YJF-TEST-370123 redis]# ./bin/redis-cli
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> set site www.baidu.com
OK
127.0.0.1:6379> set name yjf
OK
127.0.0.1:6379> set addr bj
OK
127.0.0.1:6379> flushall
OK
127.0.0.1:6379> get name
(nil)服務器

此時必定要先中止服務,避免其餘人有寫入操做,重寫aof。何況aof記錄着也有flushall操做。
[root@ZFRC-YW-YJF-TEST-370123 dir]# more laoyang-appendonly.aof
2
$6
SELECT
$1
0
3
$3
set
$4
site
$13
www.baidu.com
3
$3
set
$4
name
$3
yjf
3
$3
set
$4
addr
$2
bj
*1
$8
flushallapp

127.0.0.1:6379> shutdown nosave ---shutdown 操做不記錄日誌
not connected> ide

而後編輯一下aof生成文件。將最後危險操做flushall給dd掉。--注意記錄的格式,通常是*開始,命令結尾;日誌

[root@ZFRC-YW-YJF-TEST-370123 dir]# vim laoyang-appendonly.aof
刪除下面三行,保存退出
*1
$8
flushallserver

而後重啓一下服務,登錄查詢,若是麼有,退出後,再次登錄查詢
[root@ZFRC-YW-YJF-TEST-370123 redis]# ./bin/redis-server ./redis.conf
[root@ZFRC-YW-YJF-TEST-370123 redis]# ./bin/redis-cli
127.0.0.1:6379> get name
(nil)
127.0.0.1:6379> exit
[root@ZFRC-YW-YJF-TEST-370123 redis]# ./bin/redis-cli
127.0.0.1:6379> get name
yjf進程

檢查rdb文件
[root@ZFRC-YW-YJF-TEST-370123 redis]# ./bin/redis-check-rdb /var/dir/dump6380.rdb
[offset 0] Checking RDB file /var/dir/dump6380.rdb
[offset 27] AUX FIELD redis-ver = '3.2.13'
[offset 41] AUX FIELD redis-bits = '64'
[offset 53] AUX FIELD ctime = '1561537890'
[offset 68] AUX FIELD used-mem = '880976'
[offset 77] Checksum OK
[offset 77] \o/ RDB looks OK! \o/
[info] 0 keys read
[info] 0 expires
[info] 0 already expiredget

相關文章
相關標籤/搜索