Restoring backup to AlwaysOn Availability Group primary server.

  • 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

  • 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.

  • 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

  • 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

  • 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.

  • 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" 😉

  • 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

  • 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
  • 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" 😉

  • 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.

  • Perry Whittle - Friday, May 4, 2018 7:23 AM

    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

    I wasn't sure that if I didn't disable AOAG, that when I restored the database to the primary, it would automatically try to rebuild the database on the secondary. I would rather restore to both the primary and secondary and then enable AOAG (which would then recognize the same database is on the Primary and Secondary). Again, in my head that's how I envisioned it...

    Mike Scalise, PMP
    https://www.michaelscalise.com

  • jcarranza 23978 - Friday, May 4, 2018 8:13 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

    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.

    Ok, thanks. I'm looking for as few steps as possible. So, just to clarify, let's say I have database named "MyDatabase" on the primary and on the secondary (both part of an AG).

    Then, just for argument's sake, let's say I want both instances of "MyDatabase" gone because I have a backup of a completely different database that just so happens to also be named "MyDatabase" and that I want on the Primary and Secondary--would your instructions change at all?

    I realize it's an odd scenario, but I'm looking to see what would be the best or most efficient way of doing this.

    Thanks,
    Mike

    Mike Scalise, PMP
    https://www.michaelscalise.com

  • Mike Scalise - Monday, May 7, 2018 9:32 AM

    I wasn't sure that if I didn't disable AOAG, that when I restored the database to the primary, it would automatically try to rebuild the database on the secondary.

    You get the option to auto create and sync or do this manually

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

    "Ya can't make an omelette without breaking just a few eggs" 😉

Viewing 13 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic. Login to reply