Creating MongoDB Full Backup
The entire data in the MongoDB repository can be cloned and copied to another location and then used as a backup. Using Lua, this process can be carried out in AspenTech Inmation using an object that can execute Lua scripts.
The Lua functionality is provided by an internal Lua library called syslib.Backup.
backup:MONGODB()
The backup:MONGODB() function stops the MongoDB service and makes a copy of the data to a valid path destination. After the copy is complete, it restarts the MongoDB service.
|
Cloning the MongoDB can be a long process and it is difficult to predict how long the process will take. Therefore, it is sensible to execute the Mongo Backup functionality in Lua from an object (ActionItem or GenItem) rather than the console display. This way the object can be allocated a dedicated thread to complete the cloning process without affecting other running processes. |
Arguments
The arguments that must be provided for the function are:
-
service_name - the name of the MongoDB service (as displayed in Windows services)
-
source - the path location of the source MongoDB data store (using \\ notation for the path)
-
destination - valid path to a destination directory (using \\ notation for the path)
Returns
The function will return "0" and error message "(err_code: 0) backup successful" if the entire cloning was successful. If the process was not completed successfully then "nil" plus an error message including the error code will be returned.
Possible errors are:
-
stopping service failed
-
source folder doesn’t exist
-
could not delete old files
-
copying files failed
-
starting service failed
This will help you find the source of any problems.
Example
local backup = require('syslib.Backup') (1)
local a,b = backup:MONGODB("MongoDB", "C:\\MongoDB\\Server\\7.0\\data", "C:\\del\\backup\\new") (2)
return tostring(a) .. " : " .. tostring(b) (3)
| 1 | - making the syslib.backup library available for the script |
| 2 | - calling the function with service_name, source and destination and receiving returned values |
| 3 | - returning the values returned by the MONGODB() function to the object hosting the script |
|
The MONGODB function is called using the Lua “:” notation. |