From 0d580f3688524938caa937b90d1ac83cdec4b7a9 Mon Sep 17 00:00:00 2001 From: Tobias Wittwer Date: Wed, 9 Nov 2016 17:40:13 +0100 Subject: [PATCH 1/5] Add option for initial restore of database --- run.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/run.sh b/run.sh index 2643cb0..6a69ef7 100755 --- a/run.sh +++ b/run.sh @@ -59,6 +59,17 @@ chmod +x /restore.sh touch /mongo_backup.log tail -F /mongo_backup.log & +if [ -n "${INIT_RESTORE}" ]; then + echo "=> Restore on the startup" + echo "TEST" + echo $(ls backup/ -1 | sort -r | head -1) + latest_backup=$(ls backup/ -1 | sort -r | head -1) + if [ -n "$latest_backup" ]; then + echo $latest_backup + /restore.sh /backup/$latest_backup/${MONGODB_DB} + fi +fi + if [ -n "${INIT_BACKUP}" ]; then echo "=> Create a backup on the startup" /backup.sh From 102ce78419c889a4d3beac343cf869b1ee66d262 Mon Sep 17 00:00:00 2001 From: Tobias Wittwer Date: Thu, 10 Nov 2016 20:25:38 +0100 Subject: [PATCH 2/5] [TASK] Adjust README for new environment variable --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ed3fdb1..42aecda 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Moreover, if you link `tutum/mongodb-backup` to a mongodb container(e.g. `tutum/ EXTRA_OPTS the extra options to pass to mongodump command CRON_TIME the interval of cron job to run mongodump. `0 0 * * *` by default, which is every day at 00:00 MAX_BACKUPS the number of backups to keep. When reaching the limit, the old backup will be discarded. No limit, by default + INIT_RESTORE if set, restore latest backup when the container launched (before initial backup) INIT_BACKUP if set, create a backup when the container launched ## Restore from a backup From 9000d29c961fffb312e88a41982018231643c36d Mon Sep 17 00:00:00 2001 From: Tobias Wittwer Date: Thu, 10 Nov 2016 20:27:40 +0100 Subject: [PATCH 3/5] [BUGFIX] Fix DB_STR declaration --- run.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/run.sh b/run.sh index 6a69ef7..da5001d 100755 --- a/run.sh +++ b/run.sh @@ -11,7 +11,7 @@ MONGODB_PASS=${MONGODB_PASS:-${MONGODB_ENV_MONGODB_PASS}} [[ ( -n "${MONGODB_USER}" ) ]] && USER_STR=" --username ${MONGODB_USER}" [[ ( -n "${MONGODB_PASS}" ) ]] && PASS_STR=" --password ${MONGODB_PASS}" -[[ ( -n "${MONGODB_DB}" ) ]] && USER_STR=" --db ${MONGODB_DB}" +[[ ( -n "${MONGODB_DB}" ) ]] && DB_STR=" --db ${MONGODB_DB}" BACKUP_CMD="mongodump --out /backup/"'${BACKUP_NAME}'" --host ${MONGODB_HOST} --port ${MONGODB_PORT} ${USER_STR}${PASS_STR}${DB_STR} ${EXTRA_OPTS}" @@ -61,7 +61,6 @@ tail -F /mongo_backup.log & if [ -n "${INIT_RESTORE}" ]; then echo "=> Restore on the startup" - echo "TEST" echo $(ls backup/ -1 | sort -r | head -1) latest_backup=$(ls backup/ -1 | sort -r | head -1) if [ -n "$latest_backup" ]; then From e8266f62e12946883612eab3e4dad2126b405c65 Mon Sep 17 00:00:00 2001 From: Tobias Wittwer Date: Thu, 10 Nov 2016 21:49:40 +0100 Subject: [PATCH 4/5] [CLEANUP] Cleanup debug messages in init_restore code --- run.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/run.sh b/run.sh index da5001d..e317048 100755 --- a/run.sh +++ b/run.sh @@ -61,10 +61,8 @@ tail -F /mongo_backup.log & if [ -n "${INIT_RESTORE}" ]; then echo "=> Restore on the startup" - echo $(ls backup/ -1 | sort -r | head -1) - latest_backup=$(ls backup/ -1 | sort -r | head -1) + latest_backup=$(ls /backup/ -1 | sort -r | head -1) if [ -n "$latest_backup" ]; then - echo $latest_backup /restore.sh /backup/$latest_backup/${MONGODB_DB} fi fi From 0eadbfc152965893c87ef1459c6eb4cb2eb57323 Mon Sep 17 00:00:00 2001 From: Tobias Wittwer Date: Thu, 10 Nov 2016 21:50:32 +0100 Subject: [PATCH 5/5] [BUGFIX] Add DB_STR to restore command --- run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.sh b/run.sh index e317048..372971b 100755 --- a/run.sh +++ b/run.sh @@ -47,7 +47,7 @@ rm -f /restore.sh cat <> /restore.sh #!/bin/bash echo "=> Restore database from \$1" -if mongorestore --host ${MONGODB_HOST} --port ${MONGODB_PORT} ${USER_STR}${PASS_STR} \$1; then +if mongorestore --host ${MONGODB_HOST} --port ${MONGODB_PORT} ${USER_STR}${PASS_STR}${DB_STR} \$1; then echo " Restore succeeded" else echo " Restore failed"