Bakcup Django Database

1

Good afternoon, I have an application in Django 1.10 in which today I need to create a backup of the bd, this copy must be made when the user clicks on a button that will be placed in a template and download the copy on the user's computer.

In my views.py I have the following.

def backup(request):
    subprocess.Popen("mysqldump -u root -p12345 victimas > /home/proyecto/backup.sql")
    subprocess.Popen("gzip -c /home/proyecto/backup.sql > /home/proyecto/backup.gz")
    dataf = open('/home/proyecto/backups/backup.gz', 'r')
    return HttpResponse(dataf.read(), mimetype='application/x-gzip')

But I get the error

[Errno 2] No such file or directory: django mysqldump

When doing it directly from the consolo I create the file, and verify the permissions of the folder.

I appreciate your cooperation

    
asked by jhon1946 18.10.2017 в 18:40
source

1 answer

1

I think the problem is how the Popen runs, try this way:

subprocess.Popen("mysqldump -u root -p12345 victimas > /home/proyecto/backup.sql", shell=True)

Here comes info about it, link

    
answered by 19.10.2017 / 18:43
source