Need to archive a MySQL database using a python script

B

bruceg113355

Python Users Group,

I need to archive a MySQL database using a python script.
I found a good example at: https://gist.github.com/3175221

The following line executes however, the archive file is empty.

os.popen("mysqldump -u %s -p%s -h %s -e --opt -c %s | gzip -c > %s.gz" %
(user,password,host,database,database+"_"+filestamp))
Where:
User = “someUser”
password = “somePassword”
host = “someRemote.database.server”
database = “someDatabase”

If I execute mysqldump from the command line, an archive is created.

Using Python 2.6 and MySQL-python-1.2.2.win32-py2.6 (MySQLdb)
Mysql-5.5.27 from the command line.

Any ideas?

Thanks,
Bruce
 
D

Dennis Lee Bieber

Python Users Group,

I need to archive a MySQL database using a python script.
I found a good example at: https://gist.github.com/3175221

The following line executes however, the archive file is empty.

os.popen("mysqldump -u %s -p%s -h %s -e --opt -c %s | gzip -c > %s.gz" %
(user,password,host,database,database+"_"+filestamp))

Well, First start might be to update from the old os.popen to
subprocess.Popen

Then I'd suggest working in pieces... Don't do the pipe/gzip part,
just see if the dump is creating a file first.
 
H

Hans Mulder

Python Users Group,

I need to archive a MySQL database using a python script.
I found a good example at: https://gist.github.com/3175221

The following line executes however, the archive file is empty.

os.popen("mysqldump -u %s -p%s -h %s -e --opt -c %s | gzip -c > %s.gz" %
(user,password,host,database,database+"_"+filestamp))
Where:
User = “someUser”
password = “somePassword”
host = “someRemote.database.server”
database = “someDatabase”

If I execute mysqldump from the command line, an archive is created.

Using Python 2.6 and MySQL-python-1.2.2.win32-py2.6 (MySQLdb)
Mysql-5.5.27 from the command line.

Any ideas?

* If there are shell meta characters in the password, you'd have
need to use single quotes, as in -p'%s'. Actually, that's true
for any of the parameters, but the password is one most likely
to contain punctuation characters.

* You could try

print("mysqldump -u %s -p%s -h %s -e --opt -c %s | gzip -c > %s.gz" %
(user,password,host,database,database+"_"+filestamp))

and if the result looks okay, copy and paste it to the command line
(do not retype; use copy and paste) and see if it works.

* In your script, add a line

os.popen("monty_python")

This should produce an error message. If it doesn't, find out why.

* Check the timestamp of your empty output file. If it was created
yesterday, then maybe your script is now writing its file in another
directory and you're looking at the output of yesterday's test.


Hope this helps,

-- HansM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top