From ed016b8a6e6c7d4ed659d51f16cfc552656f63b5 Mon Sep 17 00:00:00 2001 From: foobar Date: Wed, 2 Feb 2022 01:41:37 +0100 Subject: [PATCH] foo --- .gitignore | 2 ++ backup.sh | 12 +++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..88626db --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +logs/* +!logs/.gitkeep diff --git a/backup.sh b/backup.sh index e44844e..acc7e16 100644 --- a/backup.sh +++ b/backup.sh @@ -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"