Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. Backup all MySQL databases, one in each file with a timestamp on the end.
  2.  
  3.  
  4.  
  5. #Importing the modules
  6. import os
  7. import ConfigParser
  8. import time
  9.  
  10. # On Debian, /etc/mysql/debian.cnf contains 'root' a like login and password.
  11. config = ConfigParser.ConfigParser()
  12. config.read("/etc/mysql/debian.cnf")
  13. username = config.get('client', 'user')
  14. password = config.get('client', 'password')
  15. hostname = config.get('client', 'host')
  16. filestamp = time.strftime('%Y-%m-%d')
  17.  
  18. # Get a list of databases with :
  19. database_list_command="mysql -u %s -p%s -h %s --silent -N -e 'show databases'" % (username, password, hostname)
  20. for database in os.popen(database_list_command).readlines():
  21. database = database.strip()
  22. if database == 'information_schema':
  23. continue
  24. if database == 'performance_schema':
  25. continue
  26. filename = "/backups/mysql/%s-%s.sql" % (database, filestamp)
  27. os.popen("mysqldump --single-transaction -u %s -p%s -h %s -d %s | gzip -c > %s.gz" % (username, password, hostname, database, filename))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement