Commit 587925b4 authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

Add db_restore task

parent 16bff396
......@@ -2,6 +2,7 @@ from .deploy import *
import drush
import behat
import docker
import core
from .environments import e
from fabric.api import lcd, cd, task, roles, env, local, run, runs_once, execute
......
from __future__ import unicode_literals
from fabric.api import lcd, cd, task, roles, env, local, run, runs_once, execute
from fabric.contrib.console import confirm
from fabric.colors import red, green
import helpers as h
import os.path
@task
@roles('local')
def db_import(filename, role='local'):
"""Import and restore the specified database dump.
$ fab core.db_import:/tmp/db_dump.sql.gz
:param filename: a full path to a gzipped sql dump.
"""
if os.path.isfile(filename):
print green('Database dump {} found.'.format(filename))
with h.fab_cd(role, env.site_root):
h.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))
......@@ -163,3 +163,4 @@ def gen_doc(role='local'):
h.fab_run(role, 'asciidoctor -b html5 -o {}/CHANGELOG.html {}/CHANGELOG.adoc'.format(env.workspace, env.workspace))
print(green('CHANGELOG.html generated in {}'.format(env.workspace)))
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