rdb解析rdb文件


环境:
Os:Centos 7
Python:3.6.5

1.安装rdbtools

[root@localhost ~]# pip3 install rdbtools
Collecting rdbtools
  Downloading https://files.pythonhosted.org/packages/dd/e5/eebb748863d74b7f9d433e359b874d97e830e9d1b3e3d876b91b5cba6b9d/rdbtools-0.1.15.tar.gz
Collecting redis (from rdbtools)
  Downloading https://files.pythonhosted.org/packages/91/f1/cbae04b7bdf1ae5f952dcf6babfe413647663e73fef8061a5d3c08b0b6f4/redis-4.0.0-py3-none-any.whl (118kB)
    100% |████████████████████████████████| 122kB 486kB/s 
Collecting deprecated (from redis->rdbtools)
  Downloading https://files.pythonhosted.org/packages/51/6a/c3a0408646408f7283b7bc550c30a32cc791181ec4618592eec13e066ce3/Deprecated-1.2.13-py2.py3-none-any.whl
Collecting wrapt<2,>=1.10 (from deprecated->redis->rdbtools)
  Downloading https://files.pythonhosted.org/packages/e2/0f/89c9c2d8ba06709a3d471507a78be443e2c2d9f1321d3e1154c76f44150c/wrapt-1.13.3-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (78kB)
    100% |████████████████████████████████| 81kB 1.6MB/s 
Installing collected packages: wrapt, deprecated, redis, rdbtools
  Running setup.py install for rdbtools ... done
Successfully installed deprecated-1.2.13 rdbtools-0.1.15 redis-4.0.0 wrapt-1.13.3
You are using pip version 9.0.3, however version 21.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

2.安装python-lzf
pip3 install python-lzf


3.使用
[root@localhost ~]# rdb -help

转换成json格式
rdb -c json /tmp/7001-dump.rdb>/tmp/7001dump.txt

4.rdb文件比较差异
[root@localhost ~]# rdb --command diff /tmp/dump.rdb | sort > /tmp/dump1.txt
[root@localhost ~]# rdb --command diff /tmp/7001-dump.rdb| sort > /tmp/dump2.txt

运行差异程序
安装kdiff3
[root@localhost tmp]#yum install kdiff3 ##python2环境下执行
[root@localhost tmp]# kdiff3 dump1.txt dump2.txt