On 26 September 2012 00:17, <bruceg113...@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+"_"+filestamp))
> Where:
>   User     = “someUser”
>   password = “somePassword”
>   host     = “someRemote.database.server”
>   database = “someDatabase”
>

I hope you're getting those variables from a trusted source as this code is
vulnerable to injection.

Use subprocess.check_call instead of os.popen. os.popen is obsolete and it
also doesn't quite do what you think. It returns a file object. You need to
read the data from the file object and then close it to make the process
actually run.

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

Reply via email to