-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathServerDefaultLocations.sql
More file actions
68 lines (58 loc) · 2.02 KB
/
Copy pathServerDefaultLocations.sql
File metadata and controls
68 lines (58 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
CREATE TABLE #MDFFiles (MyFile varchar(200))
CREATE TABLE #LDFFiles (MyFile varchar(200))
CREATE TABLE #FileLocations (
[ServerName] varchar(64),
[MasterDBLogPath] varchar(512),
[MasterDBPath] varchar(512),
[BackupDir] varchar(512),
[ErrorLogPath] varchar(512),
[RootDirectory] varchar(512)
)
declare @RegPathParams sysname
declare @Arg sysname
declare @Param sysname
declare @MasterPath nvarchar(512)
declare @LogPath nvarchar(512)
declare @ErrorLogPath nvarchar(512)
declare @n int
select @n=0
select @RegPathParams=N'Software\Microsoft\MSSQLServer\MSSQLServer'+'\Parameters'
select @Param='dummy'
while(not @Param is null)
begin
select @Param=null
select @Arg='SqlArg'+convert(nvarchar,@n)
exec master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE', @RegPathParams, @Arg, @Param OUTPUT
if(@Param like '-d%')
begin
select @Param=substring(@Param, 3, 255)
select @MasterPath=substring(@Param, 1, len(@Param) - charindex('\', reverse(@Param)))
end
else if(@Param like '-l%')
begin
select @Param=substring(@Param, 3, 255)
select @LogPath=substring(@Param, 1, len(@Param) - charindex('\', reverse(@Param)))
end
else if(@Param like '-e%')
begin
select @Param=substring(@Param, 3, 255)
select @ErrorLogPath=substring(@Param, 1, len(@Param) - charindex('\', reverse(@Param)))
end
select @n=@n+1
end
declare @SmoRoot nvarchar(512)
exec master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\Setup', N'SQLPath', @SmoRoot OUTPUT
DECLARE @BackupLoc nvarchar(255)
EXECUTE master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\MSSQLServer', N'BackupDirectory', @param = @BackupLoc OUTPUT
INSERT #FileLocations
SELECT
CAST(SERVERPROPERTY(N'MachineName') AS sysname) AS [ServerName],
@LogPath AS [MasterDBLogPath],
@MasterPath AS [MasterDBPath],
@BackupLoc AS [BackupDir],
@ErrorLogPath AS [ErrorLogPath],
@SmoRoot AS [RootDirectory]
select * from #FileLocations
DROP TABLE #MDFFiles
DROP TABLE #LDFFiles
DROP TABLE #FileLocations