您的位置:首页 > 博客中心 > 数据库 >

定时取数据库的schema,并推送到git服务器

时间:2022-03-13 23:19

 

写了个脚本,定时去数据库取schema,并推送到公司的git里。

#daily_schema.py

#/usr/bin/env python
import os import datetime,time os.system(‘mkdir -p /tmp/schema‘) tmp_now=datetime.datetime.now() now=tmp_now.strftime("%Y-%m-%d") os.system("pg_dump -U postgres class4_pr -s -t ‘cdr_report‘ -t ‘cdr_report_detail‘ -t ‘client_cdr‘ -T ‘cdr_report20*‘ -T ‘cdr_report_detail20*‘ -T ‘client_cdr20*‘ > /tmp/schema/class4_pr_%s.sql" %now) time.sleep(30) os.chdir(‘/tmp/schema‘) os.system(‘su mygit‘) os.system(‘git add class4_pr_%s.sql‘ %now) os.system(‘git remote add origin yht_gitlab@git.denovolab.com:liaosf/daily_schema.git‘) os.system(‘git push -u origin master‘)
加到contrab中,每天执行定时任务:
#crontab -e

0 0 * * * python daily_schema.py

 

热门排行

今日推荐

热门手游