Skip to content

Commit e4f900a

Browse files
committed
Updated LogWalk Scripts
Updated LogWalk Scripts
1 parent 31e14fd commit e4f900a

20 files changed

+2667
-53
lines changed
0 Bytes
Binary file not shown.

Backup-Restore/3) Generate - Restore Script - BackupHistory.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
SET NOCOUNT ON;
22
-- Input 01
3-
DECLARE @p_Target_Data_Path varchar(255) = 'H:\MSSQLData\Data\';
3+
DECLARE @p_Target_Data_Path varchar(255) = 'J:\MSSQLData\Data\';
44
-- Input 02
5-
DECLARE @p_Target_Log_Path varchar(255) = 'E:\MSSQLData\Log\';
5+
DECLARE @p_Target_Log_Path varchar(255) = 'J:\MSSQLData\Logs\';
66
-- Input 03
77
DECLARE @p_RestoreType varchar(20) = 'Log'; /* Full/Diff/Log */
88
-- Input 04
99
DECLARE @p_Leave_in_NORECOVERY_Mode bit = 1; /* Recover Database, means, Bring Online */
1010
-- Input 05
1111
DECLARE @p_ReplaceExistingDatabase bit = 0;
1212
-- Input 06
13-
DECLARE @Databases nvarchar(max) = 'RCM_rovicore_20130710_NoMusic1a_en-US';
13+
DECLARE @Databases nvarchar(max) = 'Staging';
1414
/* -- https://ola.hallengren.com/sql-server-backup.html
1515
Select databases. The keywords SYSTEM_DATABASES, USER_DATABASES, ALL_DATABASES, and AVAILABILITY_GROUP_DATABASES are supported. The hyphen character (-) is used to exclude databases, and the percent character (%) is used for wildcard selection. All of these operations can be combined by using the comma (,).
1616
*/
1717

1818
-- Input 07
19-
DECLARE @p_Destination_ServerName VARCHAR(125) = 'YourDestinationServer';
19+
DECLARE @p_Destination_ServerName VARCHAR(125) = 'TUL1CIPXDB17';
2020
-- Input 08
21-
DECLARE @p_Destination_BackupLocation VARCHAR(255) = 'H:\backups\';
21+
DECLARE @p_Destination_BackupLocation VARCHAR(255) = 'F:\backups\';
2222
-- Input 09
2323
DECLARE @p_Generate_RoboCopy_4_Backups bit = 0;
2424

Backup-Restore/Backup-Restore.ssmssqlproj

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<LogicalFolder Name="Connections" Type="2" Sorted="true">
55
<Items>
66
<ConnectionNode Name="(local):CORPORATE\adwivedi">
7-
<Created>2019-08-27T10:15:39.8361802+05:30</Created>
7+
<Created>2019-08-26T23:45:39.8361802-05:00</Created>
88
<Type>SQL</Type>
99
<Server>(local)</Server>
1010
<UserName />
@@ -15,6 +15,42 @@
1515
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
1616
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
1717
</ConnectionNode>
18+
<ConnectionNode Name="LOCALHOST:CORPORATE\adwivedi">
19+
<Created>2019-10-08T07:32:23.4522102-05:00</Created>
20+
<Type>SQL</Type>
21+
<Server>LOCALHOST</Server>
22+
<UserName />
23+
<Authentication>Windows Authentication</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="TUL1CIPCNPDB1:CORPORATE\adwivedi">
31+
<Created>2019-10-09T05:43:05.9153233-05:00</Created>
32+
<Type>SQL</Type>
33+
<Server>TUL1CIPCNPDB1</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>
42+
<ConnectionNode Name="TUL1CIPXDB20:CORPORATE\adwivedi">
43+
<Created>2019-10-09T11:59:39.1977294-05:00</Created>
44+
<Type>SQL</Type>
45+
<Server>TUL1CIPXDB20</Server>
46+
<UserName />
47+
<Authentication>Windows Authentication</Authentication>
48+
<InitialDB>DBA</InitialDB>
49+
<LoginTimeout>30</LoginTimeout>
50+
<ExecutionTimeout>0</ExecutionTimeout>
51+
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
52+
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
53+
</ConnectionNode>
1854
</Items>
1955
</LogicalFolder>
2056
<LogicalFolder Name="Queries" Type="0" Sorted="true">
@@ -32,8 +68,8 @@
3268
<FullPath>2) Script Out DB Permissions in case of DB Refresh.sql</FullPath>
3369
</FileNode>
3470
<FileNode Name="3) Generate - Restore Script - BackupHistory.sql">
35-
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:(local):True</AssociatedConnectionMoniker>
36-
<AssociatedConnSrvName>(local)</AssociatedConnSrvName>
71+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:TUL1CIPCNPDB1:True</AssociatedConnectionMoniker>
72+
<AssociatedConnSrvName>TUL1CIPCNPDB1</AssociatedConnSrvName>
3773
<AssociatedConnUserName />
3874
<FullPath>3) Generate - Restore Script - BackupHistory.sql</FullPath>
3975
</FileNode>
@@ -92,8 +128,8 @@
92128
<FullPath>Query - Backup History - Path Finding.sql</FullPath>
93129
</FileNode>
94130
<FileNode Name="Query - Backup History.sql">
95-
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:(local):True</AssociatedConnectionMoniker>
96-
<AssociatedConnSrvName>(local)</AssociatedConnSrvName>
131+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:TUL1CIPCNPDB1:True</AssociatedConnectionMoniker>
132+
<AssociatedConnSrvName>TUL1CIPCNPDB1</AssociatedConnSrvName>
97133
<AssociatedConnUserName />
98134
<FullPath>Query - Backup History.sql</FullPath>
99135
</FileNode>
@@ -104,8 +140,8 @@
104140
<FullPath>Query - Restore History.sql</FullPath>
105141
</FileNode>
106142
<FileNode Name="RevLogin-Script.sql">
107-
<AssociatedConnectionMoniker />
108-
<AssociatedConnSrvName />
143+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:TUL1CIPXDB20:True</AssociatedConnectionMoniker>
144+
<AssociatedConnSrvName>TUL1CIPXDB20</AssociatedConnSrvName>
109145
<AssociatedConnUserName />
110146
<FullPath>RevLogin-Script.sql</FullPath>
111147
</FileNode>

Backup-Restore/Query - Backup History.sql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---------------------------------------------------------------------------------
22
--Database Backups for all databases For Previous Week
33
---------------------------------------------------------------------------------
4-
SELECT TOP (10) CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS SERVER
4+
SELECT TOP 100 CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS SERVER
55
,bs.database_name
66
,bs.backup_start_date
77
,bs.backup_finish_date
@@ -11,6 +11,8 @@ SELECT TOP (10) CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS SERVER
1111
THEN 'Database'
1212
WHEN 'L'
1313
THEN 'Log'
14+
WHEN 'I'
15+
THEN 'Diff'
1416
END AS backup_type
1517
,bs.backup_size
1618
,bmf.logical_device_name
@@ -24,6 +26,5 @@ SELECT TOP (10) CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS SERVER
2426
,is_copy_only
2527
FROM msdb.dbo.backupmediafamily AS bmf
2628
INNER JOIN msdb.dbo.backupset AS bs ON bmf.media_set_id = bs.media_set_id
27-
WHERE bs.type='D' and
28-
database_name = 'CMS'
29+
WHERE database_name = 'Staging'
2930
ORDER BY bs.backup_finish_date DESC
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
SELECT --j.name,
2+
'exec msdb..sp_start_job '''+j.name+'''
3+
GO
4+
'
5+
FROM msdb..sysjobs_view j
6+
WHERE j.name like 'DBA Log Walk%'
7+
AND j.enabled = 1
8+
9+
10+
SELECT d.name, d.recovery_model_desc
11+
FROM sys.databases d
12+
WHERE d.name IN ('AMG_Avg','AMG_Extra','AMG_Music','AMG_MusicMore','DSG_EU','Facebook','MuzeUK','MuzeVideo','RGS','Staging2','Twitter')
13+
ORDER BY d.recovery_model_desc, d.name
14+
15+
SELECT db_name(mf.database_id) as dbName, mf.physical_name
16+
FROM sys.master_files mf
17+
WHERE db_name(mf.database_id) in ('AMG_Avg','AMG_Extra','AMG_Music','AMG_MusicMore','DSG_EU','Facebook','MuzeUK','MuzeVideo','RGS','Staging2','Twitter')

BlitzQueries/BlitzQueries.ssmssqlproj

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<LogicalFolder Name="Connections" Type="2" Sorted="true">
55
<Items>
66
<ConnectionNode Name="(local):CORPORATE\adwivedi">
7-
<Created>2019-08-22T17:19:33.2581521+05:30</Created>
7+
<Created>2019-08-22T06:49:33.2581521-05:00</Created>
88
<Type>SQL</Type>
99
<Server>(local)</Server>
1010
<UserName />
@@ -15,8 +15,20 @@
1515
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
1616
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
1717
</ConnectionNode>
18+
<ConnectionNode Name="LOCALHOST:CORPORATE\adwivedi">
19+
<Created>2019-10-04T09:27:18.2935143-05:00</Created>
20+
<Type>SQL</Type>
21+
<Server>LOCALHOST</Server>
22+
<UserName />
23+
<Authentication>Windows Authentication</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>
1830
<ConnectionNode Name="tul1cipbksdb2:CORPORATE\adwivedi">
19-
<Created>2019-09-16T17:09:31.5964044+05:30</Created>
31+
<Created>2019-09-16T06:39:31.5964044-05:00</Created>
2032
<Type>SQL</Type>
2133
<Server>tul1cipbksdb2</Server>
2234
<UserName />
@@ -50,8 +62,8 @@
5062
<FullPath>blitzFirst.sql</FullPath>
5163
</FileNode>
5264
<FileNode Name="BlitzIndex.sql">
53-
<AssociatedConnectionMoniker />
54-
<AssociatedConnSrvName />
65+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:LOCALHOST:True</AssociatedConnectionMoniker>
66+
<AssociatedConnSrvName>LOCALHOST</AssociatedConnSrvName>
5567
<AssociatedConnUserName />
5668
<FullPath>BlitzIndex.sql</FullPath>
5769
</FileNode>
@@ -62,8 +74,8 @@
6274
<FullPath>Blocking Tree.sql</FullPath>
6375
</FileNode>
6476
<FileNode Name="Buffer-Pool-Analysis.sql">
65-
<AssociatedConnectionMoniker />
66-
<AssociatedConnSrvName />
77+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:LOCALHOST:True</AssociatedConnectionMoniker>
78+
<AssociatedConnSrvName>LOCALHOST</AssociatedConnSrvName>
6779
<AssociatedConnUserName />
6880
<FullPath>Buffer-Pool-Analysis.sql</FullPath>
6981
</FileNode>
@@ -97,9 +109,15 @@
97109
<AssociatedConnUserName />
98110
<FullPath>Detect n Reduce High VLFs.sql</FullPath>
99111
</FileNode>
112+
<FileNode Name="Fragmentation-Analysis.sql">
113+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:LOCALHOST:True</AssociatedConnectionMoniker>
114+
<AssociatedConnSrvName>LOCALHOST</AssociatedConnSrvName>
115+
<AssociatedConnUserName />
116+
<FullPath>Fragmentation-Analysis.sql</FullPath>
117+
</FileNode>
100118
<FileNode Name="Other queries.sql">
101-
<AssociatedConnectionMoniker />
102-
<AssociatedConnSrvName />
119+
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:LOCALHOST:True</AssociatedConnectionMoniker>
120+
<AssociatedConnSrvName>LOCALHOST</AssociatedConnSrvName>
103121
<AssociatedConnUserName />
104122
<FullPath>Other queries.sql</FullPath>
105123
</FileNode>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Script to Get Fragmentation Stats for All Dbs on Multiple Servers (in Parallel Jobs)
2+
$dbServers = @('TUL1CIPBIAPP1','TUL1CIPBIAPP2','TUL1CIPBIAPP3','TUL1CIPXDB18','TUL1SUB2008');
3+
4+
$dbQuery = @"
5+
select d.name
6+
from sys.databases as d
7+
where not(d.source_database_id IS NOT NULL or d.state_desc = 'OFFLINE' or d.database_id <= 4)
8+
"@;
9+
10+
$IndexQuery = @"
11+
select @@serverName as ServerName,
12+
db_name(ips.database_id) as DataBaseName,
13+
object_name(ips.object_id) as ObjectName,
14+
sch.name as SchemaName,
15+
ind.name as IndexName,
16+
ips.index_type_desc,
17+
avg_fragmentation_in_percent as avg_fragmentation,
18+
avg_page_space_used_in_percent,
19+
page_count,
20+
ps.row_count,
21+
STATS_DATE(ind.object_id, ind.index_id) AS StatsUpdated
22+
from sys.dm_db_index_physical_stats(DB_ID(),NULL,NULL,NULL,'LIMITED') as ips
23+
inner join sys.tables as tbl
24+
on ips.object_id = tbl.object_id
25+
inner join sys.schemas as sch
26+
on tbl.schema_id = sch.schema_id
27+
inner join sys.indexes as ind
28+
on ips.index_id = ind.index_id and
29+
ips.object_id = ind.object_id
30+
inner join sys.dm_db_partition_stats as ps
31+
on ps.object_id = ips.object_id and
32+
ps.index_id = ips.index_id
33+
where page_count >= 1000;
34+
"@;
35+
36+
foreach($srv in $dbServers) {
37+
Write-Host $srv -ForegroundColor DarkYellow;
38+
39+
# find databases from server
40+
$alldbs = Invoke-DbaQuery -SqlInstance $srv -Query $dbQuery | Select-Object -ExpandProperty name;
41+
42+
foreach($db in $alldbs) {
43+
Write-Host "`tJob started for [$srv].[$db]..." -ForegroundColor Green;
44+
$ScriptBlock = {
45+
param($srv, $db, $IndexQuery)
46+
Invoke-DbaQuery -SqlInstance $srv -Database $db -Query $IndexQuery -QueryTimeOut 3600
47+
}
48+
Start-Job -Name "IndexStats-$srv-$db" -ScriptBlock $ScriptBlock -ArgumentList $srv, $db, $IndexQuery;
49+
}
50+
} # Server loop
51+
Write-Host "Jobs created/started for each Server/Database pair." -ForegroundColor Green;
52+
53+
54+
$IndexAnalysisResult = @();
55+
do {
56+
# Find completed jobs, Retrieve Data, and Remove them
57+
$Jobs_Completed = Get-Job -Name IndexStats* | Where-Object {$_.State -eq 'Completed'};
58+
$IndexAnalysisResult += $Jobs_Completed | Receive-Job;
59+
$Jobs_Completed | Remove-Job;
60+
61+
# Wait for 10 seconds
62+
Start-Sleep -Seconds 10;
63+
$Jobs_Yet2Process = Get-Job -Name IndexStats* |
64+
Where-Object {$_.State -in ('NotStarted','Running','Suspending','Stopping')};
65+
}
66+
while($Jobs_Yet2Process -ne $null); # keep looping if jobs are still in progress
67+
68+
# Save to Excel
69+
$IndexAnalysisResult | Export-Excel -Path C:\Temp\IndexAnalysisResult.xlsx -WorksheetName 'IndexAnalysisResult';
70+
71+
# Find Jobs with Failures
72+
$Jobs_Issue = Get-Job -Name IndexStats* |
73+
Where-Object {$_.State -notin ('Completed','NotStarted','Running','Suspending','Stopping')};
74+
if($Jobs_Issue -ne $null) {
75+
Write-Host @"
76+
Some jobs failed. Execute below script
77+
`$Jobs_Yet2Process
78+
"@
79+
}
80+
81+
<#
82+
$excel = Import-Excel 'C:\temp\IndexAnalysisResult.xlsx'
83+
$i = 1
84+
$excel | select -Property ServerName, DatabaseName -Unique | ForEach-Object {
85+
$_ | Add-Member -NotePropertyName ID -NotePropertyValue $i -PassThru;
86+
$i += 1;
87+
} | ogv
88+
#>

0 commit comments

Comments
 (0)