Import/Export Cache Data
NCache provides users with the ability to backup cache data for later use. To create the backup use the Export-CacheData PowerShell cmdlet. Once data is exported, you can get all the items present in the existing backup of the cache using the Import-CacheData PowerShell cmdlet.
It is important to note that you can only restore data for a distributed cache using the Import and Export cache data cmdlets together. This is particularly useful during an NCache version upgrade when restoring previously cached data is required.
Important
The cache name must be the same while using the Export-CacheData and Import-CacheData cmdlets.
Export Cache Data
The Export-CacheData cmdlet enables the user to create a backup of the data present in the cache for later use.
- This command backs up all the keys present in the cache.
Export-CacheData -Name defaultCache -Path C:\Backup-path
- This command backs up all the keys present in the cache with 2 MB data files.
Export-CacheData -Name defaultCache -Path C:\Backup-path `
-FileSize 2
- This command backs up all the keys present in the cache on server 20.200.20.11.
Export-CacheData -Name defaultCache -Path C:\Backup-path `
-Server 20.200.20.11
- This command backs up a cache configured with Pub/Sub Messaging as its store type. In addition to the cache items, it backs up all topics, their registered durable subscriptions, and the messages associated with each topic. The topic and message data is stored in the
TopicsandMessagesfolders within the backup.
Export-CacheData -Name pubSubCache -Path C:\Backup-path
- This command exports data from defaultCache to
C:\Backup-pathon the specified server with mutual TLS (mTLS) enabled. It runs from a machine where NCache is not installed and usesC:\certs\client.pemto authenticate the machine running the cmdlet. The-TlsCertPasswordparameter decrypts the certificate’s password-protected private key. Omit this parameter if the private key is not encrypted.
Export-CacheData -Name defaultCache -Path C:\Backup-path `
-Server 20.200.20.11 -TlsCertPath "C:\certs\client.pem" `
-TlsCertPassword "clientKeyPassword"
- This command backs up all the keys present in the cache, using security credentials.
Export-CacheData -Name defaultCache -Path C:\Backup-path `
-Credentials(Get-Credential john_smith)
Import Cache Data
You can use the Import-CacheData cmdlet to restore the data that was backed up using the Export-CacheData command.
- This command reloads all the items to the cache from the specified path.
Import-CacheData -Name defaultCache -Path C:\Backup-path
- This command reloads all the items to the cache from the specified path and will exit if 10 errors occur during the process.
Import-CacheData -Name defaultCache -Path C:\Backup-path `
-ErrorThreshhold 10
- This command reloads all the items in bulk of 100 to the cache from the specified path.
Import-CacheData -Name defaultCache -Path C:\Backup-path `
-BulkSize 100
- This command reloads all the items to the cache on server 20.200.20.11 from the specified path.
Import-CacheData -Name defaultCache -Path C:\Backup-path `
-Server 20.200.20.11
- This command restores a backup of a cache configured with Pub/Sub Messaging as its store type. It restores all topics, their registered durable subscriptions, and the messages associated with each topic. Each restored message retains its original message ID, creation time, and expiration time from the backup. This allows subscribers that reconnect to a restored durable subscription to receive the messages available for that subscription.
Import-CacheData -Name pubSubCache -Path C:\Backup-path
- This command imports data from
C:\Backup-pathinto defaultCache on the specified server with mutual TLS (mTLS) enabled. It runs from a machine where NCache is not installed and usesC:\certs\client.pemto authenticate the machine running the cmdlet. The-TlsCertPasswordparameter decrypts the certificate’s password-protected private key. Omit this parameter if the private key is not encrypted.
Import-CacheData -Name defaultCache -Path C:\Backup-path `
-Server 20.200.20.11 -TlsCertPath "C:\certs\client.pem" `
-TlsCertPassword "clientKeyPassword"
- This command reloads all the items to the cache from the specified path, using security credentials.
Import-CacheData -Name defaultCache -Path C:\Backup-path `
-Credentials(Get-Credential john_smith)
See Also
Start Cache
Restart Cache
Manage Cache Service on a Server Node