foo
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
logs/*
|
||||||
|
!logs/.gitkeep
|
||||||
12
backup.sh
12
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 3 ]
|
if [ "$result" -gt 2 ]
|
||||||
then
|
then
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
@@ -36,20 +36,22 @@ LOGFILE_PATH="${DIR_BACKUP_LOGS}/${LOGFILE_STATUS}"
|
|||||||
|
|
||||||
|
|
||||||
# 1) backup seafile databases
|
# 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
|
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
|
# loop databases and dump tables to sql files inside temporary docker backup folder
|
||||||
for i in "${DATABASES[@]:1}"
|
for i in "${DATABASES[@]:1}"
|
||||||
do
|
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
|
done
|
||||||
|
|
||||||
# 2) copy backup database files to host and cleanup
|
# 2) copy backup database files to host and cleanup
|
||||||
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 -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
|
# 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}
|
||||||
|
|
||||||
|
echo "backup ${TIMESTAMP} done"
|
||||||
|
|||||||
Reference in New Issue
Block a user