SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Restoring backup to AlwaysOn Availability Group primary server.


Restoring backup to AlwaysOn Availability Group primary server.

Author
Message
Mike Scalise
Mike Scalise
SSCertifiable
SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)

Group: General Forum Members
Points: 5312 Visits: 1092
I'm a bit of a novice when it comes to AlwaysOn, so I was hoping some of you that have expertise in this area can help me understand the high-level process for restoring a database to an AOAG cluster. Is it simply:

1) Disable AOAG
2) Delete the database from the primary
3) Restore database to primary
4) Restore database to secondary (and others if necessary)
5) Enable AOAG

Something like that? Also, would your answer change if this were a true production cluster vs a non-production one (where HA isn't critical).

Thank you in advance.

Mike

Mike Scalise, PMP
https://www.michaelscalise.com
RVSC48
RVSC48
SSCertifiable
SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)

Group: General Forum Members
Points: 6204 Visits: 2007
Hi Mike,
To restore a database to an AOAG cluster, you would:
1) Remove the database from Availability Group
2) Drop the database on the Secondary
3) Restore the database on the Primary
4) Back up the database on the Primary
5) Back up the transaction log of the database on the Primary
6) Restore the database on the Secondary with No Recovery
7) Restore the transaction log on the Secondary with No Recovery
8) Run a command on the secondary similar to: ALTER DATABASE xxxx SET HADR AVAILABILITY GROUP = [my AG]
9) Run a command on the primary similar to: ALTER AVAILABILITY GROUP [my AG] ADD DATABASE [xxxx]
For restoring a database on a FCI (Failover Cluster Instance) with no AOAG's, the process would be to simply restore the database as you would on a stand-alone instance.
Mike Scalise
Mike Scalise
SSCertifiable
SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)

Group: General Forum Members
Points: 5312 Visits: 1092
RVSC48 - Tuesday, May 1, 2018 10:59 AM
Hi Mike,
To restore a database to an AOAG cluster, you would:
1) Remove the database from Availability Group
2) Drop the database on the Secondary
3) Restore the database on the Primary
4) Back up the database on the Primary
5) Back up the transaction log of the database on the Primary
6) Restore the database on the Secondary with No Recovery
7) Restore the transaction log on the Secondary with No Recovery
8) Run a command on the secondary similar to: ALTER DATABASE xxxx SET HADR AVAILABILITY GROUP = [my AG]
9) Run a command on the primary similar to: ALTER AVAILABILITY GROUP [my AG] ADD DATABASE [xxxx]
For restoring a database on a FCI (Failover Cluster Instance) with no AOAG's, the process would be to simply restore the database as you would on a stand-alone instance.

Thanks, RVSC! I appreciate the information.


Mike Scalise, PMP
https://www.michaelscalise.com
Mike Scalise
Mike Scalise
SSCertifiable
SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)

Group: General Forum Members
Points: 5312 Visits: 1092
RSVC,

I was reviewing your steps and I had a few more questions if you don't mind.

1) Steps 2 and 3 are not making sense to me...drop on the secondary and restore on the primary? Wouldn't I want to drop the database where I'm about to restore? In other words, drop database from primary then restore database to primary?

2) With steps 3 and 4, why would I restore a database on the primary and then back it up right after that? Wouldn't that effectively be the same as the backup I just restored?

Thanks,

Mike

Mike Scalise, PMP
https://www.michaelscalise.com
jcarranza 23978
jcarranza 23978
SSC Eights!
SSC Eights! (995 reputation)SSC Eights! (995 reputation)SSC Eights! (995 reputation)SSC Eights! (995 reputation)SSC Eights! (995 reputation)SSC Eights! (995 reputation)SSC Eights! (995 reputation)SSC Eights! (995 reputation)

Group: General Forum Members
Points: 995 Visits: 110
Mike Scalise - Wednesday, May 2, 2018 8:05 AM
RSVC,

I was reviewing your steps and I had a few more questions if you don't mind.

1) Steps 2 and 3 are not making sense to me...drop on the secondary and restore on the primary? Wouldn't I want to drop the database where I'm about to restore? In other words, drop database from primary then restore database to primary?

2) With steps 3 and 4, why would I restore a database on the primary and then back it up right after that? Wouldn't that effectively be the same as the backup I just restored?

Thanks,

Mike

When you remove the Database from the Availability Group there are two copies..
Server 1 has the copy that you can restore (Step 3). Restore and Overwrite the Database.
Server 2 ( on Step 2) will have a database in RECOVERY mode. It will not be accessible. You will remove the DB in the secondary node.

If you do the above you can then Synchronize again. However, if it tells you that you need to backup the database (Step 4) then you will have to do it (he is trying to make sure you don't get that message but you have a point), otherwise you can synchronize.

Perry Whittle
Perry Whittle
SSC Guru
SSC Guru (198K reputation)SSC Guru (198K reputation)SSC Guru (198K reputation)SSC Guru (198K reputation)SSC Guru (198K reputation)SSC Guru (198K reputation)SSC Guru (198K reputation)SSC Guru (198K reputation)

Group: General Forum Members
Points: 198096 Visits: 18538
Mike Scalise - Tuesday, May 1, 2018 9:41 AM
I'm a bit of a novice when it comes to AlwaysOn, so I was hoping some of you that have expertise in this area can help me understand the high-level process for restoring a database to an AOAG cluster. Is it simply:

1) Disable AOAG
2) Delete the database from the primary
3) Restore database to primary
4) Restore database to secondary (and others if necessary)
5) Enable AOAG

Something like that? Also, would your answer change if this were a true production cluster vs a non-production one (where HA isn't critical).

Thank you in advance.

Mike


First please specify is the database to be restored currently a member of the existing AG?

-----------------------------------------------------------------------------------------------------------

"Ya can't make an omelette without breaking just a few eggs" ;-)
Mike Scalise
Mike Scalise
SSCertifiable
SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)

Group: General Forum Members
Points: 5312 Visits: 1092
Perry Whittle - Thursday, May 3, 2018 4:12 AM
Mike Scalise - Tuesday, May 1, 2018 9:41 AM
I'm a bit of a novice when it comes to AlwaysOn, so I was hoping some of you that have expertise in this area can help me understand the high-level process for restoring a database to an AOAG cluster. Is it simply:

1) Disable AOAG
2) Delete the database from the primary
3) Restore database to primary
4) Restore database to secondary (and others if necessary)
5) Enable AOAG

Something like that? Also, would your answer change if this were a true production cluster vs a non-production one (where HA isn't critical).

Thank you in advance.

Mike


First please specify is the database to be restored currently a member of the existing AG?

In this particular scenario, the database to be restored is NOT currently a member of the existing AG...


Mike Scalise, PMP
https://www.michaelscalise.com
jcarranza 23978
jcarranza 23978
SSC Eights!
SSC Eights! (995 reputation)SSC Eights! (995 reputation)SSC Eights! (995 reputation)SSC Eights! (995 reputation)SSC Eights! (995 reputation)SSC Eights! (995 reputation)SSC Eights! (995 reputation)SSC Eights! (995 reputation)

Group: General Forum Members
Points: 995 Visits: 110
So you have a Database that is not part of the Availability Group?
Is the Database ONLINE?
Is the Database ready to be added to the Availability Group?
- Or the Database is corrupted?
-Or the Database needs to be Restored from backup for whatever reason?

Can you be more specific on your question. I'll make an assumption.

1. Your database is ONLINE and ready to be added to the Availability Group. First time adding this database to Availability Group.
2. The availability Group is Healthy and there are no issues. Shares are properly configured for Synchronization.
3. You are using either SQL 2012 or 2014. SQL 2016 makes it a little bit easier with "SEEDING".
4. Go to Always ON High Availability > Availability Groups > Select the GROUP > Right click on Availability Databases > "Add Database"
- Here it will tell you if it "Meets Prerequisites"
- Or needs "Full Recovery"
- or needs a "Backup"
5. If it meets Prerequisites then you can add it
6. It will ask you to connect to the secondary node
7. in the Select Data Synchronization it will ask you to choose one of the following:
- Specify the file share path (Location of Full Database and Log backup) - I usually do this one
- Join Only (you have restored database and log backup to each secondary server) - I've had problems with this one
- Skip initial Synchronization (perform own DB/log backup to primary ) -never done this one
8. It will perform a validation... if there are errors it will tell you here. Errors such as
- problems with shared location
- Disk space
- Does database already exists in secondary node or files already exists there
- Compatibility of file locations
9. Once it passes the validation then you are ready to FINISH and make it part of the availability Group.
It will Synchronize and add it to the secondary node.

Things to know :
Server 1 : developmentsql1
Server2 : developmentsql2
Database to be added : MyDatabase
Availability Group : DEVSQLGRP
Shared backup location 1 : \\Developmentsql1\SharedLocation\
Shared Backup location: \\Developmentsql2\SharedLocation\


SCRIPTED BELOW..
--- YOU MUST EXECUTE THE FOLLOWING SCRIPT IN SQLCMD MODE.
:Connect developmentsql1 --whatever name of your primary server
USE [master]
GO
ALTER AVAILABILITY GROUP [DEVSQLGRP] --whatever GROUP name you have
ADD DATABASE [MyDatabase]; --whatever Server
GO
:Connect developmentsql1
BACKUP DATABASE [MyDatabase] TO DISK = N'\\Developmentsql1\SharedLocation\developmentsql.bak' WITH COPY_ONLY, FORMAT, INIT, SKIP, REWIND, NOUNLOAD, COMPRESSION, STATS = 5
GO
:Connect developmentsql2
RESTORE DATABASE [PeopleAdmin] FROM DISK = N'\\Developmentsql2\SharedLocation\developmentsql.bak' WITH NORECOVERY, NOUNLOAD, STATS = 5
GO
:Connect developmentsql1
BACKUP LOG [PeopleAdmin] TO DISK = N'\\Developmentsql1\SharedLocation\developmentsql.trn' WITH NOFORMAT, INIT, NOSKIP, REWIND, NOUNLOAD, COMPRESSION, STATS = 5
GO
:Connect developmentsql2
RESTORE LOG [PeopleAdmin] FROM DISK = N'\\Developmentsql2\SharedLocation\developmentsql.trn' WITH NORECOVERY, NOUNLOAD, STATS = 5
GO
:Connect developmentsql2

-- Wait for the replica to start communicating
begin try
declare @conn bit
declare @count int
declare @replica_id uniqueidentifier
declare @group_id uniqueidentifier
set @conn = 0
set @count = 30 -- wait for 5 minutes
if (serverproperty('IsHadrEnabled') = 1)
and (isnull((select member_state from master.sys.dm_hadr_cluster_members where upper(member_name COLLATE Latin1_General_CI_AS) = upper(cast(serverproperty('ComputerNamePhysicalNetBIOS') as nvarchar(256)) COLLATE Latin1_General_CI_AS)), 0) <> 0)
and (isnull((select state from master.sys.database_mirroring_endpoints), 1) = 0)
begin
select @group_id = ags.group_id from master.sys.availability_groups as ags where name = N'DEVSQLGRP'
select @replica_id = replicas.replica_id from master.sys.availability_replicas as replicas where upper(replicas.replica_server_name COLLATE Latin1_General_CI_AS) = upper(@@SERVERNAME COLLATE Latin1_General_CI_AS) and group_id = @group_id
while @conn <> 1 and @count > 0
begin
set @conn = isnull((select connected_state from master.sys.dm_hadr_availability_replica_states as states where states.replica_id = @replica_id), 1)
if @conn = 1
begin
-- exit loop when the replica is connected, or if the query cannot find the replica status
break
end
waitfor delay '00:00:10'
set @count = @count - 1
end
end
end try
begin catch
-- If the wait loop fails, do not stop execution of the alter database statement
end catch
ALTER DATABASE [MyDatabase] SET HADR AVAILABILITY GROUP = [DEVSQLGRP];
GO

GO

Perry Whittle
Perry Whittle
SSC Guru
SSC Guru (198K reputation)SSC Guru (198K reputation)SSC Guru (198K reputation)SSC Guru (198K reputation)SSC Guru (198K reputation)SSC Guru (198K reputation)SSC Guru (198K reputation)SSC Guru (198K reputation)

Group: General Forum Members
Points: 198096 Visits: 18538
Mike Scalise - Thursday, May 3, 2018 7:00 AM
Perry Whittle - Thursday, May 3, 2018 4:12 AM
Mike Scalise - Tuesday, May 1, 2018 9:41 AM
I'm a bit of a novice when it comes to AlwaysOn, so I was hoping some of you that have expertise in this area can help me understand the high-level process for restoring a database to an AOAG cluster. Is it simply:

1) Disable AOAG
2) Delete the database from the primary
3) Restore database to primary
4) Restore database to secondary (and others if necessary)
5) Enable AOAG

Something like that? Also, would your answer change if this were a true production cluster vs a non-production one (where HA isn't critical).

Thank you in advance.

Mike


First please specify is the database to be restored currently a member of the existing AG?

In this particular scenario, the database to be restored is NOT currently a member of the existing AG...


Ok so why do you think you need to disable the AG, which incidentally you cannot do.
Correct sequence is

1) Restore backup of the new database to the Primary replica
2) either manually or using wizard, stage the secondary databases

-----------------------------------------------------------------------------------------------------------

"Ya can't make an omelette without breaking just a few eggs" ;-)
jcarranza 23978
jcarranza 23978
SSC Eights!
SSC Eights! (995 reputation)SSC Eights! (995 reputation)SSC Eights! (995 reputation)SSC Eights! (995 reputation)SSC Eights! (995 reputation)SSC Eights! (995 reputation)SSC Eights! (995 reputation)SSC Eights! (995 reputation)

Group: General Forum Members
Points: 995 Visits: 110
Mike Scalise - Tuesday, May 1, 2018 9:41 AM
I'm a bit of a novice when it comes to AlwaysOn, so I was hoping some of you that have expertise in this area can help me understand the high-level process for restoring a database to an AOAG cluster. Is it simply:

1) Disable AOAG
2) Delete the database from the primary
3) Restore database to primary
4) Restore database to secondary (and others if necessary)
5) Enable AOAG

Something like that? Also, would your answer change if this were a true production cluster vs a non-production one (where HA isn't critical).

Thank you in advance.

Mike


Look, if the database is fine on the Primary node all you have to do is just add it to the Availability Group.
The wizard will let you know if it needs a Recovery model or a backup or both. Once it meets the prerequisites then everything should work.
If the AOAG is functioning properly.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search