Skip to content
Snippets Groups Projects
Commit 8e464f7e authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

create missing subdir dbdumps

parent c73053eb
Branches
No related tags found
1 merge request!21create missing subdir dbdumps
This commit is part of merge request !21. Comments created here will be created in the context of that merge request.
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
# 2024-08-14 v1.18 <www.axel-hahn.de> update container view # 2024-08-14 v1.18 <www.axel-hahn.de> update container view
# 2024-09-20 v1.19 <www.axel-hahn.de> detect dockerd-rootless (hides menu item to set permissions) # 2024-09-20 v1.19 <www.axel-hahn.de> detect dockerd-rootless (hides menu item to set permissions)
# 2024-10-16 v1.20 <axel.hahn@unibe.ch> add db import and export # 2024-10-16 v1.20 <axel.hahn@unibe.ch> add db import and export
# 2024-10-25 v1.21 <axel.hahn@unibe.ch> create missing subdir dbdumps
# ====================================================================== # ======================================================================
cd "$( dirname "$0" )" || exit 1 cd "$( dirname "$0" )" || exit 1
...@@ -38,7 +39,7 @@ _self=$( basename "$0" ) ...@@ -38,7 +39,7 @@ _self=$( basename "$0" )
# shellcheck source=/dev/null # shellcheck source=/dev/null
. "${_self}.cfg" || exit 1 . "${_self}.cfg" || exit 1
_version="1.20" _version="1.21"
# git@git-repo.iml.unibe.ch:iml-open-source/docker-php-starterkit.git # git@git-repo.iml.unibe.ch:iml-open-source/docker-php-starterkit.git
selfgitrepo="docker-php-starterkit.git" selfgitrepo="docker-php-starterkit.git"
...@@ -64,6 +65,8 @@ DC_CONFIG_CHANGED=0 ...@@ -64,6 +65,8 @@ DC_CONFIG_CHANGED=0
DC_WEB_URL="" DC_WEB_URL=""
DC_DUMP_DIR=dbdumps
isDockerRootless=0 isDockerRootless=0
ps -ef | grep dockerd-rootless | grep -q $USER && isDockerRootless=1 ps -ef | grep dockerd-rootless | grep -q $USER && isDockerRootless=1
...@@ -100,6 +103,13 @@ function _getStatus_docker(){ ...@@ -100,6 +103,13 @@ function _getStatus_docker(){
DC_DB_UP=0 DC_DB_UP=0
grep -q "${APP_NAME}-server" <<< "$_out" && DC_WEB_UP=1 grep -q "${APP_NAME}-server" <<< "$_out" && DC_WEB_UP=1
grep -q "${APP_NAME}-db" <<< "$_out" && DC_DB_UP=1 grep -q "${APP_NAME}-db" <<< "$_out" && DC_DB_UP=1
if [ $DC_DB_UP -eq 1 ] && [ ! -d "${DC_DUMP_DIR}" ]; then
echo "INFO: creating subdir ${DC_DUMP_DIR} to import/ export databases ..."
mkdir "${DC_DUMP_DIR}" || exit 1
return
fi
} }
function _getWebUrl(){ function _getWebUrl(){
...@@ -164,7 +174,7 @@ function showMenu(){ ...@@ -164,7 +174,7 @@ function showMenu(){
if [ $DC_WEB_UP -eq 1 ] || [ $DC_DB_UP -eq 1 ] || [ $_bAll -eq 1 ]; then if [ $DC_WEB_UP -eq 1 ] || [ $DC_DB_UP -eq 1 ] || [ $_bAll -eq 1 ]; then
echo "${_spacer}$( _key s ) - shutdown containers docker-compose stop" echo "${_spacer}$( _key s ) - shutdown containers docker-compose stop"
echo echo
echo "${_spacer}$( _key i ) - Import more into infos" echo "${_spacer}$( _key m ) - more infos"
echo "${_spacer}$( _key o ) - open app [${APP_NAME}] $DC_WEB_URL" echo "${_spacer}$( _key o ) - open app [${APP_NAME}] $DC_WEB_URL"
echo "${_spacer}$( _key c ) - console (bash)" echo "${_spacer}$( _key c ) - console (bash)"
fi fi
...@@ -516,7 +526,7 @@ function _dbDump(){ ...@@ -516,7 +526,7 @@ function _dbDump(){
echo "Database container is not running. Aborting." echo "Database container is not running. Aborting."
return return
fi fi
outfile=dbdumps/${MYSQL_DB}_$( date +%Y%m%d_%H%M%S ).sql outfile=${DC_DUMP_DIR}/${MYSQL_DB}_$( date +%Y%m%d_%H%M%S ).sql
echo -n "dumping ${MYSQL_DB} ... " echo -n "dumping ${MYSQL_DB} ... "
if docker exec -i "${APP_NAME}-db" mysqldump -uroot -p${MYSQL_ROOT_PASS} ${MYSQL_DB} > "$outfile"; then if docker exec -i "${APP_NAME}-db" mysqldump -uroot -p${MYSQL_ROOT_PASS} ${MYSQL_DB} > "$outfile"; then
echo -n "OK ... Gzip ... " echo -n "OK ... Gzip ... "
...@@ -527,14 +537,14 @@ function _dbDump(){ ...@@ -527,14 +537,14 @@ function _dbDump(){
# CLEANUP # CLEANUP
echo echo
echo "--- Cleanup: keep $_iKeepDumps files." echo "--- Cleanup: keep $_iKeepDumps files."
ls -1t dbdumps/* | sed -n "$_iStart,\$p" | while read -r delfile ls -1t ${DC_DUMP_DIR}/* | sed -n "$_iStart,\$p" | while read -r delfile
do do
echo "CLEANUP: Deleting $delfile ... " echo "CLEANUP: Deleting $delfile ... "
rm -f "$delfile" rm -f "$delfile"
done done
echo echo
echo -n "Size of dump directory: " echo -n "Size of dump directory: "
du -hs dbdumps | awk '{ print $1 }' du -hs ${DC_DUMP_DIR} | awk '{ print $1 }'
else else
echo "ERROR" echo "ERROR"
...@@ -549,7 +559,7 @@ function _dbDump(){ ...@@ -549,7 +559,7 @@ function _dbDump(){
# DB TOOL - import local database dump into container # DB TOOL - import local database dump into container
function _dbImport(){ function _dbImport(){
echo "--- Available dumps:" echo "--- Available dumps:"
ls -ltr dbdumps/*.gz | sed "s#^# #g" ls -ltr ${DC_DUMP_DIR}/*.gz | sed "s#^# #g"
if [ $DC_DB_UP -eq 0 ]; then if [ $DC_DB_UP -eq 0 ]; then
echo "Database container is not running. Aborting." echo "Database container is not running. Aborting."
return return
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment