'Create replica of Azure DB for my SQL Server using powershell

While creating replica of Azure DB for my SQL Server using powershell getting the below error. Please help me to fix.

Command to create replica of DB server:

1st command tried:

$TargetDBServerName2= Get-AzMySqlServer -ResourceGroupName $ResourceGroupName -ServerName $TargetDBServerName New-AzMySqlReplica -Master $TargetDBServerName2 -Replica $TargetDBServerName-replica -ResourceGroupName $ResourceGroupName

2nd command tried:

Get-AzMySqlServer -ResourceGroupName $ResourceGroupName -ServerName $TargetDBServerName | New-AzMySqlReplica -Replica $TargetDBServerName-replica -ResourceGroupName $ResourceGroupName

Error when I ran first command:

PS /home/praveen> New-AzMySqlReplica -Master $TargetDBServerName2 -Replica $TargetDBServerName-replica -ResourceGroupName $ResourceGroupName New-AzMySqlServer_Create: /usr/local/share/powershell/Modules/Az.MySql/1.0.0/custom/New-AzMySqlReplica.ps1:139 Line | 139 | Az.MySql.internal\New-AzMySqlServer @PSBoundParameters | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | An unexpected error occured while processing the request. Tracking ID: '0268ff12-7c60-49de-8de5-ccdb844d8329'

Error when I ran 2nd command:

PS /home/praveen> Get-AzMySqlServer -ResourceGroupName $ResourceGroupName -ServerName $TargetDBServerName | New-AzMySqlReplica -Replica $TargetDBServerName-replica -ResourceGroupName $ResourceGroupName New-AzMySqlServer_Create: /usr/local/share/powershell/Modules/Az.MySql/1.0.0/custom/New-AzMySqlReplica.ps1:139 Line | 139 | Az.MySql.internal\New-AzMySqlServer @PSBoundParameters | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | An unexpected error occured while processing the request. Tracking ID: '3aea208b-0a59-4be9-ad95-aef3593b2c71'



Solution 1:[1]

The read replica feature is only available for Azure Database for MySQL servers in the General Purpose or Memory Optimized pricing tiers. Ensure the source server is in one of these pricing tiers.

The Az PowerShell module installed locally or Azure Cloud Shell in the browser

While the Az.MySql PowerShell module is in preview, you must install it separately from the Az PowerShell module using the following command: Install-Module -Name Az.MySql -AllowPrerelease.

The following command may be used to construct a read replica server.

Get-AzMySqlServer -Name mydemoserver -ResourceGroupName myresourcegroup |  
New-AzMySqlReplica -Name mydemoreplicaserver -ResourceGroupName myresourcegroup

myresourcegroup : The resource group where the replica server is created.
mydemoreplicaserver : The name of the new replica server that is created.

Depending on the storage utilised (v1/v2), your source server may need to restart to ready itself for replication if there are no current replica servers. Please consider restarting the server and do so at off-peak hours. For further information, see Source Server Restart.

Refer this document for more information.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 PratikLad-MT