python数据迁移--未完
来源:互联网 发布:linux jdk1.7下载 编辑:程序博客网 时间:2024/06/07 04:05
有个需求,要求只保留表的上个月的数据,那么我在crontab中定义每个月1号执行这个脚本
那么时间是 xx月份-01日 某点某分
那我就先把这个上个月的时间返回出来,放到sql里面,把对应的id搞出来,那么这个id就是要迁移数据的最大值。在它之前的数据全部都要迁走,迁走之后再调用工具重建该表,来提升查询的效率。我先把第一块,取系统时间的函数写出来,后面的功能我再慢慢加,别急
import datetime
'''
获取上个月的系统时间,下个月的时间只是顺手写写,暂时用不上
'''
def get_last_1_month_time():today = datetime.datetime.today()
year = today.year
month = today.month
if month == 1:
month = 12
year -= 1
else:
month -= 1
res = datetime.datetime(year,month,1)
return res
def get_next_1_month_time():
today = datetime.datetime.today()
year = today.year
month = today.month
if month == 12:
month = 1
year += 1
else:
month += 1
res = datetime.datetime(year,month,1)
return res
if __name__ == '__main__':
last_month = get_last_1_month_time()
print last_month
next_month = get_next_1_month_time()
print next_month
阅读全文
0 0
- python数据迁移--未完
- Python + Mysql数据迁移
- Python迁移ArcSDE多版本数据
- 使用python进行数据迁移案例
- 7.5-Python-语言及其应用-笔记-数据的归属-未完!
- 用Python定时提取mysql中的数据(未完)
- Python网络数据采集总结——未完待续
- python相关资料(未完)
- Python学习笔记(未完)
- Python学习笔记(未完)
- Python开始(未完)
- Python关键字(未完...)
- 数据迁移
- 数据迁移
- 数据迁移
- 数据迁移
- 数据迁移
- 数据迁移
- 598. Range Addition II的C++解法
- 【剑指offer-解题系列(52)】构建乘积数组
- InvalidDataAccessApiUsageException:Write operations are not allowed in read-only mode (FlushMode.NEV
- Excel VBA高效办公应用-第二章-Excel VBA编辑基础-Part1(VBA关键字)
- Spring源码之XML解析
- python数据迁移--未完
- Android7.0中文文档(API)-- ViewAnimator
- Codeforces 814C An impassioned circulation of affection【Dp】
- bzoj 4802: 欧拉函数 大整数分解
- QT学习 常见操作记录
- JAVA发送http get/post请求,调用http接口、方法
- 微信小程序 车轮之 滑动删除
- Android中Okhttp的使用(一)
- 浏览器的重绘和回流