Jump to content
Welcome to our new Citrix community!
  • 0

DB server migration


Darman

Question

2 answers to this question

Recommended Posts

  • 0

Implement

  1. Take VM Snapshot of SQL servers + Delivery Controllers, (if applicable.)
  2. Perform a Test Site in Studio to make sure environment is healthly. Then ensure all instances of Citrix Studio are closed.
  3. Do a SQL Backup/Restore from old server to new server.
  4. Create/check SQL logons/ database permissions. This is very important as permissions must be the same. 
  5. Set SQL Connection strings on one delivery controller. Citrix has some scripts, but I combined them into one and tweaked it. I used it on 1912. If you're running 2203, might need some adjustment. 

Do not open Citrix Studio or Citrix Director until ALL DELIVERY CONTROLLERS have had their connection strings updated.

 

Test plan:

  1. Launch Citrix Director and check database links at the bottom of the dashboard
  2. Open Citrix Studio. Verify Applications and Delivery Groups look normal. Check Database servers (Configuration.)
  3. In Studio, Perform a Site test under Citrix Studio>Site Configuration. Ensure all 237 tests pass.

 

PowerShell Script:

 

#Citrix Database Connection Scripts
#by Jason Ochs 3/22/21

#This script with backup DB connections to services, nullify then, and allow you to set a new database connection string. 
#CITRIX may add new services thus adding/removing the database connection strings below, so run command 'Get-Command -Name get-*DBConnection' to get a current list.

asnp Citrix*

## Record existing database connection Strings to CitrixDBConnectionStrings.txt
Write-Host "Backing up existing connection strings to C:\Temp\CitrixDBConnectionStrings.txt. Strings will also be written as variables as well." -ForegroundColor Red
Write-Output "ConfigDBConnection is:" (Get-configDBConnection) | Out-File C:\Temp\CitrixDBConnectionStrings.txt -Append
Write-Output "AppLibDBConnection is:" (Get-AppLibDBConnection) | Out-File C:\Temp\CitrixDBConnectionStrings.txt -Append
Write-Output "OrchDBConnection is:" (Get-OrchDBConnection) | Out-File C:\Temp\CitrixDBConnectionStrings.txt -Append
Write-Output "TrustDBConnection is:" (Get-TrustDBConnection) | Out-File C:\Temp\CitrixDBConnectionStrings.txt -Append 
Write-Output "AcctDBConnection is:" (Get-AcctDBConnection) | Out-File C:\Temp\CitrixDBConnectionStrings.txt -Append 
Write-Output "AnalyticsDBConnection is:" (Get-AnalyticsDBConnection) | Out-File C:\Temp\CitrixDBConnectionStrings.txt -Append
Write-Output "HypDBConnection is:" (Get-HypDBConnection) | Out-File C:\Temp\CitrixDBConnectionStrings.txt -Append 
Write-Output "ProvDBConnection is:" (Get-ProvDBConnection) | Out-File C:\Temp\CitrixDBConnectionStrings.txt -Append 
Write-Output "BrokerDBConnection is:" (Get-BrokerDBConnection) | Out-File C:\Temp\CitrixDBConnectionStrings.txt -Append 
Write-Output "EnvTestDBConnection is:" (Get-EnvTestDBConnection) | Out-File C:\Temp\CitrixDBConnectionStrings.txt -Append 
Write-Output "SfDBConnection is:" (Get-SfDBConnection) | Out-File C:\Temp\CitrixDBConnectionStrings.txt -Append 
Write-Output "MonitorDBConnection is:" (Get-MonitorDBConnection) | Out-File C:\Temp\CitrixDBConnectionStrings.txt -Append 
Write-Output "MonitorDBConnection is:" (Get-MonitorDBConnection) | Out-File C:\Temp\CitrixDBConnectionStrings.txt -Append 
Write-Output "LogDBConnection is:" (Get-LogDBConnection) | Out-File C:\Temp\CitrixDBConnectionStrings.txt -Append 
Write-Output "LogDBConnection is:" (Get-LogDBConnection) | Out-File C:\Temp\CitrixDBConnectionStrings.txt -Append
Write-Output "AdminDBConnection is:" (Get-AdminDBConnection) | Out-File C:\Temp\CitrixDBConnectionStrings.txt -Append
# Records Strings to backup variables:
Get-configDBConnection | Out-File C:\Temp\CitrixDB_configDBConnectionOLD.txt
Get-AppLibDBConnection | Out-File C:\Temp\CitrixDB_AppLibDBConnectionOLD.txt
Get-OrchDBConnection | Out-File C:\Temp\CitrixDB_OrchDBConnectionOLD.txt
Get-TrustDBConnection | Out-File C:\Temp\CitrixDB_TrustDBConnectionOLD.txt
Get-AcctDBConnection | Out-File C:\Temp\CitrixDB_AcctDBConnectionOLD.txt
Get-AnalyticsDBConnection | Out-File C:\Temp\CitrixDB_AnalyticsDBConnectionOLD.txt
Get-HypDBConnection | Out-File C:\Temp\CitrixDB_HypDBConnectionOLD.txt
Get-ProvDBConnection | Out-File C:\Temp\CitrixDB_ProvDBConnectionOLD.txt
Get-BrokerDBConnection | Out-File C:\Temp\CitrixDB_BrokerDBConnectionOLD.txt
Get-EnvTestDBConnection | Out-File C:\Temp\CitrixDB_EnvTestDBConnectionOLD.txt
Get-SfDBConnection | Out-File C:\Temp\CitrixDB_SfDBConnectionOLD.txt
Get-MonitorDBConnection | Out-File C:\Temp\CitrixDB_MonitorDBConnectionOLD.txt
Get-LogDBConnection | Out-File C:\Temp\CitrixDB_LogDBConnectionOLD.txt
Get-AdminDBConnection | Out-File C:\Temp\CitrixDB_AdminDBConnectionOLD.txt

Write-Host "Completed writing existing connection strings to C:\Temp\CitrixDBConnectionStrings.txt. Please verify." -ForegroundColor Red
pause

#Checking Service State. All should report "OK."
Get-AcctServiceStatus
Get-AdminServiceStatus
Get-AnalyticsServiceStatus
Get-AppLibServiceStatus
Get-BrokerServiceStatus
Get-ConfigServiceStatus
Get-EnvTestServiceStatus
Get-HypServiceStatus
Get-LogServiceStatus
Get-MonitorServiceStatus
Get-OrchServiceStatus
Get-ProvServiceStatus
Get-SfServiceStatus
Get-TrustServiceStatus
Write-Host "Next, Monitoring and Logging will be disabled. Afterwards, DB connections will be nullified. Proceed only if everything checks out OK and you are ready." -ForegroundColor Red
pause

#Disable Monitoring and Logging
Set-MonitorConfiguration –DataCollectionEnabled $False
Set-LogSite –State Disabled


## Nullifies DB connection strings so we can change them.
Set-AnalyticsDBConnection -DBConnection $null -force             #  7.6 and newer
Set-AppLibDBConnection -DBConnection $null -force                  # 7.8 and newer
Set-OrchDBConnection -DBConnection $null -force                    #  7.11 and newer
Set-TrustDBConnection -DBConnection $null -force                    #  7.11 and newer
Set-HypDBConnection -DBConnection $null -force
Set-ProvDBConnection -DBConnection $null -force                     
Set-BrokerDBConnection -DBConnection $null -force
Set-EnvTestDBConnection -DBConnection $null -force
Set-SfDBConnection -DBConnection $null -force
Set-MonitorDBConnection -DataStore Monitor -DBConnection $null -force
Set-MonitorDBConnection -DBConnection $null -force
Set-LogDBConnection -DataStore Logging -DBConnection $null -force
Set-LogDBConnection -DBConnection $null -force
Set-ConfigDBConnection -DBConnection $null  -force
Set-AcctDBConnection -DBConnection $null -force
Set-AdminDBConnection -DBConnection $null -force

Write-Host "DB connections have been nullified. Setting new connection string." -ForegroundColor Red
pause

## Replace <dbserver> with the New SQL server, and instance if present
## Replace <dbname> with the name of your restored Database
## Note: AdminDBConnection should be first

#$ServerName="<SQL AlwayaOn Listener Name>"
$ServerName = Read-Host -Prompt 'Input your SQL AlwaysOn Listener Name. You can specify instance or port. E.G> CTXDBLSNR\CTRX \ CTXDBLSNR,1433'
#$SiteDBName = "<DbName(case sensitive)>"
$SiteDBName = Read-Host -Prompt 'Input your SITE DbName, (case sensitive)'
#$LogDBName = "<LoggingDbName>"
$LogDBName = Read-Host -Prompt 'Input your LOGGING DbName, (case sensitive)'
#$MonitorDBName = "<MonitorDbName>"
$MonitorDBName = Read-Host -Prompt 'Input your MONITORING DbName, (case sensitive)'

$cs="Server=$ServerName;Initial Catalog=$SiteDBName;Integrated Security=True;MultiSubnetFailover=True"
$csLogging= "Server=$ServerName;Initial Catalog=$LogDBName;Integrated Security=True;MultiSubnetFailover=True"
$csMonitoring = "Server=$ServerName;Initial Catalog=$MonitorDBName;Integrated Security=True;MultiSubnetFailover=True"

Set-AdminDBConnection -DBConnection $cs
Set-ConfigDBConnection -DBConnection $cs
Set-AcctDBConnection -DBConnection $cs
Set-AnalyticsDBConnection -DBConnection $cs               # 7.6 and newer
Set-HypDBConnection -DBConnection $cs              
Set-ProvDBConnection -DBConnection $cs
Set-AppLibDBConnection -DBConnection $cs                 #  7.8 and newer
Set-OrchDBConnection -DBConnection $cs                    # 7.11 and newer
Set-TrustDBConnection -DBConnection $cs                  #  7.11 and newer
Set-BrokerDBConnection -DBConnection $cs
Set-EnvTestDBConnection -DBConnection $cs
Set-SfDBConnection -DBConnection $cs
Set-LogDBConnection -DBConnection $cs
Set-LogDBConnection -DataStore Logging -DBConnection $csLogging
Set-MonitorDBConnection -DBConnection $cs
Set-MonitorDBConnection -DataStore Monitor -DBConnection $csMonitoring
Write-Host "DB connections have been set. Enabling Monitoring and Logging. Afterwards, performing database tests..." -ForegroundColor Red

#Enable Monitoring and Logging
Set-LogSite –State Enabled
Set-MonitorConfiguration –DataCollectionEnabled $true


##Performing connection tests.
Test-AcctDBConnection -DBConnection $cs
Test-AdminDBConnection -DBConnection $cs
Test-AnalyticsDBConnection -DBConnection $cs # 7.6 and newer
Test-AppLibDBConnection -DBConnection $cs # 7.8 and newer
Test-BrokerDBConnection -DBConnection $cs
Test-ConfigDBConnection -DBConnection $cs
Test-EnvTestDBConnection -DBConnection $cs
Test-HypDBConnection -DBConnection $cs
Test-LogDBConnection -DBConnection $cs
Test-LogDBConnection -DataStore Logging -DBConnection $csLogging
Test-MonitorDBConnection -DBConnection $cs
Test-MonitorDBConnection -Datastore Monitor -DBConnection $csMonitoring
Test-OrchDBConnection -DBConnection $cs # 7.11 and newer
Test-ProvDBConnection -DBConnection $cs
Test-SfDBConnection -DBConnection $cs
Test-TrustDBConnection -DBConnection $cs # 7.11 and newer

Write-Host "Testing complete. Setting monitoring retention." 

Set-MonitorConfiguration -GroomApplicationInstanceRetentionDays 180 
Set-MonitorConfiguration -GroomDeletedRetentionDays 180 
Set-MonitorConfiguration -GroomFailuresRetentionDays 180 
Set-MonitorConfiguration -GroomLoadIndexesRetentionDays 180 
Set-MonitorConfiguration -GroomMachineHotfixLogRetentionDays 180 
Set-MonitorConfiguration -GroomMachineMetricDaySummaryDataRetentionDays 180 
Set-MonitorConfiguration -GroomNotificationLogRetentionDays 180 
Set-MonitorConfiguration -GroomResourceUsageDayDataRetentionDays 180 
Set-MonitorConfiguration -GroomSessionsRetentionDays 180 
Set-MonitorConfiguration -GroomSummariesRetentionDays 180 
Set-MonitorConfiguration -EnableDayLevelGranularityProcessUtilization $True
Set-MonitorConfiguration -EnableHourLevelGranularityProcessUtilization $True
Set-MonitorConfiguration -GroomApplicationErrorsRetentionDays 7
Set-MonitorConfiguration -GroomApplicationFaultsRetentionDays 7
Set-MonitorConfiguration -GroomMachineMetricDataRetentionDays 7
Set-MonitorConfiguration -GroomSessionMetricsDataRetentionDays 7

Write-Host "-- Please reboot the Delivery Controller. --" -ForegroundColor Red 
Write-Host "Run script against remaining delivery controllers until all controllers have been updated." -ForegroundColor Red

Write-Host "Do not open Citrix Studio or Citrix Director until ALL DELIVERY CONTROLLERS have had their connection strings updated." -BackgroundColor Yellow -ForegroundColor Black
Write-Host "Test steps after all controllers have been updated:" 
Write-Host "1) Launch Citrix Director and check database links at the bottom of the dashboard "
Write-Host "2) Open Citrix Studio. Verify Applications and Delivery Groups look normal. Check Database servers (Configuration.)"
Write-Host "3) In Studio, Perform a Site test under Citrix Studio>Site Configuration. Ensure all 237 tests pass." 

pause

  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...