From 7784299dd0ef9e6c7a0dcd4eec84591909cef386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20=C5=81ukaszewicz?= Date: Tue, 7 Nov 2017 23:05:22 +0100 Subject: [PATCH] add new functions ip, mysql, mysqldump --- mage2docker.plugin.zsh | 57 +++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/mage2docker.plugin.zsh b/mage2docker.plugin.zsh index bd181ef..abd48c1 100644 --- a/mage2docker.plugin.zsh +++ b/mage2docker.plugin.zsh @@ -14,6 +14,10 @@ _mage2docker_mage() { docker exec -it -u www-data $1 bin/magento $2 } +_mage2docker_container_ip() { + docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $1 +} + _mage2docker_report() { compadd `docker exec -u www-data $1 ls -tr var/report` } @@ -22,23 +26,32 @@ _mage2docker_log(){ compadd `docker exec -u www-data $1 ls -tr var/log` } -_mage2docker() { +_mage2docker_mysql_data() { + printf '%s ' 'User name:' + read user + printf '%s ' 'Database name:' + read database + printf '%s ' 'file name:' + read file +} + +_mage2docker() { local curcontext="$curcontext" state line typeset -A opt_args - + _arguments \ '1: :->containerName'\ '2: :->command' \ '3: :->options' - + case $state in containerName) compadd $(_docker_get_container_name) ;; command) - compadd "$@" bash-www bash logs magento mage mage-cache mage-reindex mage-di mage-upgrade mage-report mage-log grunt watch rename rm restart stop inspect top - ;; + compadd "$@" bash-www bash logs magento mage mage-cache mage-reindex mage-di mage-upgrade mage-report mage-log grunt watch rename rm restart stop inspect top mysqldump mysql ip + ;; options) case $words[3] in mage) @@ -49,7 +62,7 @@ _mage2docker() { ;; mage-log) _mage2docker_log $words[2] - ;; + ;; esac esac } @@ -62,9 +75,9 @@ mage2docker () { docker $2 $1 ;; logs) - docker logs -f $1 + docker logs -f $1 ;; - bash) + bash) docker exec -it -u root $1 bash ;; bash-www) @@ -74,10 +87,10 @@ mage2docker () { docker exec -it -u www-data $1 bin/magento ;; mage)$ - _mage2docker_mage $1 $3 + _mage2docker_mage $1 $3 ;; mage-cache) - _mage2docker_mage $1 cache:clean + _mage2docker_mage $1 cache:clean ;; mage-reindex) _mage2docker_mage $1 indexer:reindex @@ -103,22 +116,36 @@ mage2docker () { mage-log) docker exec -it -u www-data $1 tail -f var/log/$3 ;; + #new informations + ip) + _mage2docker_container_ip $1 + ;; + mysqldump) + _mage2docker_mysql_data + mysqldump -h$(_mage2docker_container_ip $1) -u$user -p $database > $file + echo "Success database backup was created" + ;; + mysql) + _mage2docker_mysql_data + mysql -h$(_mage2docker_container_ip $1) -u$user -p $database < $file + echo "Success database restore" + ;; *) if [ ! "$1" ]; then docker ps else docker exec -it -u www-data $1 bash - fi - ;; - esac + fi + ;; + esac } if type "docker" > /dev/null; then - + compdef _mage2docker mage2docker alias m2d='mage2docker' -else +else echo "mage2docker - docker is not installed" fi