Skip to content

Commit 26041a3

Browse files
committed
Adding LogShipping Project
Adding LogShipping Project
1 parent b059010 commit 26041a3

21 files changed

+829
-21
lines changed
13 KB
Binary file not shown.

Backup-Restore/Backup-Restore.ssmssqlproj

+21-9
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,26 @@
2727
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
2828
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
2929
</ConnectionNode>
30+
<ConnectionNode Name="SQL-B:sa">
31+
<Created>2018-04-02T13:11:19.2341396+05:30</Created>
32+
<Type>SQL</Type>
33+
<Server>SQL-B</Server>
34+
<UserName>sa</UserName>
35+
<Authentication>SQL</Authentication>
36+
<InitialDB>WhoIsActive</InitialDB>
37+
<LoginTimeout>30</LoginTimeout>
38+
<ExecutionTimeout>0</ExecutionTimeout>
39+
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
40+
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
41+
</ConnectionNode>
3042
</Items>
3143
</LogicalFolder>
3244
<LogicalFolder Name="Queries" Type="0" Sorted="true">
3345
<Items>
3446
<FileNode Name="1) Generate - Backup Script.sql">
35-
<AssociatedConnectionMoniker />
36-
<AssociatedConnSrvName />
37-
<AssociatedConnUserName />
47+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:SQL-B:False:sa</AssociatedConnectionMoniker>
48+
<AssociatedConnSrvName>SQL-B</AssociatedConnSrvName>
49+
<AssociatedConnUserName>sa</AssociatedConnUserName>
3850
<FullPath>1) Generate - Backup Script.sql</FullPath>
3951
</FileNode>
4052
<FileNode Name="2) Script Out DB Permissions in case of DB Refresh.sql">
@@ -44,9 +56,9 @@
4456
<FullPath>2) Script Out DB Permissions in case of DB Refresh.sql</FullPath>
4557
</FileNode>
4658
<FileNode Name="3) Generate - Restore Script.sql">
47-
<AssociatedConnectionMoniker />
48-
<AssociatedConnSrvName />
49-
<AssociatedConnUserName />
59+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:SQL-A:False:sa</AssociatedConnectionMoniker>
60+
<AssociatedConnSrvName>SQL-A</AssociatedConnSrvName>
61+
<AssociatedConnUserName>sa</AssociatedConnUserName>
5062
<FullPath>3) Generate - Restore Script.sql</FullPath>
5163
</FileNode>
5264
<FileNode Name="4) Script Out DB_Owner from Source.sql">
@@ -92,9 +104,9 @@
92104
<FullPath>Query - Backup History.sql</FullPath>
93105
</FileNode>
94106
<FileNode Name="Query - Restore History.sql">
95-
<AssociatedConnectionMoniker />
96-
<AssociatedConnSrvName />
97-
<AssociatedConnUserName />
107+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:SQL-B:False:sa</AssociatedConnectionMoniker>
108+
<AssociatedConnSrvName>SQL-B</AssociatedConnSrvName>
109+
<AssociatedConnUserName>sa</AssociatedConnUserName>
98110
<FullPath>Query - Restore History.sql</FullPath>
99111
</FileNode>
100112
</Items>

BlitzQueries/BlitzQueries.ssmssqlproj

+29-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,30 @@
1515
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
1616
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
1717
</ConnectionNode>
18+
<ConnectionNode Name="BAN-2ADWIVEDI-L:SA">
19+
<Created>2018-04-01T16:04:10.5753003+05:30</Created>
20+
<Type>SQL</Type>
21+
<Server>BAN-2ADWIVEDI-L</Server>
22+
<UserName>SA</UserName>
23+
<Authentication>SQL</Authentication>
24+
<InitialDB />
25+
<LoginTimeout>30</LoginTimeout>
26+
<ExecutionTimeout>0</ExecutionTimeout>
27+
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
28+
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
29+
</ConnectionNode>
30+
<ConnectionNode Name="TUL1DBAPMTDB1:CORPORATE\adwivedi">
31+
<Created>2018-04-01T15:45:55.25382+05:30</Created>
32+
<Type>SQL</Type>
33+
<Server>TUL1DBAPMTDB1</Server>
34+
<UserName />
35+
<Authentication>Windows Authentication</Authentication>
36+
<InitialDB />
37+
<LoginTimeout>30</LoginTimeout>
38+
<ExecutionTimeout>0</ExecutionTimeout>
39+
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
40+
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
41+
</ConnectionNode>
1842
</Items>
1943
</LogicalFolder>
2044
<LogicalFolder Name="Queries" Type="0" Sorted="true">
@@ -56,9 +80,9 @@
5680
<FullPath>CREATE TABLE [dbo].[whatIsRunning].sql</FullPath>
5781
</FileNode>
5882
<FileNode Name="Other queries.sql">
59-
<AssociatedConnectionMoniker />
60-
<AssociatedConnSrvName />
61-
<AssociatedConnUserName />
83+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:BAN-2ADWIVEDI-L:False:SA</AssociatedConnectionMoniker>
84+
<AssociatedConnSrvName>BAN-2ADWIVEDI-L</AssociatedConnSrvName>
85+
<AssociatedConnUserName>SA</AssociatedConnUserName>
6286
<FullPath>Other queries.sql</FullPath>
6387
</FileNode>
6488
<FileNode Name="Perf Counters.sql">
@@ -86,8 +110,8 @@
86110
<FullPath>who_is_active_v11_30(Modified).sql</FullPath>
87111
</FileNode>
88112
<FileNode Name="whoIsActive.sql">
89-
<AssociatedConnectionMoniker />
90-
<AssociatedConnSrvName />
113+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:TUL1DBAPMTDB1:True</AssociatedConnectionMoniker>
114+
<AssociatedConnSrvName>TUL1DBAPMTDB1</AssociatedConnSrvName>
91115
<AssociatedConnUserName />
92116
<FullPath>whoIsActive.sql</FullPath>
93117
</FileNode>

BlitzQueries/Other queries.sql

+16
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ SELECT @@servername as SvrName,
88
DATEDIFF(day,create_date, GETDATE()) as ServiceStartDays
99
FROM sys.databases as d where d.name = 'tempdb';
1010

11+
-- Get Socket, Physical Core, and Logical Core count from SQL Server Error Log
12+
EXEC master..xp_readerrorlog 0,1, N'Server process ID is'
13+
EXEC master..xp_readerrorlog 0,1, N'System Manufacturer:', N'System Model'
14+
EXEC master..xp_readerrorlog 0,1, N'sockets',N'processors'
15+
EXEC master..xp_readerrorlog 0,1, N'Instant File Initialization'
16+
EXEC master..xp_readerrorlog 0,1, N'Server is listening on'
17+
EXEC master..xp_readerrorlog 0,1, N'Dedicated admin connection support'
18+
19+
-- Hardware Information from SQL Server 2016
20+
SELECT i.cpu_count as [Logical_CPU_Count], physical_memory_kb/1024 as [Physical Memory(MB)], i.virtual_machine_type_desc
21+
,i.sqlserver_start_time
22+
FROM sys.dm_os_sys_info as i;
23+
24+
-- Check Enabled Trace Flags
25+
DBCC TRACESTATUS(-1);
26+
1127
-- Check if compatibility Model of databases are up to date
1228
SELECT * FROM sys.databases as d
1329
WHERE d.compatibility_level NOT IN (SELECT d1.compatibility_level FROM sys.databases as d1 WHERE d1.name = 'model');

LogShipping/LogShipping.sql

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
-- http://www.sqlservercentral.com/articles/Administration/customlogshipping/1201/
2+
3+
/* Step 01 -> Perform Full Backup */
4+
BACKUP DATABASE [LSTesting]
5+
TO DISK = '\\DC\Backups\SQL-A\LSTesting_FullBackup_01Apr2018.bak'
6+
GO
7+
8+
BACKUP LOG [LSTesting]
9+
TO DISK = '\\DC\Backups\SQL-A\LSTesting_TLog_01Apr2018.trn'
10+
GO
11+
12+
/* Step 02 -> Restore Full & TLog in NORECOVERY */
13+
RESTORE DATABASE [LSTesting]
14+
FROM DISK = '\\DC\Backups\SQL-A\LSTesting_FullBackup_01Apr2018.bak'
15+
WITH NORECOVERY, REPLACE
16+
GO
17+
18+
RESTORE LOG [LSTesting]
19+
FROM DISK = N'\\DC\Backups\SQL-A\master_TLog_2Apr2018_1246AM.trn'
20+
--WITH NORECOVERY
21+
GO
22+
23+
/* Step 03 -> Restore Full & TLog in NORECOVERY */
24+
RESTORE DATABASE [LSTesting]
25+
WITH STANDBY = 'E:\LS_UndoFiles\LSTesting_undo.tuf'
26+
GO
27+
28+
29+
-- Find Log Shipping Jobs
30+
SELECT *
31+
FROM msdb..sysjobs as j
32+
WHERE j.category_id = 6;
33+
34+
-- Get variety of messages related to Log Shipping
35+
SELECT *
36+
FROM msdb.sys.sysmessages as m
37+
WHERE m.description LIKE '%Shipping%'
38+
AND m.msglangid = 1033
39+
40+
-- Look for text in SQL Server Error Log
41+
EXEC sys.xp_readerrorlog 0,1,'The log shipping primary database',NULL

LogShipping/LogShipping.ssmssqlproj

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0"?>
2+
<SqlWorkbenchSqlProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="LogShipping">
3+
<Items>
4+
<LogicalFolder Name="Connections" Type="2" Sorted="true">
5+
<Items>
6+
<ConnectionNode Name="SQL-A:sa">
7+
<Created>2018-04-02T07:53:24.6936396+05:30</Created>
8+
<Type>SQL</Type>
9+
<Server>SQL-A</Server>
10+
<UserName>sa</UserName>
11+
<Authentication>SQL</Authentication>
12+
<InitialDB />
13+
<LoginTimeout>30</LoginTimeout>
14+
<ExecutionTimeout>0</ExecutionTimeout>
15+
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
16+
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
17+
</ConnectionNode>
18+
<ConnectionNode Name="SQL-B:sa">
19+
<Created>2018-04-01T22:35:48.4348004+05:30</Created>
20+
<Type>SQL</Type>
21+
<Server>SQL-B</Server>
22+
<UserName>sa</UserName>
23+
<Authentication>SQL</Authentication>
24+
<InitialDB>WhoIsActive</InitialDB>
25+
<LoginTimeout>30</LoginTimeout>
26+
<ExecutionTimeout>0</ExecutionTimeout>
27+
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
28+
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
29+
</ConnectionNode>
30+
</Items>
31+
</LogicalFolder>
32+
<LogicalFolder Name="Queries" Type="0" Sorted="true">
33+
<Items>
34+
<FileNode Name="LogShipping.sql">
35+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:SQL-A:False:sa</AssociatedConnectionMoniker>
36+
<AssociatedConnSrvName>SQL-A</AssociatedConnSrvName>
37+
<AssociatedConnUserName>sa</AssociatedConnUserName>
38+
<FullPath>LogShipping.sql</FullPath>
39+
</FileNode>
40+
<FileNode Name="PerformBackup.sql">
41+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:SQL-A:False:sa</AssociatedConnectionMoniker>
42+
<AssociatedConnSrvName>SQL-A</AssociatedConnSrvName>
43+
<AssociatedConnUserName>sa</AssociatedConnUserName>
44+
<FullPath>PerformBackup.sql</FullPath>
45+
</FileNode>
46+
<FileNode Name="PerformRestore.sql">
47+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:SQL-B:False:sa</AssociatedConnectionMoniker>
48+
<AssociatedConnSrvName>SQL-B</AssociatedConnSrvName>
49+
<AssociatedConnUserName>sa</AssociatedConnUserName>
50+
<FullPath>PerformRestore.sql</FullPath>
51+
</FileNode>
52+
<FileNode Name="usp_DBAApplyTLogs.sql">
53+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:SQL-B:False:sa</AssociatedConnectionMoniker>
54+
<AssociatedConnSrvName>SQL-B</AssociatedConnSrvName>
55+
<AssociatedConnUserName>sa</AssociatedConnUserName>
56+
<FullPath>usp_DBAApplyTLogs.sql</FullPath>
57+
</FileNode>
58+
</Items>
59+
</LogicalFolder>
60+
<LogicalFolder Name="Miscellaneous" Type="3" Sorted="true">
61+
<Items />
62+
</LogicalFolder>
63+
</Items>
64+
</SqlWorkbenchSqlProject>

LogShipping/PerformBackup.sql

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
DECLARE @fileName VARCHAR(256) -- filename for backup
2+
DECLARE @fileDate VARCHAR(20) -- used for file name
3+
DECLARE @dbName VARCHAR(125) = 'LSTesting';
4+
DECLARE @backupPath VARCHAR(125) = '\\DC\Backups\SQL-A\';
5+
DECLARE @sqlString NVARCHAR(MAX);
6+
7+
SELECT @fileDate = DATENAME(DAY,GETDATE())+CAST(DATENAME(MONTH,GETDATE()) AS VARCHAR(3))
8+
+DATENAME(YEAR,GETDATE())+'_'+REPLACE(REPLACE(RIGHT(CONVERT(VARCHAR, GETDATE(), 100),7),':',''), ' ','0');
9+
SELECT @fileName = (SELECT @backupPath+@dbName+'_TLog_'+ @fileDate + '.trn');
10+
11+
SET @sqlString = '
12+
BACKUP LOG '+QUOTENAME(@dbName)+'
13+
TO DISK = '''+@fileName+'''';
14+
15+
EXEC (@sqlString);

LogShipping/PerformRestore.sql

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use master
2+
go
3+
-- Get all files of path
4+
exec xp_dirtree '\\DC\Backups\SQL-A',0,1;
5+
6+
/* Step 01 -> Restore Full & TLog in NORECOVERY */
7+
RESTORE DATABASE [LSTesting]
8+
FROM DISK = '\\DC\Backups\SQL-A\LSTesting_FullBackup_01Apr2018.bak'
9+
WITH NORECOVERY, REPLACE
10+
GO
11+
12+
RESTORE LOG [LSTesting]
13+
FROM DISK = N'\\DC\Backups\SQL-A\LSTesting_TLog_01Apr2018.trn'
14+
WITH NORECOVERY
15+
GO
16+
17+
/* Step 01 -> Restore Full & TLog in NORECOVERY */
18+
RESTORE DATABASE [LSTesting]
19+
WITH STANDBY = 'E:\LS_UndoFiles\LSTesting_undo.tuf'
20+
GO
21+
22+
EXEC master..[usp_DBAApplyTLogs] 'LSTesting', 'LSTesting', '\\DC\Backups\SQL-A\', @p_TUFLocation = 'E:\LS_UndoFiles' ,@p_Verbose = 1 ,@p_DryRun = 1
23+
24+
select d.create_date from sys.databases as d where d.name = 'LSTesting'

0 commit comments

Comments
 (0)