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

Commit 2271eca

Browse files
committed
add restore script
1 parent 2785992 commit 2271eca

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,13 @@ 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+
31+
## Restore from a backup
32+
33+
See the list of backups, you can run:
34+
35+
docker exec tutum-backup ls /backup
36+
37+
To restore database from a certain backup, simply run:
38+
39+
docker exec tutum-backup /restore.sh /backup/2015.08.06.171901

run.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ BACKUP_CMD="mongodump --out /backup/"'$(date +\%Y.\%m.\%d.\%H\%M\%S)'" --host ${
2121

2222

2323
echo "=> Creating backup script"
24+
rm -f /backup.sh
2425
cat <<EOF >> /backup.sh
2526
#!/bin/bash
2627
MAX_BACKUPS=${MAX_BACKUPS}
@@ -39,6 +40,16 @@ echo "=> Backup done"
3940
EOF
4041
chmod +x /backup.sh
4142

43+
echo "=> Creating restore script"
44+
rm -f /restore.sh
45+
cat <<EOF >> /restore.sh
46+
#!/bin/bash
47+
echo "=> Restore database from \$1"
48+
mongorestore --host ${MONGODB_HOST} --port ${MONGODB_PORT} ${USER_STR}${PASS_STR} \$1
49+
echo "=> Done"
50+
EOF
51+
chmod +x /restore.sh
52+
4253
echo "${CRON_TIME} /backup.sh >> /mongo_backup.log 2>&1" > /crontab.conf
4354
echo "=> Adding cron job"
4455
crontab /crontab.conf

0 commit comments

Comments
 (0)