Skip to content

Instantly share code, notes, and snippets.

@alb3rto269
Created January 30, 2015 18:24
Show Gist options
  • Save alb3rto269/17ad19cb076d08b78af2 to your computer and use it in GitHub Desktop.
Save alb3rto269/17ad19cb076d08b78af2 to your computer and use it in GitHub Desktop.
Simple dump task for fabric
# Simple environment
env.project_name = 'my_project'
env.project_path = '/home/user/{project_name}'.format(**env)
env.environment = 'dev' # 'dev' || 'prod'
env.dump_path = '{project_path}/db'.format(**env)
@task
def dump(filename=None):
"""Generate and download a db dump."""
# ensure remote dump_path exists
run("mkdir -p {}".format(env.dump_path))
# build filename
import time
timestamp = time.strftime("%Y%m%d-%H%M%S", time.gmtime())
filename = filename or "db_{}.dump".format(timestamp)
# generate dump
filepath = '{}/{}'.format(env.dump_path, filename)
cmd('pg_dump {} > {}'.format(env.project_name, filepath))
# download dump
get(remote_path=filepath, local_path='db/{}/{}'.format(env.environment,
filename))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment