MongoDB Disaster Recovery Automation

1. Introduction:-

MongoDB Backups has been a grey area for Sage's BP's it is our intent in this Blog to illustrate a simple but very effective method for Automatically creating MongoDB Backups on a scheduled basis.

 These MongoDB backups will form a small part of the larger holistic Disaster Recovery that our Business Partners will deploy.

2. Basic review of Disaster Recovery

Disaster Recovery generally involves a set of policies, procedures, and hardware and software specific to DR, that enables the recovery of key infrastructure and systems following a disaster.

These disasters directly impact on the company’s operational processes.

Disaster recovery is done to support critical business functions and provides support for business continuity.

An ISO standard was published in 2011, ISO 27031. This standard replaced an older Business Continuity Standard BS 25999.

Recovery Time Objective

A Recovery Point Objective (RPO) forms part of business continuity planning. It is the maximum amount of time in which data like transactions being processed, may not be able to be processed or captured, like Sales Invoices, Purchase Orders ETC.

Recovery Time Objective

The Recovery Time Objective is the targeted amount of time a business process must be restored after a disaster has happened.

 The below diagram illustrates a disaster recovery process.

Recovery Time Actual

Recovery Time Actual or RTA is the Critical metric for business continuity and disaster recovery.

 3. Importance of holistic DR

A comprehensive Disaster Recovery plan is key to ensure Business Continuity in the eventuality Disaster Strikes, proper planning is key here.

 Antoine de Saint-Exupery was a French writer, poet, aristocrat, journalist, and pioneering aviator was quoted saying:-

A goal without a plan is just a wish

Backup sites, whether they are cold, warm, standby, or hot sites, should be included in the planning. Adequate hardware and software should support these sites and disaster recovery they will provide to ensure business continuity.

 4. MongoDB DR script

Backup Script starts defining a key parameter, also it’s the only parameter. This script will be adopted into a more Dynamic script in due course.

For now, though it works as it is. Simple and very effective.

The script may be started Automatically using the Windows Task Scheduler or Manually, it’s highly recommended to Automate the script.

REM +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
REM +- MongoDB Backup
REM +- Enter Drive letter (On which Drive MongoDB is installed)
REM +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
echo %1 REM %1 = Drive Letter

set Drive=%1
REM set MnCmpNm

REM +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
REM +- Stop the MongoDB Service and related services,
REM +- To ensure it starts-up correctly
REM +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

net stop "SafeX3MongoDB-NODE0"
net stop ElasticSearch_for_Syracuse_-_emv12trn-node-0
net stop Agent_Sage_Syracuse_-_NODE0

REM +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
REM +- $ Bak_MongoDB.bat C:
REM +- Create Temporary Directory where the MongoDB will be stored mm.dd.yyyy -> yyyy.mm.dd
REM +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

set FolderDate=%date:~10,4%.%date:~4,2%.%date:~7,2%
echo %FolderDate% is the folder date
pause
cd %Drive%\Sage\SafeX3\Backups\
mkdir %FolderDate%
dir
pause

REM +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
REM +- Copy the contents of the MongoDB source directory into the newly created
REM +- above directory.
REM +- Copy the files accross into temporary Directory. Create the below "Backups"
REM +- folder, inside the SafeX3 Directory.
REM +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Xcopy /c /s /y C:\Sage\MongoDB_for_Sage_EM\*.* c:\Sage\SafeX3\Backups\%FolderDate%\
cd c:\Sage\SafeX3\Backups\%FolderDate%\

REM +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
REM +- This Fires up 7-zip and will create a SRF of the Backup
REM +- Folder
REM +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

c:\"Program Files (X86)"\7-zip\7z.exe a -r -sfx c:\Sage\SafeX3\Backups\%FolderDate%.MongoDB_for_Sage_EM.exe *.*
pause

REM +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
REM +- Delete the source Directory from which the SRF of the Backup
REM +- Folder was created
REM +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
cd c:\Sage\SafeX3\Backups\
RMDIR /S /Q %FolderDate%

REM +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
REM +- Start the MongoDB Service and related services.
REM +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

net start SafeX3MongoDB-NODE0
net start ElasticSearch_for_Syracuse_-_emv12trn-node-0
net start Agent_Sage_Syracuse_-_NODE0

Prior to running the key elements of our script we have to Stop all the key MongoDB Services, the script takes care of this for us.

 Hereafter the name of our Backup Self Extracting File (SRF File) is created dynamically by using the System Date of the Server and combining that with the Name of the MongoDB Component.

  Next we copy the contents of our MongoDB Directory into the Backup Directory by using an Xcopy command:-

Xcopy /c /s /y C:\Sage\MongoDB_for_Sage_EM\*.* c:\Sage\SafeX3\Backups\%FolderDate%\ 

 7-zip is now kicked off via the command prompt and with some key parameters being passed to it to ensure our SRF File is created correctly.

c:\"Program Files (X86)"\7-zip\7z.exe a -r -sfx c:\Sage\SafeX3\Backups\%FolderDate%.MongoDB_for_Sage_EM.exe *.*

After completing the SRF File, 7-zip provides us with a report of whether our SRF File has been completed successfully.

The old contents of our temporary Backup directory is now deleted, as we no longer need this and it’s only taking up space now.

The Backup Directory is now replaced with our 7-zip SRF file, which may be used to restore MongoDB to a perfect Pre-Disaster State.

 5. Q&A

Nr

Question

1

How can we get this script?

Answer

For now just email me, I will email the script to you.

2

Can we get a script to do the same for Folders?

Answer

Yes you can.

3

Can we restore onto another server especially when u migrate your folders and u have to recreate all your user at the Administration

Answer

Yes you can, provided that the Server Name and environment is identical to the source environment where the MongoDB Backup was created.

4

Will the recording of this webinar be made available please?

Answer

Yes, it is available

 6. Conclusion

MongoDB Backups forms part of the key Backup Plans that every Business should have in place alongside their normal MS-SQL / Oracle Database Backups.

The MongoDB Automation backup is a great way to ensure that the X3 Business System is also covered should disaster strike. It’s a quick and easy way to restore MongoDB within a very quick time.

Anonymous