Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Need to archive a MySQL database using a python script (http://www.velocityreviews.com/forums/t952679-need-to-archive-a-mysql-database-using-a-python-script.html)

bruceg113355@gmail.com 09-25-2012 11:17 PM

Need to archive a MySQL database using a python script
 
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

Dennis Lee Bieber 09-26-2012 01:04 AM

Re: Need to archive a MySQL database using a python script
 
On Tue, 25 Sep 2012 16:17:24 -0700 (PDT), bruceg113355@gmail.com
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
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/


Hans Mulder 09-26-2012 11:50 AM

Re: Need to archive a MySQL database using a python script
 
On 26/09/12 01:17:24, bruceg113355@gmail.com 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




All times are GMT. The time now is 09:39 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.