Skip to content

Instantly share code, notes, and snippets.

@armonge
Created December 15, 2014 23:36
Show Gist options
  • Save armonge/20d10c6c22fa57cd8ce1 to your computer and use it in GitHub Desktop.
Save armonge/20d10c6c22fa57cd8ce1 to your computer and use it in GitHub Desktop.
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