0

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

1 Answer 1

2

The webserver is probably running as a different user than root, so does not have permissions to create the file.

Sign up to request clarification or add additional context in comments.

2 Comments

Currently when I click on the link, it redirects me to the homepage, but does not dump the darabase. There are no reports of any authentication errors. However if this is the case, how can I find the user that is running the webserver?
@Shehzad009, you need to read stderr returned by os.popen3 if you want to see a errors. Also consider subprocess module since documentation says os.popen3 is obsolete. And if you are in linux you could run ps u to see what user your webserver is running as.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.