1+ /* #info
2+
3+ # Autor
4+ Rodrigo Ribeiro Gomes
5+
6+ # Detalhes
7+
8+ Não lembro o motivo de ter criado isso, mas deve ter sido algum teste pontual.
9+ De qualquer maneira, deixando ai pois tem algumas sintaxes e comandos que podem ser úteis algum dia (mesmo que pra lembrar rápido)
10+ */
11+
12+ /*
13+ Uses following select to estimamte
14+ */
15+ select * ,MaxRollover = TotalRequiredSizeMB/ SingleFileMB from (
16+ select * ,TotalRequiredSizeMB = ((Lsec* RetentionTime* BytesPerL)/ 1024 .00 / 1024 .00 )* 1 .3 from (
17+ select
18+ Lsec = (pc .cntr_value * 1 .00 / datediff(ss,i .sqlserver_start_time ,current_timestamp ))* 2
19+ ,BytesPerL = 15 * 1024
20+ ,RetentionTime = 3600 * 24 * 7 -- 7days
21+ ,SingleFileMB = 100
22+ from sys .dm_os_performance_counters pc
23+ cross join sys .dm_os_sys_info i
24+ where counter_name like ' %logins%'
25+ ) T
26+ ) e
27+
28+
29+ CREATE SERVER AUDIT
30+ AuditLogins
31+ TO
32+ FILE (
33+ FILEPATH = ' D:\T races\A udit'
34+ ,MAXSIZE = 100MB
35+ ,MAX_ROLLOVER_FILES = 600
36+ )
37+ WHERE
38+ server_principal_name != ' LOGIN_AUDIT'
39+ OR
40+ succeeded = 0
41+
42+
43+
44+ CREATE SERVER AUDIT SPECIFICATION AuditAllLogins
45+ FOR SERVER AUDIT AuditLogins
46+ ADD (FAILED_LOGIN_GROUP)
47+ ,ADD(SUCCESSFUL_LOGIN_GROUP)
48+ with (state = on )
49+
50+
51+ ALTER SERVER AUDIT AuditLogins WITH(STATE = on )
52+
53+
54+ select * from sys .dm_server_audit_status
55+
56+ select server_principal_name,statement
57+ ,convert (xml,additional_information)
58+ ,*
59+ from sys .fn_get_audit_file (' D:\T races\A udit\A uditLogins_*.sqlaudit' ,null ,null ) af
60+ join sys .dm_audit_class_type_map tm
61+ on tm .class_type = af .class_type
62+ order by event_time desc
63+
64+ select * from
65+ xp_cmdshell ' del /q D:\T races\A udit\* '
66+ sp_configure ' xp_cmdshell' ,1
67+ reconfigure
68+
69+
70+
0 commit comments