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 ...@@ -27,7 +27,6 @@ from datetime import datetime
import os.path import os.path
import helpers as h import helpers as h
import core as c
@task(alias='make') @task(alias='make')
@roles('local') @roles('local')
...@@ -117,19 +116,19 @@ def site_install(): ...@@ -117,19 +116,19 @@ def site_install():
with h.fab_cd(role, site_root): with h.fab_cd(role, site_root):
locale = '--locale="fr"' if env.locale else '' locale = '--locale="fr"' if env.locale else ''
h.fab_run(role, 'sudo -u {} drush site-install {} {} --db-url=mysql://{}:{}@{}/{} --site-name={} ' h.fab_run(role, 'sudo -u {} drush site-install {} {} --db-url=mysql://{}:{}@{}/{} --site-name={} '
'--account-name={} --account-pass={} --sites-subdir={} -y'.format(apache, profile, locale, '--account-name={} --account-pass={} --sites-subdir={} -y'.format(apache, profile, locale,
db_user, db_pass, db_user, db_pass,
db_host, db_name, site_name, db_host, db_name, site_name,
site_admin_name, site_admin_name,
site_admin_pass, site_admin_pass,
print green('Site installed successfully!')
site_subdir)) site_subdir))
# Import db_dump if it exists. # Import db_dump if it exists.
if env.db_dump: if 'db_dump' in env and env.db_dump is not False:
c.db_import() h._db_import(env.db_dump)
print green('Site installed successfully!')
h.hook_execute('post_install', role) h.hook_execute('post_install', role)
...@@ -200,3 +200,15 @@ def _init_db(role='docker'): ...@@ -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.')
print red('Could not find database dump at {}'.format(filename))
Supports Markdown
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