Tayra Documentation

You could possibly be in one of the below scenarios. Choose the best applicable to you.

Scenario 1

Taking backup from a fresh replica set (containing no data) and restoring to a fresh Mongo.

Mechanics

Backup: Start backup utility on primary in tailable mode using the command:
backup -s localhost --port=27017 -f backup.log -t
The tool tails the primary oplog and backs up documents as operations are performed on primary. Should backup be aborted (using 'Ctrl + C'), the timestamp of last backed-up document is recorded and when backup resumes, it starts recording new documents.
Restore: Start restore utility on the target to replay the backup using:
restore -d localhost --port=27020 -f backup.log
The tool will replay the documents from the backup file "backup.log" into the target mongo.

Caveat: In case the backup is aborted, in order to prevent loss of data due to oplog falling off make sure that it is restarted in time. For sustained backups and restore, you may want to look at scenario 3.

Scenario 2

Taking backup from an existing replica set (having some data) and restoring to a fresh Mongo. For seeding purpose, take snapshot of the database using fsyncLock / fsyncUnlock.

Mechanics

Taking Snapshot: Take a snapshot of primary into the file system using:
  1. db.fysncLock() on the source mongo
  2. archive the dbpath files and
  3. db.fsyncUnlock() the source
Backup: Start backup utility on primary in tailable mode using:
backup -s localhost --port=27017 -f backup.log -t
The tool will catch up with the primary oplog and tail it to backup documents as operations are performed.
Seeding: Start the target mongod with archived files in its dbpath using:
mongod --port 27021 --dbpath "location of archive/snapshot"
The target mongo will be started in a consistent state.
Restore: Start restore utility on the target to replay the backup using:
restore -d "localhost" --port=27021 -f backup.log
The tool will replay the documents from the backup file "backup.log" into the target mongo.
Note: Alternatively, seeding can also be done by using
mongodump
and
mongorestore
utility. For sustained backups and restore, you may want to look at scenario 3.

Scenario 3

Sustaining periodic backups and restore.

Mechanics

Backup: Start backup utility on primary in tailable mode using the command:
backup -s localhost --port=27017 -f backup.log -t --fMax=4 --fSize=1MB
The tool will refer to "timestamp.out" and resume backup from the last backed up document in oplog. It will back up a total of 4MB data into 4 files in the above case.
Archive: The files generated are-
'backup.log', 'backup.log.1', 'backup.log.2', 'backup.log.3' and 'backup.log.4'.
As soon as backup.log.4 is created, move all 4 files (except backup.log - which is the running backup file) to a separate directory for consumption by restore utility.
Restore: Start restore utility to replay from the backup across multiple files:
restore -d localhost --port=27017 -f backup.log -fAll
The tool will replay all the documents.
Caveat: While taking backup using rotating files, make sure older files are restored before being rolled over.

Should you wish to perform selective backup and restore, or perform analysis prior to restoring, please find the details in the line items below.

Table Of Contents

1 Selective Backup With Complete Restore

2 Restore To Point In Time

3 Complete Backup With Selective Restore

4 C U D Operations

5 Analyze Data To Restore Using Dry Run