MySQL备份压缩加密解决方案
MySQL 备份压缩加密方案
数据安全性对于任何一个公司都是非常重要的, 特别是互联网公司. 对数据进行加密也是我们提高安全性的重要手段之一, 今天我们谈谈如何对MySQL进行备份加密.
xtrabackup热备工具是我们最常用的, 它从 xtrabackup 2.2.1 版本开始提供了加密支持, 现今最新版本是2.4.7.今天我们利用该特性进行备份的加密和压缩
下载安装 XtraBackup
1 | 1.在http://www.percona.com/downloads/XtraBackup/LATEST/ |
压缩加密备份
关键参数说明:
Compress
–compress[=name]
1 | This option instructs xtrabackup to compress backup |
–compress-threads=#
1
2
3
4This option specifies the number of worker threads that
will be used for parallel compression. It is passed
directly to the xtrabackup child process. Try 'xtrabackup
--help' for more details.
–compress-chunk-size=#
1 | Size of working buffer(s) for compression threads in |
Encryption
–encrypt=ALGORITHM
currently supported algorithms are: AES128, AES192 and AES256
–encrypt-key=ENCRYPTION_KEY
1
2
3proper length encryption key to use. It is not recommended to use this
option where there is uncontrolled access to the machine as the command
line and thus the key can be viewed as part of the process info.
–encrypt-key-file=name
1 | This option instructs xtrabackup to use the encryption |
–encrypt-threads= NUMBER
the threads number to do encrypt, default 1
操作命令
encrypt-key : 3c0efcea569021b49245e47b5d6a0e28
备份到本机
1 | innobackupex --defaults-file=/data/mysql3306/my.cnf --user=XXXXXXXXX \ |
备份到远端
假设备份中心机器: 192.168.xxx.xxx
1 | innobackupex --defaults-file=/data/mysql3306/my.cnf --user=XXXXXXXXX \ |
备份完成之后会提示日志
1 | xtrabackup: Transaction log of lsn (4669176459) to (4669176459) was copied. |
恢复
解码文件
1 | xbstream -x < /data/tmp/backup20160101.xbstream -C /data/tmp/test |
先解密
方案1
1 | cd /data/tmp/test |
方案2
1 | innobackupex --decrypt=AES256 --encrypt-key=$encrypt-key /data/tmp/test |
解压缩
install qpress tool first
1 | rpmkeys --import https://www.percona.com/downloads/RPM-GPG-KEY-percona |
方案1
innobackupex --decompress .
方案2
1 | /data/tmp/test |
Apply log
innobackupex --apply-log .
...
总结
数据备份的安全性, 对于互联网公司非常重要, 建议大家都进行加密.