2

I have configured mongodb replica set (I have 3 db instances -Redhat) and I would like to take a backup of db file ( dbPath: /var/lib/mongo) using rsync, 10 or 12 times per day.

  1. So, do I need to stop the mongod process before start rsync?

    • select one of the server of replica set and stop the mongod process
    • take the backup (using rsync)
    • start the mongod process
  2. or else, can I start rsync (dbPath: /var/lib/mongo) without stopping the mongod process.

  3. what is the recommended backup method other than LVM backup and mongodump?

4

So, do I need to stop the mongod process before start rsync?

To take a file copy backup with rsync or cp you need to quiesce writes by stopping the mongod service or issuing the db.fsyncLock() command in the mongo shell or via a driver. Since the secondary you are backing up from will be intermittently available with this approach, it would be best to make it hidden to avoid drivers trying to read from this member when it is down or fsyncLock'd.

I would make sure you test several full backup and restore cycles. In particular, be wary of rsync options that might invalidate backups (for example: --ignore-existing, --size-only, --partial).

Note: if you are using the fsyncLock() approach there is a db.fsyncUnLock() command to restore normal operation after your backup completes. Another caveat: the WiredTiger storage engine only supports fsyncLock in MongoDB 3.2 or newer.

can I start rsync (dbPath: /var/lib/mongo) without stopping the mongod process.

No. This will result in an inconsistent backup.

what is the recommended backup method other than LVM backup and mongodump?

Supported backup approaches are described in the documentation: MongoDB Backup Methods.

There are less disruptive (and more continuous) backup approaches such as using an agent-based backup service (for example, MongoDB Cloud Manager).

If you want to backup by copying underlying data files, filesystem snapshots (LVM/EBS/...) are generally less disruptive and more recommendable than pausing all writes to a mongod. Filesystem snapshots against a running mongod do have some requirements if you want to capture a consistent backup: all data must be on the same volume, journaling must be enabled, and the filesystem must support point-in-time snapshots. For full details, check out the official documentation and backup tutorials.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.