Skip to content

Instantly share code, notes, and snippets.

@yuchant
Created May 21, 2014 00:38
Show Gist options
  • Save yuchant/ba3c7839dc957ba391de to your computer and use it in GitHub Desktop.
Save yuchant/ba3c7839dc957ba391de to your computer and use it in GitHub Desktop.
def pull_down_remote_db():
""" Export database and files.
"""
local_db_dump_path = os.path.join(PROJECT_ROOT, 'remote_db_dump/auto_db_dump.sql')
with settings(sudo_user='postgres'):
with cd('/var/lib/postgresql'):
run('pwd')
print("Dumping database on remote..")
sudo('pg_dump db_krownlab > auto_db_dump.sql')
get('auto_db_dump.sql', local_db_dump_path)
print("Dropping & Creating local DB")
with warn_only():
local("dropdb 'db_krownlab'")
local("createdb db_krownlab")
local('psql db_krownlab < %s' % local_db_dump_path)
def pull_down_remote_files():
""" Download remote files
"""
with cd(DJANGO_DIR):
print("Compressing site_media directory")
run('tar -zcvf site_media.tar.gz site_media')
local_root = os.path.join(os.path.dirname(__file__), 'krownlab')
source = os.path.join(DJANGO_DIR, 'site_media.tar.gz')
target = os.path.join(local_root, 'site_media.tar.gz')
print '''pulling down remote tar archive.
from remote: %s
to local: %s
uncompressed: %s
''' % (source, target, local_root)
get(source, target)
local('tar -xzvf %s -C %s' % (target, local_root))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment