MMZ wrote:

> config.read("~/my.cnf")
> username = config.get('client', 'mmz')
> password = config.get('client', 'pass1')
> hostname = config.get('client', 'localhost')

### A simple config file ###
[client]
user = mmz
password = pass1
host = localhost
### EOF ###

#!/usr/bin/env python
import ConfigParser

config = ConfigParser.ConfigParser()
config.read("~/configfile.cfg")
username = config.get('client', 'user')
password = config.get('client', 'password')
hostname = config.get('client', 'host')
[...]

> # 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 == 'db_dev':
>         continue
>     filename = "/backups/mysql/%s-%s.sql" % (database, filestamp)
>     os.popen("mysqldump -u %s -p%s -h %s -e --opt -c %s | gzip -c > %s.gz" 
% (username, password, hostname, database, filename))

command = subprocess.Popen(['mysql', '-u ' + username,
                            '-p' + password, '-h ' + hostname,
                            '--silent', '-N', "-e 'show databases'"],
                            shell=False,
                            stdout=subprocess.PIPE)
status = command.wait()
for line in command.stdout.readlines():
    if line.strip() not in ['information_schema', 'db_dev']:
        filename = "/backups/mysql/%s-%s.sql" % (database, filestamp)
        cmd1  = subprocess.Popen(['mysqldump', '-u ' + username,
                            '-p' + password, '-h ' + hostname,
                            '-e', '--opt', '-c ' + database],
                            shell=False,
                            stdout=subprocess.PIPE)
        cmd2 =  subprocess.Popen(['gzip' '-c'],
                            shell=False,
                            stdout=filename)


Enrico
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to