From 76712a2378c57e58dcf1df470887ce12568b9168 Mon Sep 17 00:00:00 2001 From: Mascaro Lucas Date: Mon, 14 May 2018 01:47:20 +0200 Subject: [PATCH] Implemented automatic backup of mariadb (every 24 hours) --- metactl/post-start.sh | 21 ++++++++++++++++++++- metactl/post-stop.sh | 5 ++++- virtual/vhost | 2 +- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/metactl/post-start.sh b/metactl/post-start.sh index f3a1576..91688eb 100644 --- a/metactl/post-start.sh +++ b/metactl/post-start.sh @@ -83,4 +83,23 @@ docker exec php-fpm bash -c "cd /vhost; composer install" >/dev/null 2>&1 && ech # 2. Re-build js/scss echo -n " * Webpack build............."; -docker exec php-fpm bash -c "cd /vhost; npm install; npm run build" >/dev/null 2>&1 && echo "built" || (echo "failed"; exit 1); \ No newline at end of file +docker exec php-fpm bash -c "cd /vhost; npm install; npm run build" >/dev/null 2>&1 && echo "built" || (echo "failed"; exit 1); + +# 3. touch the file the backup loop will use to run +echo -n " * Launch mariadb backup loop............."; + +backup(){ + if [ ! -d $ROOT/backups ]; then + mkdir $ROOT/backups; + fi + + touch $ROOT/backuploop + while [ -f $ROOT/backuploop ]; do + # sleep 24 hours before next backup kick in + sleep 86400; + docker exec $MARIADB_SERVICE mysqldump --all-databases --flush-privileges -uroot -p$MARIADB_ROOT_PASSWORD | gzip > $ROOT/backups/$(date -d "today" +"%Y%m%d%H%M").sql.gz; + done; +} + +backup &; +echo "done" diff --git a/metactl/post-stop.sh b/metactl/post-stop.sh index 22ba604..3d481bc 100644 --- a/metactl/post-stop.sh +++ b/metactl/post-stop.sh @@ -26,4 +26,7 @@ if [ -f $PID_FILE ]; then else echo "already"; fi; -rm $PID_FILE >/dev/null 2>&1; \ No newline at end of file +rm $PID_FILE >/dev/null 2>&1; + +echo -ne " * Kill backup loop............"; +rm $ROOT/backuploop && echo "killed" || (echo "fail"; exit 1); diff --git a/virtual/vhost b/virtual/vhost index 32da513..8f90982 160000 --- a/virtual/vhost +++ b/virtual/vhost @@ -1 +1 @@ -Subproject commit 32da5131b4c203bc0495f980a2d1cfc3ec15423c +Subproject commit 8f909821b6fea274722e0662d2863de2e1b0cd59