Created
July 16, 2011 21:54
-
-
Save seungjin/1086839 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## {{{ http://code.activestate.com/recipes/577793/ (r1) | |
| #!/usr/bin/env python | |
| import os | |
| import time | |
| username = 'root' | |
| defaultdb = 'postgres' | |
| port = '5433' | |
| backupdir='/www/backup/' | |
| date = time.strftime('%Y-%m-%d') | |
| #GET DB NAMES | |
| get_db_names="psql -U%s -d%s -p%s --tuples-only -c '\l' | awk -F\| '{ print $1 }' | grep -E -v '(template0|template1|^$)'" % (username, defaultdb, port) | |
| #MAKE BACKUP OF SYSTEMGRANTS | |
| os.popen("pg_dumpall -p%s -g|gzip -9 -c > %s/system.%s.gz" % (port, backupdir, date)) | |
| #MAKING DB BACKUP | |
| for base in os.popen(get_db_names).readlines(): | |
| base = base.strip() | |
| fulldir = backupdir + base | |
| if not os.path.exists(fulldir): | |
| os.mkdir(fulldir) | |
| filename = "%s/%s-%s.sql" % (fulldir, base, date) | |
| os.popen("nice -n 19 pg_dump -C -F c -U%s -p%s %s > %s" % (username, port, base, filename)) | |
| ## end of http://code.activestate.com/recipes/577793/ }}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment