I seem to be having a problem. I want a view where I can allow staff users to download the MySQL database for that program. Unfortunately it is not working. I finding out the problem seems to be hard.
Views.py
@login_required
def dbbackup(request):
if not (request.user.is_authenticated() and request.user.is_staff):
raise http.Http404
os.popen3("mysqldump -u *username* -p*password* *database* > /usr/local/src/djcode/c2duo_mms/backup.sql")
os.popen3("gzip -c /usr/local/src/djcode/c2duo_mms/backup.sql > /usr/local/src/djcode/c2duo_mms/backup.gz"
return HttpResponseRedirect("/mmc")
I have tried to troubleshoot the problem. It is failing on the part where it dumps the data - as there is no sql file in c2duo_mms that appears.
Now, if I was to create a seperate python script, the run using python test.py it will work. So why is it that it cannot work in my views.py file - or Django.
test.py
#!/usr/bin/env python
from django.conf import settings
import os
os.popen3("mysqldump -u *username* -p*password* *database* > /usr/local/src/djcode/c2duo_mms/backup.sql")
os.popen3("gzip -c /usr/local/src/djcode/c2duo_mms/backup.sql > /usr/local/src/djcode/c2duo_mms/backup.gz")
Also here are the the permission of my c2duo_mms folder. All of the files have the same permissions as well. I don't think its to do with permissions. I'm also making sure I am using full directory paths.
drwxr-xr-x 5 root root 4096 Aug 15 12:40 c2duo_mms