From 9636856edb5bac78b6946f900b3e6c16c45e054f Mon Sep 17 00:00:00 2001 From: Alex Hyett Date: Sat, 19 Dec 2015 22:31:06 +0000 Subject: [PATCH] Add ability to backup and restore mysql database --- compose-dev.yml | 5 ++++- scripts/docker-dbbackup.sh | 4 ++++ scripts/host-dbbackup.bat | 1 + scripts/vagrant-dbbackup.sh | 6 ++++++ 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 scripts/docker-dbbackup.sh create mode 100644 scripts/host-dbbackup.bat create mode 100644 scripts/vagrant-dbbackup.sh diff --git a/compose-dev.yml b/compose-dev.yml index 9c0cb9a..4876b29 100644 --- a/compose-dev.yml +++ b/compose-dev.yml @@ -14,4 +14,7 @@ mysql: image: mysql:5.7 environment: - MYSQL_ROOT_PASSWORD=password - - MYSQL_DATABASE=wordpress \ No newline at end of file + - MYSQL_DATABASE=wordpress + volumes: + - /vagrant/data/:/docker-entrypoint-initdb.d + - /vagrant/scripts/:/scripts diff --git a/scripts/docker-dbbackup.sh b/scripts/docker-dbbackup.sh new file mode 100644 index 0000000..bbb3dc6 --- /dev/null +++ b/scripts/docker-dbbackup.sh @@ -0,0 +1,4 @@ +#!/bin/bash +echo "Running docker-dbackup.sh" +/usr/bin/mysqldump -u root -p"$MYSQL_ROOT_PASSWORD" "$MYSQL_DATABASE" > /docker-entrypoint-initdb.d/dbbackup.sql +echo "Finished docker-dbackup.sh" diff --git a/scripts/host-dbbackup.bat b/scripts/host-dbbackup.bat new file mode 100644 index 0000000..7a17565 --- /dev/null +++ b/scripts/host-dbbackup.bat @@ -0,0 +1 @@ +vagrant ssh -c "/vagrant/scripts/vagrant-dbbackup.sh" diff --git a/scripts/vagrant-dbbackup.sh b/scripts/vagrant-dbbackup.sh new file mode 100644 index 0000000..946bc17 --- /dev/null +++ b/scripts/vagrant-dbbackup.sh @@ -0,0 +1,6 @@ +#!/bin/bash +echo "Running vagrant-dbackup.sh" +ID="$(docker ps | grep mysql | awk -F ' ' '{print $1}')" +echo "mysql docker container is $ID" +docker exec -it $ID /scripts/docker-dbbackup.sh +echo "Finished vagrant-dbbackup.sh"