实现Mysql正式库数据导出并上传到测试机(二)
因为开发需求,需要将几张表的数据每月都导出并上传到测试机,故修改上一份代码,将时间参数输入改为获取上个月的第一天和最后一天。修改后代码如下:#!/usr/bin/env python# -*- coding: utf-8 -*-# @Date: 2018-08-02 10:24:05# @Author: Zhou Jiaan# @Version : $2.0#根据...
·
因为开发需求,需要将几张表的数据每月都导出并上传到测试机,故修改上一份代码,将时间参数输入改为获取上个月的第一天和最后一天。
修改后代码如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2018-08-02 10:24:05
# @Author : Zhou Jiaan
# @Version : $2.0
#根据开发要求将channelStatic tradeInfo iflogInfo 上个月的数据导入测试机
import os
import sys
import datetime
import calendar
def ExportData( start_date, end_date):
month=datetime.datetime.now().month-1
os.system(
"mysql -hXX.XX.XX.XXX -uroot -pXXXXXXX mycart -e \"select * from channelStatic WHERE ordtime BETWEEN '{0}' AND '{1}' \" >/home/zhouja01/log/20channelStatic_{2}.txt".format(start_date, end_date,month))
def main():
today = datetime.date.today()
end_date= datetime.date(today.year, today.month, 1) - datetime.timedelta(1)
start_date = datetime.date(end_date.year, end_date.month, 1)
ExportData(start_date, end_date)
if __name__ == '__main__':
main()
将导出数据下载到堡垒机并上传到测试机:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2018-08-03 10:03:09
# @Author : Zhou Jiaan
# @Version : $V2.0
import os
import sys
import datetime
def remote_mysql_system():
month=datetime.datetime.now().month-1
mysql_system_ip = ['10.1.11.37', ]
tableName = ['channelStatic','tradeInfo','iflogInfo']
for mysql_ip in mysql_system_ip:
for table_name in tableName:
os.system("ssh zhouja01@{0} 'python /home/zhouja01/bin/threetable.py'".format(mysql_ip))
os.system("scp zhouja01@{0}:/home/zhouja01/log/{1}{2}_{3}.txt /home/zhouja01/log/".format(mysql_ip,mysql_ip[3:5],table_name,month))
os.system("scp /home/zhouja01/log/{0}{1}_{2}.txt root@10.1.100.240:/home/zhouja01/log".format(mysql_ip[3:5],table_name,month))
def main():
remote_mysql_system()
if __name__ == '__main__':
main()
更多推荐
已为社区贡献7条内容
所有评论(0)