019 - SQL - Server - 2012 - Features - For - Admins - Lesson 19 - Log - Shipping - Lab - Manual

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Lesson 19: Log Shipping 1

Lesson 19: Log Shipping

Microsoft | Services © 2012 Microsoft Corporation ITOE Educate Workshop

Microsoft Confidential
2 Lesson 19: Log Shipping

Conditions and Terms of Use


Microsoft Confidential - For Internal Use Only

This training package is proprietary and confidential, and is intended only for uses described in the training
materials. Content and software is provided to you under a Non-Disclosure Agreement and cannot be
distributed. Copying or disclosing all or any portion of the content and/or software included in such packages is
strictly prohibited.
The contents of this package are for informational and training purposes only and are provided "as is" without
warranty of any kind, whether express or implied, including but not limited to the implied warranties of
merchantability, fitness for a particular purpose, and non-infringement.
Training package content, including URLs and other Internet Web site references, is subject to change without
notice. Because Microsoft must respond to changing market conditions, the content should not be interpreted to
be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information
presented after the date of publication. Unless otherwise noted, the companies, organizations, products,
domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious, and no
association with any real company, organization, product, domain name, e-mail address, logo, person, place, or
event is intended or should be inferred.

© 2012 Microsoft Corporation. All rights reserved.

Copyright and Trademarks


© 2012 Microsoft Corporation. All rights reserved.

Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights
covering subject matter in this document. Except as expressly provided in written license agreement from
Microsoft, the furnishing of this document does not give you any license to these patents, trademarks,
copyrights, or other intellectual property.
Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under
copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or
transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for
any purpose, without the express written permission of Microsoft Corporation.
For more information, see Use of Microsoft Copyrighted Content at
http://www.microsoft.com/about/legal/permissions/
Microsoft®, Internet Explorer®, and Windows® are either registered trademarks or trademarks of Microsoft
Corporation in the United States and/or other countries. Other Microsoft products mentioned herein may be
either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.
All other trademarks are property of their respective owners.

Microsoft | Services © 2012 Microsoft Corporation ITOE Educate Workshop

Microsoft Confidential
Lesson 19: Log Shipping 3

Log Shipping

Introduction
In this lab you will be setting up a Log Shipping environment with SQL Server 2012.

Objectives
After completing this lab, you will be able to:
 Set up the Log Shipping
 Simulate database recovery pending scenario
 Recovery the database by restoring the tail log

Prerequisites
Local access to two or more SQL Server 2012 machines

Estimated time to complete this lab


45 minutes

Virtual Machines Needed for this Lab:


 SQL11AdminWork
 SQLAdmin11CluN1
 SQLAdmin11CluN2

Scenario
You have been tasked to setup a Log Shipping environment for DR. One fine morning
you identified that primary database has went in to recovery pending state and Log
Shipping has failed. You find that Primary database data file is corrupt you know that the
only method left is to recover database from the tail log backup and apply on secondary
server.

Microsoft | Services © 2012 Microsoft Corporation ITOE Educate Workshop

Microsoft Confidential
4 Lesson 19: Log Shipping

Exercise 1: Setup SQL Server 2012 Log Shipping


Objectives
In this exercise, you will:
 Configure SQL Server 2012 Log Shipping

Task: Configure LogShipping and Recover the Tail over the Log
1. Login to SQL11AdminWork,
2. Open SQL Server Management Stuido
3. Connect to the Primary Server named SQLAdmin11CluN1.
4. Open new query window type the below query:
You can type this or open the script file located: L:\Features\Labs\Lesson 19 -
LogShipping\script1.sql on SQL11AdminWork.
USE master
GO
-- DROP THE DATABASE IF IT ALREADY EXISTS
IF EXISTS (SELECT name FROM sys.databases WHERE name =
N'LogShipping_Demo')
BEGIN
DROP DATABASE LogShipping_Demo
END
GO
CREATE DATABASE LogShipping_Demo
GO

5. Create a simple table and insert few rows using the below query:
You can type this or open the script file located: L:\Features\Labs\Lesson 19 -
LogShipping\script2.sql on SQL11AdminWork.
USE [LogShipping_Demo]
GO
CREATE TABLE dbo.LStest
(
C1 int NULL,
C2 varchar(50) NULL
) ON [PRIMARY]
GO
INSERT INTO [dbo].[LStest]
([C1]
,[C2])
VALUES
(1, 'James'),(2, 'Mike'),(3, 'Steeve'),
(4, 'Mark'),(5, 'Ben'),(6, 'Aron'),
(7, 'Rick'),(8, 'Ivan'),(9, 'George'),
(10, 'Brian')
GO

6. Right click on the Databases root in Object Explorer and choose Refresh to make
sure the new database is visible.

Microsoft | Services © 2012 Microsoft Corporation ITOE Educate Workshop

Microsoft Confidential
Lesson 19: Log Shipping 5

7. Right Click on LogShipping_Demo database, Select Properties and then Options.


8. Verify that the Recovery Model is set to FULL. If not, this will need to be changed.

Note: We need to verify that the Recovery Model of the database named
LogShipping_Demo has been set to FULL because in Simple Recovery Model, the
transactional log backup of the database cannot be performed.

9. Click OK.
10. Right-click the LogShipping_Demo database choose tasks and then select Ship
Transaction Logs

Note: You can also go to the Properties of the database and select the
‘Transaction Log Shipping’ tab.

11. Select the Enable this as a primary database in a log shipping configuration
check box.
12. Click the Backup Settings.button

13. In the Network path to the backup folder box, type the following:
\\SQLAdmin11CluN1\logshipping\backups

14. Type in the box called If the backup folder is located on the primary server this
path
C:\logshipping\backups

15. Leave the Delete files older than and Alert if no backup occurs within parameters
to default.
16. Change the Set backup compression to ‘Compress backup’

17. Note the backup schedule listed in the Schedule box under Backup job. If you want
to customize the schedule for your installation, then click Schedule and adjust the
SQL Server Agent schedule as needed.

Microsoft | Services © 2012 Microsoft Corporation ITOE Educate Workshop

Microsoft Confidential
6 Lesson 19: Log Shipping

18. Click OK.


19. Under Secondary server instances and databases, Click Add.
20. Click Connect and type SQLAdmin11CluN2 in the Server name box, and Click
Connect.
21. In the Secondary Database drop down box, leave it to default .
22. On the Initialize Secondary Database tab you can choose the option that you want
to use to initialize the secondary database. Choose “Yes, generate a full backup of the
primary database and restore into the secondary database (and create the secondary
database if it doesn’t exist)”

Microsoft | Services © 2012 Microsoft Corporation ITOE Educate Workshop

Microsoft Confidential
Lesson 19: Log Shipping 7

Note: If you choose to have Management Studio initialize the secondary database
from a database backup, the data files created on the secondary server will have
the same names as those on the primary server, and will be created in an identical
directory structure, including the drive letter.

23. Click on the Copy Files tab.


24. In the Destination folder for copied files box, type the path of the folder as
\\SQLAdmin11CluN2\Logshipping\backups

This folder is usually located on the secondary server.


25. Click the Schedule button to adjust the copy job schedule.
26. Change the Copy Job schedule from 15 minutes to copy every 2 minutes.

27. Click on the Restore Transaction Log tab.


28. Under Database state when restoring backups, choose the Standby mode option.

Microsoft | Services © 2012 Microsoft Corporation ITOE Educate Workshop

Microsoft Confidential
8 Lesson 19: Log Shipping

Note: You can choose to delay the restore process on the secondary server by
selecting a delay time under Delay restoring backups at least x (Hours, Minutes,
or Days).

29. Choose an Alert threshold to alert if no restore occurs within 1 minute..


30. Customize the Restore Job schedule to restore every 3 minutes as shown below.

31. Click OK.


32. Under Monitor server instance, select the Use a monitor server instance check box,
and then click Settings.
33. Click Connect to the SQLAdmin11CluN1 instance of SQL Server as your monitor
server.
34. Under Monitor connections, choose the connection method to be used by the backup,
copy, and restore jobs to connect to the monitor server. For this lab leave it as the
default.

Microsoft | Services © 2012 Microsoft Corporation ITOE Educate Workshop

Microsoft Confidential
Lesson 19: Log Shipping 9

35. Under History retention, choose the length of time to retain a record of your log
shipping history as 24 hours.

36. Click OK.

Microsoft | Services © 2012 Microsoft Corporation ITOE Educate Workshop

Microsoft Confidential
10 Lesson 19: Log Shipping

37. Click OK to begin the configuration process.

Microsoft | Services © 2012 Microsoft Corporation ITOE Educate Workshop

Microsoft Confidential
Lesson 19: Log Shipping 11

38. Once you are successfully done, click Close


39. In Object Explorer connect to SQLAdmin11CluN2 and Open a New Query window.
40. Run this query to ensure the Log Shipping is in Sync state.
You can type this or open the script file located: L:\Features\Labs\Lesson 19 -
LogShipping\script3.sql on SQL11AdminWork.
USE LogShipping_Demo
GO

SELECT * FROM LStest

We are now going to disable the Log Shipping Jobs on the primary server.
41. In Object Explorer expand SQL SERVER Agent for SQLAdmin11CluN2
42. Double Click on Job Activity Monitor
43. In the Job Activity Monitor you will see 2 jobs in there that start with LS. One should
be LSCopy and one should be LSRestore. Right Click on each of these and choose
Disable Job. Click Close.
44. Now Open the new query window on SQLAdmin11CluN1and insert few more rows
in the dbo.lstest table with below query
You can type this or open the script file located: L:\Features\Labs\Lesson 19 -
LogShipping\script5.sql on SQL11AdminWork.
USE LogShipping_Demo
GO

INSERT INTO [dbo].[LStest]


([C1]
,[C2])
VALUES (1, 'Angel'),
(2, 'Abigel'),
(3, 'Rebecca'),
(4, 'Stevie'),
(5, 'Sabrina'),
(6, 'Madonna'),
(7, 'Liza'),
(8, 'Asma'),
(9, 'Prisha'),
(10, 'Jennifer')
GO 50000

45. Browse to "L:\Features\Labs\Lesson 19 - LogShipping\ " and Right-click the


FileMissing.cmd file and choose run as Administrator. Do not stop the script it will
take about 1-2 minutes to run.

Microsoft | Services © 2012 Microsoft Corporation ITOE Educate Workshop

Microsoft Confidential
12 Lesson 19: Log Shipping

This script will stop the SQL Server service on the Primary server and deletes the
Logshipping_Demo data file and restart the SQL Server which subsequently turns the
database in to Recovery Pending state.
In order to recover the database we need to take the transaction log backup and apply it to
the Secondary database using below commands:
46. In Object Explorer Refresh Databases for SQLAdmin11CluN1 after the script has
finished. You should see the log shipping database in Recovery Pending state now.

47. Open a new query window and execute the below query on SQLAdmin11CluN1
instance.
You can type this or open the script file located: L:\Features\Labs\Lesson 19 -
LogShipping\script6.sql on SQL11AdminWork.
BACKUP Log [logshipping_demo] TO DISK =
N'C:\logshipping\backups\taillog.trn' WITH No_Truncate
GO

48. Open a new query window and execute the below query on SQLAdmin11CluN2
instance.
You can type this or open the script file located: L:\Features\Labs\Lesson 19 -
LogShipping\script7.sql on SQL11AdminWork.
RESTORE LOG [Logshipping_Demo] FROM DISK =
N'\\sqladmin11clun1\logshipping\backups\taillog.trn' WITH FILE =
1, NOUNLOAD, STATS = 10
GO

Microsoft | Services © 2012 Microsoft Corporation ITOE Educate Workshop

Microsoft Confidential
Lesson 19: Log Shipping 13

If you get an error message about the log being too recent then check in this path for a
transaction log backup that may not have been applied:

\\SQLAdmin11CluN1\logshipping\backups

If it has not been applied apply this to the database first with NO RECOVERY specified
and then try and restore the tail log again.

Once the log restores are done if you refresh your databases on SQLAdmin11CluN2 you
will see the database is back up and running as the tail log restore command did not
specify with NoRecovery or anything and the default is to perform Recovery after a
restore so it recovers and then brings the database online all the way.

49. The final step should be to verify the health of the Log Shipping environment. Click
on the SQLAdmin11CluN1 root and Right-click and go to Reports | Standard
Reports | Transaction Log Shipping Status.

Question 1 – What is the health of the secondary LogShipping_Demo instance?


If there are any errors list them here:
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________

50. Run the same report on SQLAdmin11CluN2

Question 1 – What is the health of the primary LogShipping_Demo instance? If


there are any errors list them here:
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________

Microsoft | Services © 2012 Microsoft Corporation ITOE Educate Workshop

Microsoft Confidential

You might also like