Guest User

Untitled

a guest
Jan 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import os
  3. import time
  4.  
  5. username = 'root'
  6. defaultdb = 'postgres'
  7. port = '5433'
  8. backupdir='/www/backup/'
  9. date = time.strftime('%Y-%m-%d')
  10.  
  11. #GET DB NAMES
  12. 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)
  13.  
  14. #MAKE BACKUP OF SYSTEMGRANTS
  15. os.popen("pg_dumpall -p%s -g|gzip -9 -c > %s/system.%s.gz" % (port, backupdir, date))
  16.  
  17. #MAKING DB BACKUP
  18. for base in os.popen(get_db_names).readlines():
  19. base = base.strip()
  20. fulldir = backupdir + base
  21. if not os.path.exists(fulldir):
  22. os.mkdir(fulldir)
  23. filename = "%s/%s-%s.sql" % (fulldir, base, date)
  24. os.popen("nice -n 19 pg_dump -C -F c -U%s -p%s %s > %s" % (username, port, base, filename))
Add Comment
Please, Sign In to add comment