Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Need to archive a MySQL database using a python script

Reply
Thread Tools

Need to archive a MySQL database using a python script

 
 
bruceg113355@gmail.com
Guest
Posts: n/a
 
      09-25-2012
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+"_"+filestam p))
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
 
Reply With Quote
 
 
 
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      09-26-2012
On Tue, 25 Sep 2012 16:17:24 -0700 (PDT), http://www.velocityreviews.com/forums/(E-Mail Removed)
declaimed the following in gmane.comp.python.general:

> 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+"_"+filestam p))


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.
--
Wulfraed Dennis Lee Bieber AF6VN
(E-Mail Removed) HTTP://wlfraed.home.netcom.com/

 
Reply With Quote
 
 
 
 
Hans Mulder
Guest
Posts: n/a
 
      09-26-2012
On 26/09/12 01:17:24, (E-Mail Removed) wrote:
> 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+"_"+filestam p))
> 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+"_"+filestam p))

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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Database Database Database scott93727@gmail.com Computer Information 0 09-27-2012 02:43 AM
DataBase DataBase DataBase DataBase scott93727@gmail.com Computer Information 0 09-26-2012 09:40 AM
Using Python and Connecting to MySQL remotely WITHOUT MySQL installedon local computer dave Python 4 11-18-2010 04:19 AM
Need help with first program to connect to mysql database via apacheand python. pythonbrian Python 1 02-07-2008 02:41 AM
using mysql client to read a file to create a table in a database in a mysql server julian Ruby 8 04-06-2006 10:29 AM



Advertisments