Report server encryption key is essential in recovering, migrating and troubleshooting. Although, we generally backup it when report server is built, but it is required to take backup time-to-time to avoid any miss-out. Scheduling a SQL Server job on the SQL Server will be sufficient and we can schedule it to run once a week.
Below is a simple Powershell script which can help you scheduling such a job :
You can schedule the job with Powershell subsystem or CMDExec subsystem depending on the standard followed in your organization.
Thanks for reading this article! Please do update me if you have issues running it.
Below is a simple Powershell script which can help you scheduling such a job :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------------------------------------------------------------------------------ | |
# Script : Backup_RSKey.ps1 | |
# Author : Som DT. | |
# Purpose : Backup Report Server Encryption Key with Powershell | |
#------------------------------------------------------------------------------------------ | |
# Syntax : Powershell .\Backup_RSKey.ps1 -InstanceName <InstanceName> -PassWord <Password> -BackupLocation <BackupLocation> | |
#------------------------------------------------------------------------------------------ | |
# Example : Powershell .\Backup_RSKey.ps1 -InstanceName "MSSQLSERVER" -PassWord "rsdal@2015" -BackupLocation "C:\temp" | |
#------------------------------------------------------------------------------------------ | |
param ( | |
[string]$InstanceName="MSSQLSERVER", | |
[string]$PassWord="rsdal@2015", | |
[string]$BackupLocation="C:\temps" | |
) | |
cls | |
$FileTimestamp=$(get-date).tostring("yyyyMMddHHmmss") | |
function Backup-RSKey([string]$InstanceName , [string]$PassWord, [string]$BackupLocation) | |
{ | |
Trap { | |
echo "Failure : $($Error[0].Exception.Message)" | |
return | |
} | |
$KeyFile="${BackupLocation}\KEY_$InstanceName_$FileTimestamp.snk" | |
echo "Backing up to file : $KeyFile" | |
$Error.Clear() | |
Out-String -InputObject( echo "Y" | RSKeyMgmt.exe -e -f"$KeyFile" -p"$PasWord" -i"$InstanceName") | |
if (!(Test-Path "$KeyFile") ) | |
{ | |
return "Failure : Error occured while backing up [$KeyFile]." | |
} | |
else | |
{ | |
return "Success" | |
} | |
} | |
$Output=Backup-RSKey "$InstanceName" "$PassWord" "$BackupLocation" | |
echo $Output | |
#-------------------------------------------------------------------------------------------------------------- | |
#-- End of Program | |
#-------------------------------------------------------------------------------------------------------------- |
You can schedule the job with Powershell subsystem or CMDExec subsystem depending on the standard followed in your organization.
Thanks for reading this article! Please do update me if you have issues running it.
This is awesome. i have been looking for something like this.
ReplyDeleteI am getting error. any idea how to resolve
ReplyDeleteFailure : The term 'RSKeyMgmt.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path