Professional Documents
Culture Documents
SQL SERVER - Add Database to Availability Group Failure - This BACKUP or RESTORE
Command is Not Supported on a Database Mirror or Secondary Replica
availabilitygroup-800x242
THE SITUATION
My client had an existing availability group which was set up and deployed by a
vendor. Now, they wanted to add a new database to an existing availability group.
They were using the wizard to add the database. They selected the option to do a
fresh backup/restore. Due to old SSMS version, automatic seeding option was not
available. Here was the error which they were getting in the UI.
SQL SERVER - Add Database to Availability Group Failure - This BACKUP or RESTORE
Command is Not Supported on a Database Mirror or Secondary Replica restore-err-
seed-01
Solarwinds
The surprising part was that even after the error came, the database was added to
the availability group successfully. This means the error was a benign error and
can be ignored but I want to know what error was appearing. To dig further I
generated the script of Always On and executed it manually. It failed with the
exact same error.
Primary Replica:
Secondary Replica:
If we look at the backup and restore commands, there are two backups. Once on
TYPE=DISK and another on TYPE=VIRTUAL_DEVICE. The second backup comes when there is
an automatic seeding happening for the database.
Running script manually fails with below (on secondary). This is the same what we
get from the UI.
Connecting to sqlserver-1�
Msg 3059, Level 16, State 2, Line 29
This BACKUP or RESTORE command is not supported on a database mirror or secondary
replica.
Msg 3013, Level 16, State 1, Line 29
RESTORE LOG is terminating abnormally.
Disconnecting connection from sqlserver-1�
Connecting to sqlserver-1�
Msg 41145, Level 16, State 1, Line 67
Cannot join database �DWConfiguration� to availability group �XAG�. The database
has already joined the availability group. This is an informational message. No
user action is required.
Disconnecting connection from sqlserver-1�
When I compared the script generated from SSMS for an old and new version, I found
the difference which explained the issue clearly. This was the extra command in the
new version of SSMS.
1
2
ALTER AVAILABILITY GROUP [XAG]
MODIFY REPLICA ON N'sqlserver-1' WITH (SEEDING_MODE = MANUAL)
This means that SSMS is smart enough to change the mode to MANUAL when below option
is selected.
SQL SERVER - Add Database to Availability Group Failure - This BACKUP or RESTORE
Command is Not Supported on a Database Mirror or Secondary Replica restore-err-
seed-02
So, to conclude, the seeding was set to AUTOMATIC for the replica. When we were
using an older version of SSMS, it was doing both automatic seeding and
backup/restore. This was causing restore to fail because it was seeded already and
added successfully.
You can use below query to find replica seeding mode.
1
2
3
4
5
6
7
SELECT ag.name
,replica_server_name
,seeding_mode_desc
FROM sys.availability_replicas ar
,sys.availability_groups ag
WHERE ag.group_id = ar.group_id
AND name = 'AGSQLAGDB'
Have you seen such errors of SSMS? Please comment and let me know.