Created
January 30, 2015 18:24
-
-
Save alb3rto269/17ad19cb076d08b78af2 to your computer and use it in GitHub Desktop.
Simple dump task for fabric
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
# 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