|
Several strategies exist for backing up MongoDB databases. A word of warning: it's not safe to back up the mongod data files (by default in /data/db/) while the database is running and writes are occurring; such a backup may turn out to be corrupt. See the fsync option below for a way around that. Fsync, Write Lock and BackupMongoDB v1.3.1 and higher supports an fsync and lock command with which we can flush writes, lock the database to prevent writing, and then backup the datafiles. While in this locked mode, all writes will block. If this is a problem consider one of the other methods below. For example, you could use LVM2 to create a snapshot after the fsync+lock, and then use that snapshot to do an offsite backup in the background. This means that the server will only be locked while the snapshot is taken. Don't forget to unlock after the backup/snapshot is taken. Shutdown and BackupA simple approach is just to stop the database, back up the data files, and resume. This is safe but of course requires downtime. ExportsThe mongodump utility may be used to dump an entire database, even when the database is running and active. The dump can then be restored later if needed. Slave BackupAnother good technique for backups is replication to a slave database. The slave polls master continuously and thus always has a nearly-up-to-date copy of master. We then have several options for backing up the slave:
For methods 1 and 2, after the backup the slave will resume replication, applying any changes made to master in the meantime. Using a slave is advantageous because we then always have backup database machine ready in case master fails (failover). But a slave also gives us the chance to back up the full data set without affecting the performance of the master database. Community Stuff |

PLEASE POST QUESTIONS IN THE USER GROUPS FORUM. Post non-question comments and helpful hints here.
blog comments powered by Disqus