Commit 5cc9ce49 authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

Improve db_import logic

parent 1fadbec9
......@@ -27,7 +27,6 @@ from datetime import datetime
import os.path
import helpers as h
import core as c
@task(alias='make')
@roles('local')
......@@ -124,12 +123,12 @@ def site_install():
db_host, db_name, site_name,
site_admin_name,
site_admin_pass,
print green('Site installed successfully!')
site_subdir))
# Import db_dump if it exists.
if env.db_dump:
c.db_import()
if 'db_dump' in env and env.db_dump is not False:
h._db_import(env.db_dump)
print green('Site installed successfully!')
h.hook_execute('post_install', role)
......
......@@ -200,3 +200,15 @@ def _init_db(role='docker'):
def _db_import(filename, role='local'):
"""Import and restore the specified database dump.
:param filename: a full path to a gzipped sql dump.
"""
if path.isfile(filename):
print green('Database dump {} found.'.format(filename))
fab_run(role, 'zcat {} | mysql -u{} -p{} -h{} {}'.format(filename, env.site_db_user, env.site_db_pass, env.container_ip, env.site_db_name))
print green('Database dump successfully restored.')
else:
print red('Could not find database dump at {}'.format(filename))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment