check if container is running
This commit is contained in:
11
backup.sh
11
backup.sh
@@ -4,7 +4,7 @@
|
|||||||
me="$(basename "$0")";
|
me="$(basename "$0")";
|
||||||
result=$(ps aux | grep -i "$me" | grep -v "grep" | wc -l)
|
result=$(ps aux | grep -i "$me" | grep -v "grep" | wc -l)
|
||||||
echo "running: $result"
|
echo "running: $result"
|
||||||
if [ "$result" -gt 2 ]
|
if [ "$result" -gt 3 ]
|
||||||
then
|
then
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
@@ -18,6 +18,7 @@ MYSQL_USER=root
|
|||||||
MYSQL_PASSWORD='BV$9V#5Bq!enW&ez'
|
MYSQL_PASSWORD='BV$9V#5Bq!enW&ez'
|
||||||
|
|
||||||
# specify seafile-mysql docker name and temporary backup location inside the docker
|
# specify seafile-mysql docker name and temporary backup location inside the docker
|
||||||
|
DOCKER_SEAFILE=seafile
|
||||||
DOCKER_SEAFILE_MYSQL=seafile-mysql
|
DOCKER_SEAFILE_MYSQL=seafile-mysql
|
||||||
|
|
||||||
|
|
||||||
@@ -38,6 +39,10 @@ LOGFILE_PATH="${DIR_BACKUP_LOGS}/${LOGFILE_STATUS}"
|
|||||||
mkdir -p ${DIR_BACKUP_LOGS} ${DIR_BACKUP_DB}
|
mkdir -p ${DIR_BACKUP_LOGS} ${DIR_BACKUP_DB}
|
||||||
|
|
||||||
# 1) backup seafile databases
|
# 1) backup seafile databases
|
||||||
|
|
||||||
|
if [ "$( docker container inspect -f '{{.State.Status}}' ${DOCKER_SEAFILE} )" == "running" ]; then
|
||||||
|
echo "docker ${DOCKER_SEAFILE} running"
|
||||||
|
|
||||||
docker exec -i ${DOCKER_SEAFILE_MYSQL} sh -c "mkdir -p ${DOCKER_BACKUP_DIR_TIMESTAMP}" # create remporary backup dir inside docker
|
docker exec -i ${DOCKER_SEAFILE_MYSQL} sh -c "mkdir -p ${DOCKER_BACKUP_DIR_TIMESTAMP}" # create remporary backup dir inside docker
|
||||||
IFS=$'\n\r' # set the IFS to a newline character, so that a whole line can be assigned to an array element
|
IFS=$'\n\r' # set the IFS to a newline character, so that a whole line can be assigned to an array element
|
||||||
DATABASES=( $(docker exec -i ${DOCKER_SEAFILE_MYSQL} sh -c "mysql -e 'show databases' -s --skip-column-names -u ${MYSQL_USER} -p'${MYSQL_PASSWORD}'") ) # parse database names into array
|
DATABASES=( $(docker exec -i ${DOCKER_SEAFILE_MYSQL} sh -c "mysql -e 'show databases' -s --skip-column-names -u ${MYSQL_USER} -p'${MYSQL_PASSWORD}'") ) # parse database names into array
|
||||||
@@ -53,6 +58,10 @@ done
|
|||||||
docker cp ${DOCKER_SEAFILE_MYSQL}:${DOCKER_BACKUP_DIR_TIMESTAMP} ${DIR_BACKUP_DB}
|
docker cp ${DOCKER_SEAFILE_MYSQL}:${DOCKER_BACKUP_DIR_TIMESTAMP} ${DIR_BACKUP_DB}
|
||||||
docker exec -i ${DOCKER_SEAFILE_MYSQL} sh -c "rm -r ${DOCKER_BACKUP_DIR}"
|
docker exec -i ${DOCKER_SEAFILE_MYSQL} sh -c "rm -r ${DOCKER_BACKUP_DIR}"
|
||||||
|
|
||||||
|
else
|
||||||
|
echo "docker ${DOCKER_SEAFILE} NOT running"
|
||||||
|
fi
|
||||||
|
|
||||||
# 3) backup seafile docker volumes folder
|
# 3) backup seafile docker volumes folder
|
||||||
rsync -azh --log-file "${LOGFILE_PATH}" ${DIR_VOLUMES} ${DIR_BACKUP}
|
rsync -azh --log-file "${LOGFILE_PATH}" ${DIR_VOLUMES} ${DIR_BACKUP}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user