Professional Documents
Culture Documents
019 - SQL - Server - 2012 - Features - For - Admins - Lesson 19 - Log - Shipping - Lab - Manual
019 - SQL - Server - 2012 - Features - For - Admins - Lesson 19 - Log - Shipping - Lab - Manual
019 - SQL - Server - 2012 - Features - For - Admins - Lesson 19 - Log - Shipping - Lab - Manual
Microsoft Confidential
2 Lesson 19: Log Shipping
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.
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 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
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 Confidential
4 Lesson 19: 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 Confidential
Lesson 19: Log Shipping 5
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 Confidential
6 Lesson 19: Log Shipping
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.
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).
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.
Microsoft Confidential
10 Lesson 19: Log Shipping
Microsoft Confidential
Lesson 19: Log Shipping 11
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
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 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.
Microsoft Confidential