Script for Migration Citrix databases to new SQL server (Cluster, Always On or Mirroring)

This script will migrate the Citrix database(s) connections to a new SQL Server. Because of the standard license for SQL Server, I needed to create a separate listener for each database (you can also use this script without listeners). Before you begin you need to take some steps.

Backup

  • Create a backup and or snapshot of your Delivery Controller(s)
  • Create a backup of all Citrix databases
  • If you are migration from a SQL-Cluster, stop the sync on all databases

What is an Always On availability group? – SQL Server Always On | Microsoft Docs

Restore

  • Restore all Citrix databases on the new SQL Server
  • Add the Delivery Controller computer account(s) to SQL, so the Delivery Controller can access the database
  • Check your firewall settings

https://stackoverflow.com/questions/38680366/how-to-add-a-new-sql-server-machine-account

Migration steps

  • Open Powershell as an administrator
asnp citrix* (this loads the Citrix snap-in commandlets)
  • Retrieve the Connection Strings for each DB
Get-Command -Name get-*DBConnection
Get-Command -Name get-*ServiceStatus - to check the status of all citrix services that communicate with DB
Get-Command -Name get-*ServiceStatus | select name
  • Next step will be to check the connection string for Logging and Monitoring Data store
Get-LogDataStore
Get-MonitorDataStore
Take the necessary notes!
  • Execute the script (don’t forget the change the values in this script, for your own environment)
asnp citrix*
# Execute this script on all your Delivery Controllers
# Close Citrix Studio, before you run this script

# Disable Log database
Set-LogSite -State "Disabled"

# Disable Monitoring database
Set-MonitorConfiguration -DataCollectionEnabled $False

# Remove connectstring
Set-ConfigDBConnection -DBConnection $null
Set-AcctDBConnection -DBConnection $null
Set-AnalyticsDBConnection -DBConnection $null             #  7.6 and newer
Set-AppLibDBConnection -DBConnection $null                  # 7.8 and newer
Set-OrchDBConnection -DBConnection $null                    #  7.11 and newer
Set-TrustDBConnection -DBConnection $null                    #  7.11 and newer
Set-HypDBConnection -DBConnection $null
Set-ProvDBConnection -DBConnection $null
Set-BrokerDBConnection -DBConnection $null
Set-EnvTestDBConnection -DBConnection $null
Set-SfDBConnection -DBConnection $null
Set-MonitorDBConnection -DataStore Monitor -DBConnection $null
Set-MonitorDBConnection -DBConnection $null
Set-LogDBConnection -DataStore Logging -DBConnection $null
Set-LogDBConnection -DBConnection $null
Set-AdminDBConnection -DBConnection $null -force

# Same as reboot of Delivery Controller
Get-Service Citrix* | Stop-Service -Force
Get-Service Citrix* | Start-Service

# Add new connectstring for each database as a listner (change the values if needed)
$ServerName="LSTN-DDCSite"
$ServernameLOG="LSTN-DDCLog"
$ServernameMON="LSTN-DDCMon"
$SiteDBName = "CitrixSite"
$LogDBName = "CitrixLogging"
$MonitorDBName = "CitrixMonitoring"
$cs="Server=$ServerName;Initial Catalog=$SiteDBName;Integrated Security=True"
$csLogging= "Server=$ServerNameLOG;Initial Catalog=$LogDBName;Integrated Security=True"
$csMonitoring = "Server=$ServerNameMON;Initial Catalog=$MonitorDBName;Integrated Security=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 $null
Set-LogDBConnection -DBConnection $null
Set-LogDBConnection -DBConnection $cs
Set-LogDBConnection -DataStore Logging -DBConnection $csLogging
Set-MonitorDBConnection -DBConnection $cs
Set-MonitorDBConnection -DataStore Monitor -DBConnection $null
Set-MonitorDBConnection -DBConnection $null
Set-MonitorDBConnection -DBConnection $cs
Set-MonitorDBConnection -DataStore Monitor -DBConnection $csMonitoring

# Enable Monitoring
Set-MonitorConfiguration -DataCollectionEnabled $true

# Enable Logging
Set-LogSite -State "Enabled"

# Test connection services
Get-AcctServiceStatus
Get-AdminServiceStatus
Get-AnalyticsServiceStatus                # 7.6 and newer
Get-AppLibServiceStatus                   # 7.8 and newer
Get-BrokerServiceStatus
Get-ConfigServiceStatus
Get-EnvTestServiceStatus
Get-HypServiceStatus
Get-LogServiceStatus
Get-MonitorServiceStatus
Get-OrchServiceStatus                   #  7.11 and newer
Get-TrustServiceStatus                  #  7.11 and newer
Get-ProvServiceStatus
Get-SfServiceStatus

# Same as reboot of Delivery Controller
Get-Service Citrix* | Stop-Service -Force
Get-Service Citrix* | Start-Service
  • Login to Citrix Studio and check databases
  • If you are on a SQL Cluster, you need to activate the sync for all Citrix databases


Done!

Leave a Comment

Your email address will not be published.

Scroll to Top