Created
December 17, 2015 20:55
-
-
Save rondinelisaad/da9b5e1af0e0ba230b0d to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python | |
#coding: utf-8 | |
import argparse | |
import os | |
import time | |
username = 'postgres' | |
defaultdb = 'template1' | |
port = '5432' | |
date = time.strftime('%Y-%m-%d') | |
parser = argparse.ArgumentParser( | |
description='Faz o dump da base e compacta arquivos no format gzip') | |
parser.add_argument('--backupdir', dest='backupdir') | |
args = vars(parser.parse_args()) | |
def main(): | |
#SELECIONANDO O NOME DAS INSTANCIAS NO BANCO | |
get_db_names = "psql -U%s -d%s -p%s --tuples-only -c '\l' \ | |
| awk -F\| '{ print $1 }' | grep -E -v '(template0|template1|template2^$)'\ | |
" % (username, defaultdb, port) | |
def backup_system(): | |
#FAZER BECAPE DE TODO O SISTEMA | |
os.popen("pg_dumpall -p%s -g|gzip -9 -c > %s/system.%s.gz" % ( | |
port, args['backupdir'], date)) | |
def backup_instance(): | |
#FAZENDO BECAPE | |
for base in os.popen(get_db_names).readlines(): | |
base = base.strip() | |
os.chdir(args['backupdir']) | |
filename = "%s-%s.sql" % (base, date) | |
os.popen("nice -n 19 pg_dump -C -F c -U%s -p%s %s > %s" % ( | |
username, port, base, filename)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment