Link to home
Start Free TrialLog in
Avatar of rakkad
rakkadFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Backup MongoDB databases

Assistance in backing up MongoDB databases:-

I am new to MongoDB and need some assistance in backing up databases by writing a script:-

a) Backup MongoDB at 00:01 kept for 7 days and are removed.  
b) An e-mail notification is sent to state that backups are completed or failed.
c) Is there a way to backup MongoDB i.e. transaction log backups or similar method, so 'point-in-time' restores can be done
Avatar of noci
noci

a), b)
Save the next as script
and add a call to that script in cron.  (I assume a unix/linux system)
Cron will also send a mail if anything is written to stdout/stderr...


cd /data/backups/
rm -rf mongo.backup.7
mv mongo.backup.6 mongo.backup.7
mv mongo.backup.5 mongo.backup.6
mv mongo.backup.4 mongo.backup.5
mv mongo.backup.3 mongo.backup.4
mv mongo.backup.2 mongo.backup.3
mv mongo.backup.1 mongo.backup.2
mv mongo.backup mongo.backup.1
mkdir mondig.backup
mongodump ..... -o mongo.backup

Open in new window


c)   use --oplog as one of the options to mongodump

Please readup on mongodump's capabilities.
Avatar of rakkad

ASKER

Thanks for getting back to me.  Can you show me examples using oplog ?
ehm...
mongodump --oplog --host localhost --out /db-backup/mongo.backup

Open in new window

Be sure to use all required ssl option if using athis to backup a non localhost database.
...

Check man mongodump for details.

For reastore you need mongorestore --oplogReplay .
Check man mongorestore for that.
Avatar of rakkad

ASKER

Thanks.  So, what would a typically process be from backing a full database and using oplog and then process in restoring the database and using point in time restore.  Can you show me examples of using both mongodump and mongorestore processes

Thanks
Let me point you to the official manual... tutorial:    https://docs.mongodb.com/manual/tutorial/backup-and-restore-tools/
Avatar of rakkad

ASKER

I was hoping you could provide an example of using mongodump and oplog together and process in restoring the dbs ?

Thanks
Avatar of rakkad

ASKER

Hi Can you provide examples ?

Thanks
What would be the difference between an example from me and an example from an authorized source?
Addinf --oplog will not only make a backup but also of al changes DURING the backup. Making it a consistent set.

The restore needs to know the --oplog restore is needed. .... So take your current backup/dump and add --oplog to the line.
If you have no current backup then you need to know what you want/need to backup and what options are available (=manual),
and then make a selection that can work for you.

Then test, test and also test (=practice) a restore.
This will also tell you how long backups take to actually make  and how long restores will take.  (at the moment).
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.