Its been quite a year, 2020, but it isn’t over yet with a few days remaining. Developers and technologists have advanced themselves by making fascinating products, enhancing their features and sometimes facing critical issues regarding data loss. With an aim to achieve the best performance and scalability, they have started to use in-memory distributed caching system.
NCache, an in-memory distributed cache, gave these developers the opportunity to gear up their businesses and move to a new world of in-memory data distributed caching. But a cache is a temporary store and the data centers in multiple locations might have data loss due to any natural disaster. So how do we save that temporary data in the cache?
Therefore, it became important in certain circumstances to provide features that will allow to backup and then restore the cached data anytime. In this blog, I will be discussing about NCache provided feature of backup and restore.
Cache Backup and Restore: The Need
Sometimes unexpected events can occur at any time. Let’s suppose a developer runs an online e-commerce website. There are multiple users using that website for buying variety of products including you. Assuming that you selected some products and added them in your cart, suddenly the website goes down. What happens next? The activity you were doing just finishes off.
Also, the developer’s data stored for all the users just got wiped out. Now what should the developer do? He does not have a backup so he cannot restore anything back.
This all may sound dramatic but in reality, it might happen. Such a situation could occur to any ongoing business in the world. Maybe a developer was inattentive and executed such an operation which erased the data on the cache. Therefore, certain timeframes may depict human error or application failure and stored data on cache might be vanished.
Saving Data with NCache Backup
So, to solve this problem, NCache has provided its users with the feature of creating a backup of their cached data. This will allow the users to make a copy of their entire data so that in case of any disaster or human error the data does not need to suffer.
NCache makes a backup of user specified cached data at another specified file path and simultaneously that data is already present in the cache. As a result of this, the user needs not to worry about data loss and can keep on performing operations.
Restoring Data in NCache
Next, after the talk about backing up your data with NCache, let’s look at the scenario of restoring that copy of data from its specified place.
NCache, at one end provides its users with data backup, and at the other end, also allows them to safely recover their specified cached data back to the cache cluster from its saved location. This enhances the vision of a user where they ponder that no matter what the circumstances be, their backup cached data is ready to be recovered anytime.
How to Backup Cache Data to a Specified Path
NCache uses the PowerShell cmdlet to provide the user with the facility to backup data. During this, the user can cache the contents (data) of the cache to any specified path along with a path of dependent assemblies.
The PowerShell cmdlet used for this purpose is Export -CacheData as seen below:
1 | Export -CacheData [-Name] [-AssemblyPath] [-Logo] [-Password] [-Path] [-Port] [-UserId] |
Example: The following command backs up all the cached items to a specified path:
1 | Export -CacheData -Name myPartitionedCache -AssemblyPath C:\assembly-folder -Path C:\recovery-path |
Example: The user can also specify the maximum file size along with other attributes but the default file size is 5 MB’s. An example has been given below:
1 | Export -CacheData -Name myPartitionedCache -AssemblyPath C:\assembly-folder -Path C:\recovery-path -FileSize 2 |
Some of the important parameters for cmdlet are explained below:
- Name: Specifies the name of the cache which is to be backed up or restored.
- Path: Specifies the path where the backup data is currently present.
- AssemblyPath: Specifies the path where the dependent assemblies reside.
- UserId: Specifies the User Id used to authorize a user if security is enabled on cache server.
- Password: Specifies the password against the User Id.
How to Restore Data to Cache from a Specified Path
Similarly, to provide the user with the ability to restore data all the way back to the cache including all the dependent assembly files, NCache uses the PowerShell cmdlet Import -CacheData. This allows the user to import the cached data that resides on a specific path back to cache.
The PowerShell cmdlet used for this purpose is:
1 | Import -CacheData [-Name] [-AssemblyPath] [-BulkSize] [-ErrorThreshold] [-Expiry] [-NoLogo] [-Password] [-Path] [-UserId] |
Example: The following command recovers the data from the specified file path to the cache:
1 | Import -CacheData -Name myPartitionedCache -AssemblyPath C:\assembly-folder -Path C:\backup-path |
Example: The following command recovers the data from the specified path to the cache including the dependent assembly files and a tolerance of maximum 10 errors:
1 | Import -CacheData -Name myPartitionedCache -AssemblyPath C:\assembly-folder -Path C:\backup-path -ErrorThreshold 10 |
Example: The following command recovers the data from the specified path to the cache including the dependent assembly files in a bulk of 100 along with the display of logo banner to be suppressed.
1 | Import -CacheData -Name myPartitionedCache -AssemblyPath C:\assembly-folder -Path C:\backup-path -BulkSize 100 -NoLogo |
Some important cmdlet parameters are explained below:
- Name: Specifies the name of the cache which is to be backed up or restored.
- Path: Specifies the path where the backup data is currently present.
- AssemblyPath: Specifies the path where the dependent assemblies reside.
- ErrorThreshold: Specifies the number of errors that can be tolerated during recovering files from backup.
- Expiry: Sets the expiration policy of the data
Summarizing Our Blog at the End…
After reading the blog, what did you learn? Do you want to experience that sinking feeling in your stomach when you realize that you have just lost your valuable data? Or do you want to use NCache Backup and Restore feature to avoid that feeling?
The answer is NCache because it is the best available option along with many features including backup and restore.