Skip to content
This repository was archived by the owner on Nov 29, 2020. It is now read-only.

Commit b3114d8

Browse files
committed
Add INIT_BACKUP to backup when the container is started
1 parent 2271eca commit b3114d8

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Moreover, if you link `tutum/mongodb-backup` to a mongodb container(e.g. `tutum/
2727
EXTRA_OPTS the extra options to pass to mongodump command
2828
CRON_TIME the interval of cron job to run mongodump. `0 0 * * *` by default, which is every day at 00:00
2929
MAX_BACKUPS the number of backups to keep. When reaching the limit, the old backup will be discarded. No limit, by default
30+
INIT_BACKUP if set, create a backup when the container launched
3031

3132
## Restore from a backup
3233

run.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ cat <<EOF >> /backup.sh
2626
#!/bin/bash
2727
MAX_BACKUPS=${MAX_BACKUPS}
2828
29-
echo "=> Starting backup"
29+
echo "=> Backup started"
3030
if [ -n "\${MAX_BACKUPS}" ]; then
3131
while [ \$(ls /backup -N1 | wc -l) -ge \${MAX_BACKUPS} ];
3232
do
@@ -50,11 +50,16 @@ echo "=> Done"
5050
EOF
5151
chmod +x /restore.sh
5252

53+
touch /mongo_backup.log
54+
tail -F /mongo_backup.log &
55+
56+
if [ -n "${INIT_BACKUP}" ]; then
57+
echo "=> Create a backup on start the container"
58+
/backup.sh
59+
fi
60+
5361
echo "${CRON_TIME} /backup.sh >> /mongo_backup.log 2>&1" > /crontab.conf
54-
echo "=> Adding cron job"
5562
crontab /crontab.conf
5663
crontab -l
57-
touch /mongo_backup.log
58-
tail -F /mongo_backup.log &
5964
echo "=> Running cron job"
6065
exec cron -f

0 commit comments

Comments
 (0)