Wrote a script, timed to the database to take the schema, and pushed to the company's git.
#daily_schema. py
#/usr/bin/env python
ImportOSImportDatetime,timeos.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_rep ort_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 [email protected]:liaosf/daily_schema.git') Os.system ('git push-u Origin master')
Add to Contrab and perform scheduled tasks daily:
#crontab-E
00 * * * python daily_schema.py
Periodically fetch the schema of the database and push it to the GIT server