pt-archiver 是 pt-toolkit 中的一个工具,用于归档,传送数据至下线数据库,或者其他数据库
Examples
Archive all rows from oltp_server to olap_server and to a file:
pt-archiver –source h=oltp_server,D=test,t=tbl –dest h=olap_server \
–file ‘/var/log/archive/%Y-%m-%d-%D.%t’ \
–where “1=1” –limit 1000 –commit-each
Purge (delete) orphan rows from child table:
pt-archiver –source h=host,D=db,t=child –purge \
–where ‘NOT EXISTS(SELECT * FROM parent WHERE col=child.col)’
示例:
root@python-develpment:~# pt-archiver –source h=192.168.134.186,P=3306,u=pt-archive,p=123456,D=pcik_log_dep,t=t_user_login –where=’logintime<“2017-05-05″‘ –file=’a.txt’ –statistics –charset=utf8 –no-delete –progress=500 –limit=2000 –optimize=ture –txn-size=20000
–source 源数据库,后面的参数用‘,’隔开
—where 过滤数据
–statistics 执行完成后显示统计信息
Started at 2017-08-10T12:14:36, ended at 2017-08-10T12:14:39
Source: A=utf8,D=pcik_log_dep,P=3306,h=192.168.134.186,p=…,t=t_user_login,u=pt- archive
SELECT 50281
INSERT 0
DELETE 0
Action Count Time Pct
select 27 0.8560 24.15
print_file 50281 0.3907 11.02
commit 3 0.0014 0.04
other 0 2.2968 64.79
—file 归档到本地(文件格式和select into outfile 一样,导入时使用load data infile 默认即可)
–no-delete 默认是会删除源数据库数据的,加上此参数后将不删除源数据库数据,
—progress 每完成多少行数据就会给出提示
TIME ELAPSED COUNT
2017-08-10T12:14:36 0 0
2017-08-10T12:14:36 0 500
2017-08-10T12:14:36 0 1000
2017-08-10T12:14:36 0 1500
2017-08-10T12:14:36 0 2000
–limit 指定select 每次查询的数量(改变此值可优化速度)
–txn-size=20000 当 –file时 不能用 –commit-each ,可设置此值加快速度
归档并传送至其他服务器
pt-archiver –source h=192.168.134.186,P=3306,u=pt-archive,p=123456,D=pcik_log_dep,t=t_user_login –where=’logintime<“2017-05-05″‘ –file=’a.txt’ –statistics –charset=utf8 –no-delete –progress=500 –limit=20000 –optimize=ture –txn-size=20000 –dest h=192.168.134.186,P=3308,u=root,p=123456 –bulk-insert
–bulk-insert 加快dest 服务器插入数据速度