Periodically fetch the schema of the database and push it to the GIT server

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.