写了个脚本,定时去数据库取schema,并推送到公司的git里。
#daily_schema.py
#/usr/bin/env python import os import datetime,time os.system('mkdir -p /mnt/daily_schema') tmp_now=datetime.datetime.now() now=tmp_now.strftime("%Y-%m-%d") os.system("pg_dump -h 192.168.1.115 class4_pr -s -t 'cdr_report' -t 'cdr_report_detail' -t 'client_cdr' -T 'cdr_report20*' -T 'cdr_report_detail20*' -T 'client_cdr20*' > /mnt/daily_schema/class4_pr_%s.sql" %now) time.sleep(2) os.chdir('/mnt/daily_schema') os.system('git pull') time.sleep(3) os.system('git add *') os.system("git commit -a -m '%s schema'" %now) time.sleep(2) os.system('git push origin master') time.sleep(2)
加到contrab中,每天执行定时任务:
#crontab -e
0 0 * * * python daily_schema.py