<div class="gmail_quote">On 26 September 2012 00:17,  <span dir="ltr"><<a href="mailto:bruceg113355@gmail.com" target="_blank">bruceg113355@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Python Users Group,<br>
<br>
I need to archive a MySQL database using a python script.<br>
I found a good example at: <a href="https://gist.github.com/3175221" target="_blank">https://gist.github.com/3175221</a><br>
<br>
The following line executes however, the archive file is empty.<br>
<br>
os.popen("mysqldump -u %s -p%s -h %s -e --opt -c %s | gzip -c > %s.gz" %<br>
               (user,password,host,database,database+"_"+filestamp))<br>
Where:<br>
  User     = “someUser”<br>
  password = “somePassword”<br>
  host     = “someRemote.database.server”<br>
  database = “someDatabase”<br></blockquote><div><br></div><div>I hope you're getting those variables from a trusted source as this code is vulnerable to injection.</div><div><br></div><div>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.</div>
<div><br></div><div>Oscar</div></div>