Compare commits
5 Commits
6454a01c2e
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
690c68ba45 | ||
|
|
40f842e69f | ||
|
|
c7449536d6 | ||
|
|
ed016b8a6e | ||
|
|
5e99f44eb7 |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
logs/*
|
||||||
|
!logs/.gitkeep
|
||||||
39
backup.sh
39
backup.sh
@@ -15,9 +15,10 @@ DIR_BACKUP=/mnt/NASbarracuda1TB/backup/keese/seafile # where to store the backup
|
|||||||
|
|
||||||
# mysql credentials to access databases inside seafile-mysql docker
|
# mysql credentials to access databases inside seafile-mysql docker
|
||||||
MYSQL_USER=root
|
MYSQL_USER=root
|
||||||
MYSQL_PASSWORD=mysqlrootpasswd
|
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
|
||||||
|
|
||||||
|
|
||||||
@@ -34,22 +35,34 @@ DIR_BACKUP_LOGS=${DIR_BACKUP}/logs
|
|||||||
LOGFILE_STATUS="${TIMESTAMP}_rsync_status.log"
|
LOGFILE_STATUS="${TIMESTAMP}_rsync_status.log"
|
||||||
LOGFILE_PATH="${DIR_BACKUP_LOGS}/${LOGFILE_STATUS}"
|
LOGFILE_PATH="${DIR_BACKUP_LOGS}/${LOGFILE_STATUS}"
|
||||||
|
|
||||||
|
# create dirs that are not created automatically
|
||||||
|
mkdir -p ${DIR_BACKUP_LOGS} ${DIR_BACKUP_DB}
|
||||||
|
|
||||||
# 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
|
|
||||||
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
|
|
||||||
|
|
||||||
# loop databases and dump tables to sql files inside temporary docker backup folder
|
if [ "$( docker container inspect -f '{{.State.Status}}' ${DOCKER_SEAFILE} )" == "running" ]; then
|
||||||
for i in "${DATABASES[@]:1}"
|
echo "docker ${DOCKER_SEAFILE} running"
|
||||||
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"
|
|
||||||
done
|
|
||||||
|
|
||||||
# 2) copy backup database files to host and cleanup
|
docker exec -i ${DOCKER_SEAFILE_MYSQL} sh -c "mkdir -p ${DOCKER_BACKUP_DIR_TIMESTAMP}" # create remporary backup dir inside docker
|
||||||
docker cp ${DOCKER_SEAFILE_MYSQL}:${DOCKER_BACKUP_DIR_TIMESTAMP} ${DIR_BACKUP_DB}
|
IFS=$'\n\r' # set the IFS to a newline character, so that a whole line can be assigned to an array element
|
||||||
docker exec -ti ${DOCKER_SEAFILE_MYSQL} sh -c "rm -r ${DOCKER_BACKUP_DIR}"
|
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 -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 -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}
|
||||||
|
|
||||||
|
echo "backup ${TIMESTAMP} done"
|
||||||
|
|||||||
0
logs/.gitkeep
Normal file
0
logs/.gitkeep
Normal file
Reference in New Issue
Block a user