Created
September 13, 2012 13:59
-
-
Save bdejong/3714503 to your computer and use it in GitHub Desktop.
fabric + virtualenv + django copy remote db (*) to local (in my case sqlite)
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
def production(): | |
env.hosts = ['you.web.server'] | |
env.user = 'something' | |
env.project_root = '/path/to/your.project/' | |
env.activate = 'source /path.to/your/virtualenv/bin/activate' # virtualenv | |
def virtualenv(command): | |
run(env.activate + '&&' + command) | |
def copy_db_to_local(): | |
output_name = "output_data.json" | |
with cd(env.project_root): | |
virtualenv("python manage.py dumpdata -v0 --natural > %s" % output_name) | |
get(output_name, output_name) | |
run("rm -f %s" % output_name) | |
local("rm -f database.sql3") | |
local("python manage.py syncdb -v0 --noinput") # with django 1.5: --no-initial-data | |
local("python manage.py migrate -v0 --no-initial-data --noinput") | |
local("python manage.py sqlflush -v0 | python manage.py dbshell") | |
local("python manage.py loaddata -v0 %s" % output_name) | |
local("rm -f %s" % output_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment