天天看點

Percona-Toolkit系列(21) --- pt-secure-collect

pt-secure-collect

pt-secure-collect:​​官方位址​​

說明

用途:收集、清理、打包和加密資料。

文法:

pt-secure-data [<flags>] <command> [<args> ...]      

預設情況下會收集以下指令的結果:​

​pt-stalk​

​​,​

​pt-summary​

​​,​

​pt-mysql-summary​

​\

  • 收集
pt-secure-collect collect <flags>      
  • 解密
pt-secure-collect decrypt [flags] <input file>      
  • 加密
pt-secure-collect encrypt [flags] <input file>      
  • 清理
pt-secure-collect sanitize [flags]      

具體例子

收集資訊

以非加密方式收集MySQL資訊并且不删除臨時檔案。

[root@BigData ~]# pt-secure-collect collect --bin-dir=/usr/bin \
--temp-dir="/root/pt_collection" --no-encrypt --no-remove-temp-files \
--mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password=123

INFO[2019-07-31 15:41:37] Creating temporary directory: /root/pt_collection
INFO[2019-07-31 15:41:37] Temp directory is "/root/pt_collection"
INFO[2019-07-31 15:41:37] Creating output file "/root/pt_collection/pt-stalk_2019-07-31_15_41_37.out"
INFO[2019-07-31 15:41:37] Running pt-stalk --no-stalk --iterations=2 --sleep=30 --host=localhost --dest=/root/pt_collection --port=3306 --user=root --password=********  --調用pt-stalk指令
INFO[2019-07-31 15:43:09] Creating output file "/root/pt_collection/pt-summary_2019-07-31_15_43_09.out"
INFO[2019-07-31 15:43:09] Running pt-summary    --調用pt-summary指令
INFO[2019-07-31 15:43:16] Creating output file "/root/pt_collection/pt-mysql-summary_2019-07-31_15_43_16.out"
INFO[2019-07-31 15:43:16] Running pt-mysql-summary --host=localhost --port=3306 --user=root --password=********   --調用pt-mysql-summary指令
NFO[2019-07-31 15:43:28] Sanitizing output collected data
INFO[2019-07-31 15:44:08] Creating tar file "/root/pt_collection/pt_collection.tar.gz"      

會在​

​/root/pt_collection​

​目錄下個壓縮檔案,其他檔案為臨時檔案,如下:

[root@BigData pt_collection]# ls      

加密檔案

輸入加密密碼即可

[root@BigData pt_collection]# pt-secure-collect encrypt /root/messages --outfile=/root/messages.aes
Encryption password:
Re type password:
INFO[2019-07-31 16:01:00] Encrypting file "/root/messages" into "messages.aes"      

解密檔案

輸入解密密碼即可

[root@BigData ~]# pt-secure-collect decrypt /root/messages.aes  --outfile= /root/messages.des
Encryption password:
INFO[2019-07-31 16:03:01] Decrypting file "/root/messages.aes" into "messages"      
注意:這裡不管輸入的密碼和原加密密碼一樣不一樣,都不會提示錯誤資訊,但是會造成解密後的檔案内容錯亂。

清理内容

--源檔案内容

[root@BigData ~]# cat test.txt
select name,id from lei where a='1' and name='wo';
commit;

--清理後的内容
[root@BigData ~]# pt-secure-collect sanitize --input-file=/root/test.txt
select name,id from lei where a=? and name=?;
commit;