Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Backup all MySQL databases, one in each file with a timestamp on the end.
- #Importing the modules
- import os
- import ConfigParser
- import time
- # On Debian, /etc/mysql/debian.cnf contains 'root' a like login and password.
- config = ConfigParser.ConfigParser()
- config.read("/etc/mysql/debian.cnf")
- username = config.get('client', 'user')
- password = config.get('client', 'password')
- hostname = config.get('client', 'host')
- filestamp = time.strftime('%Y-%m-%d')
- # Get a list of databases with :
- database_list_command="mysql -u %s -p%s -h %s --silent -N -e 'show databases'" % (username, password, hostname)
- for database in os.popen(database_list_command).readlines():
- database = database.strip()
- if database == 'information_schema':
- continue
- if database == 'performance_schema':
- continue
- filename = "/backups/mysql/%s-%s.sql" % (database, filestamp)
- 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