Created
December 15, 2014 23:36
-
-
Save armonge/20d10c6c22fa57cd8ce1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.http import StreamingHttpResponse | |
from django.conf import settings | |
import subprocess | |
def _backup(): | |
db_config = settings.DATABASES['default'] | |
db_config['HOST'] = db_config.get('HOST') or 'localhost' | |
db_config['PORT'] = db_config.get('PORT') or 3306 | |
command = 'mysqldump -u{USER} -p{PASSWORD} -h{HOST} -P{PORT} {NAME}'.format(**db_config) | |
popen = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True) | |
out = iter(popen.stdout.readline, "") | |
for line in out: | |
yield line | |
def backup(request): | |
return StreamingHttpResponse(_backup()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment