Created
April 11, 2012 18:56
-
-
Save ecogswell/2361379 to your computer and use it in GitHub Desktop.
pull db
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
@hosts(["mckenzie.servers.ljworld.com"]) | |
def pull_db(db_name, user_db_name=None): | |
if db_name is None: | |
exit("You must provide a database name") | |
# add username to db_name | |
if user_db_name is None: | |
user_db_name = '%s_%s' % (env.user, db_name) | |
# drop the existing database | |
with settings(warn_only=True): | |
drop_result = local("dropdb %s" % user_db_name, capture=True) | |
if drop_result.failed and not confirm("Database %s does not exist, continue anyway?" % user_db_name): | |
abort("Aborting at user request") | |
# get the source db | |
run("pg_dump -Fc -U postgres -h10.0.0.50 %s |pv > ~/db/%s_local.db" % (db_name, db_name)) | |
local("scp %s:~/db/%s_local.db ~/db/" % db_name) | |
# restore the source db into the target db | |
local("postgis_restore.pl /usr/local/Cellar/postgresql/9.0.4/share/postgresql/contrib/postgis-1.5/postgis.sqls ~/db/%s_local.db" % db_name) | |
# clean files left from process | |
local("rm ~/db/%s_local.db" % db_name) | |
local("rm ~/db/%s_local.db.ascii" % db_name) | |
local("rm ~/db/%s_local.db.list" % db_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment