This commit is contained in:
foobar
2022-02-02 01:41:37 +01:00
parent 5e99f44eb7
commit ed016b8a6e
2 changed files with 9 additions and 5 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
logs/*
!logs/.gitkeep

View File

@@ -4,7 +4,7 @@
me="$(basename "$0")";
result=$(ps aux | grep -i "$me" | grep -v "grep" | wc -l)
echo "running: $result"
if [ "$result" -gt 3 ]
if [ "$result" -gt 2 ]
then
exit
fi
@@ -36,20 +36,22 @@ LOGFILE_PATH="${DIR_BACKUP_LOGS}/${LOGFILE_STATUS}"
# 1) backup seafile databases
docker exec -ti ${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
DATABASES=( $(docker exec -ti ${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
# loop databases and dump tables to sql files inside temporary docker backup folder
for i in "${DATABASES[@]:1}"
do
:
docker exec -ti ${DOCKER_SEAFILE_MYSQL} sh -c "mysqldump --single-transaction -h localhost -u ${MYSQL_USER} -p${MYSQL_PASSWORD} --opt ${i} > ${DOCKER_BACKUP_DIR_TIMESTAMP}/${i}.sql"
docker exec -i ${DOCKER_SEAFILE_MYSQL} sh -c "mysqldump --single-transaction -h localhost -u ${MYSQL_USER} -p${MYSQL_PASSWORD} --opt ${i} > ${DOCKER_BACKUP_DIR_TIMESTAMP}/${i}.sql"
done
# 2) copy backup database files to host and cleanup
docker cp ${DOCKER_SEAFILE_MYSQL}:${DOCKER_BACKUP_DIR_TIMESTAMP} ${DIR_BACKUP_DB}
docker exec -ti ${DOCKER_SEAFILE_MYSQL} sh -c "rm -r ${DOCKER_BACKUP_DIR}"
docker exec -i ${DOCKER_SEAFILE_MYSQL} sh -c "rm -r ${DOCKER_BACKUP_DIR}"
# 3) backup seafile docker volumes folder
rsync -azh --log-file "${LOGFILE_PATH}" ${DIR_VOLUMES} ${DIR_BACKUP}
echo "backup ${TIMESTAMP} done"