Skip to content
Snippets Groups Projects
Commit 7e756a55 authored by Antoine Barbare's avatar Antoine Barbare
Browse files

Modify mongo script to compress result and be

compliant with backup rotation
parent 740fb7dc
No related branches found
No related tags found
No related merge requests found
...@@ -9,10 +9,10 @@ BACKUP_FOLDER=${BACKUP_FOLDER:-"/backup/"} ...@@ -9,10 +9,10 @@ BACKUP_FOLDER=${BACKUP_FOLDER:-"/backup/"}
if [[ -z "${MONGO_USER}" && -z "${MONGO_PASS}" ]]; then if [[ -z "${MONGO_USER}" && -z "${MONGO_PASS}" ]]; then
BACKUP_CMD="mongodump -d ${MONGO_DB} -h ${MONGO_HOST}:${MONGO_PORT} -o $BACKUP_FOLDER"'${BACKUP_NAME}' BACKUP_CMD="mongodump -d ${MONGO_DB} -h ${MONGO_HOST}:${MONGO_PORT} -o $BACKUP_FOLDER"'${BACKUP_NAME}'
RESTORE_CMD="mongorestore -d ${MONGO_DB} -h ${MONGO_HOST}:${MONGO_PORT} $BACKUP_FOLDER"'${BACKUP_NAME}' RESTORE_CMD="mongorestore -d ${MONGO_DB} -h ${MONGO_HOST}:${MONGO_PORT} "
else else
BACKUP_CMD="mongodump -d ${MONGO_DB} -h ${MONGO_HOST}:${MONGO_PORT} -u ${MONGO_USER} -p ${MONGO_PASS} -o $BACKUP_FOLDER"'${BACKUP_NAME}' BACKUP_CMD="mongodump -d ${MONGO_DB} -h ${MONGO_HOST}:${MONGO_PORT} -u ${MONGO_USER} -p ${MONGO_PASS} -o $BACKUP_FOLDER"'${BACKUP_NAME}'
RESTORE_CMD="mongorestore -d ${MONGO_DB} -h ${MONGO_HOST}:${MONGO_PORT} -u ${MONGO_USER} -p ${MONGO_PASS} $BACKUP_FOLDER"'${BACKUP_NAME}' RESTORE_CMD="mongorestore -d ${MONGO_DB} -h ${MONGO_HOST}:${MONGO_PORT} -u ${MONGO_USER} -p ${MONGO_PASS} "
fi fi
########################## ##########################
...@@ -30,6 +30,10 @@ BACKUP_NAME=\$(date +\%Y.\%m.\%d.\%H\%M\%S) ...@@ -30,6 +30,10 @@ BACKUP_NAME=\$(date +\%Y.\%m.\%d.\%H\%M\%S)
echo "=> ${MONGO_SERVICE_NAME}: Backup started: \${BACKUP_NAME}" echo "=> ${MONGO_SERVICE_NAME}: Backup started: \${BACKUP_NAME}"
if ${BACKUP_CMD} ;then if ${BACKUP_CMD} ;then
MONGO_BACKUP=$BACKUP_FOLDER\${BACKUP_NAME}
echo " => Compress files \$MONGO_BACKUP.tar.gz"
tar -czvf \$MONGO_BACKUP.tar.gz \$MONGO_BACKUP && \
rm -rf \$MONGO_BACKUP && \
echo "${MONGO_SERVICE_NAME}: Backup succeeded" echo "${MONGO_SERVICE_NAME}: Backup succeeded"
else else
echo "${MONGO_SERVICE_NAME}: Backup failed" echo "${MONGO_SERVICE_NAME}: Backup failed"
...@@ -51,11 +55,15 @@ cat <<EOF >> /$restore_script_name ...@@ -51,11 +55,15 @@ cat <<EOF >> /$restore_script_name
#!/bin/bash #!/bin/bash
echo "=> ${MONGO_SERVICE_NAME}: Restore database from \$1" echo "=> ${MONGO_SERVICE_NAME}: Restore database from \$1"
if ${RESTORE_CMD} ;then echo " => Uncompress save \$1"
echo "${MONGO_SERVICE_NAME}: Restore succeeded" tar -xzvf \$1
output="\$(echo \$1 | awk -F'.tar.gz' '{print \$1}')"
if mongorestore -d wekan -h wekan-db2:27017 \$output;then
echo "wekan: Restore succeeded"
else else
echo "${MONGO_SERVICE_NAME}: Restore failed" echo "wekan: Restore failed"
fi fi
rm -Rf \$output
EOF EOF
chmod +x /$restore_script_name chmod +x /$restore_script_name
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment