Home Database Mysql Tutorial 查询谁修改了数据库的恢复模式

查询谁修改了数据库的恢复模式

Jun 07, 2016 pm 03:23 PM
c++ Revise recover database Inquire model programming Enter

欢迎进入C/C++编程社区论坛,与300万技术人员互动交流 >>进入 在QQ群里面有人说自己的数据库恢复模式自动被修改了,但是没有JOB也没有人修改,问我是否查出到底发生了什么。 其实在SQL Server Error Log里面会记录数据库恢复模式被更改的信息。比如我运行下

欢迎进入C/C++编程社区论坛,与300万技术人员互动交流 >>进入

  在QQ群里面有人说自己的数据库恢复模式自动被修改了,但是没有JOB也没有人修改,问我是否查出到底发生了什么。

  其实在SQL Server Error Log里面会记录数据库恢复模式被更改的信息。比如我运行下面的脚本:

  alter database sql2008 set recovery simple

  go

  alter database sql2008 set recovery full

  然后用sp_readerrorlog可以看到下面的信息:

  2013-09-1309:57:45.200        spid51      Settingdatabase option RECOVERY to SIMPLEfor database sql2008.

  2013-09-1309:57:48.980        spid51      Settingdatabase option RECOVERY to FULLfor database sql2008.

  可以看到Error Log获得的信息比较少无法确切知道当时是谁执行的,命令代码,应用程序是什么。但是在Default Trace中会记录对象的变更,事件类为 164,修改数据库的恢复模式也会被记录到这个事件。如果将Default Trace和Error Log的信息结合起来,就可以获得更为详细的资料,从而找到当时运行的脚本,用户名,应用程序名称。

  这里面有一个问题,默认情况下sp_readerrorlog只获得当前的错误日志,但是可能错误信息不在这个日志里面。所以下面的脚本使用存储过程sp_enumerrorlogs循环所有的日志文件。

  脚本如下:

  --查询所有的错误日志文件找到修改Recovery Mode的信息,由于Error Log肯能被Recycle,

  --所以我们用Undocomented存储过程mastersp_enumerrorlogs循环所有的错误日志文件

  set nocount on

  declare @searchString1 varchar(255)

  declare @searchString2 varchar(255)

  set @searchString1 = 'RECOVERY'

  set @searchString2 = 'OPTION'

  declare @logs table (LogNo int, StartDate Datetime, FileSize int)

  declare @results table (LogFileNo int, LogDate  Datetime, ProcessInfovarchar(20),Text varchar(max))

  insert into @logs EXEC mastersp_enumerrorlogs

  declare cLogs cursor for select LogNo from @logs

  declare @LogNo int

  open cLogs

  fetch cLogs into @LogNo

  while @@fetch_status =0

  begin

  insertinto @results(LogDate, ProcessInfo, Text)

  EXECsp_readerrorlog@LogNo,1, @searchString1,@searchString2

  update@resultsset LogFileNo =@LogNowhere LogFileNo isnull

  fetchcLogsinto @LogNo

  end

  deallocate cLogs

  select * from @results

  ---循环所有的DefaultTrace文件

  declare @logFile varchar(max)

  set @logFile =(select path from sys.traces where is_default=1)

  set @logFile = left(@logFile,len(@LogFile) - charindex('_',reverse(@LogFile))) + '.trc'

  --将日志文件和Trace文件关联,这样就可以获得当时修改Recovery Mode的代码,LoginID,HOSTNAME 等等。

  select starttime,*

  from fn_trace_gettable(@logFile,null) t

  join @results r on  t.StartTime between dateadd(ms,-150,r.logDate) and dateadd(ms,150,r.logdate)

  andt.spid = substring(r.ProcessInfo,5,10) --required to enable ahash join to be used

  where t.EventClass = 164

  and EventsubClass = 1

查询谁修改了数据库的恢复模式

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1269
29
C# Tutorial
1248
24
C# vs. C  : History, Evolution, and Future Prospects C# vs. C : History, Evolution, and Future Prospects Apr 19, 2025 am 12:07 AM

The history and evolution of C# and C are unique, and the future prospects are also different. 1.C was invented by BjarneStroustrup in 1983 to introduce object-oriented programming into the C language. Its evolution process includes multiple standardizations, such as C 11 introducing auto keywords and lambda expressions, C 20 introducing concepts and coroutines, and will focus on performance and system-level programming in the future. 2.C# was released by Microsoft in 2000. Combining the advantages of C and Java, its evolution focuses on simplicity and productivity. For example, C#2.0 introduced generics and C#5.0 introduced asynchronous programming, which will focus on developers' productivity and cloud computing in the future.

Golang and C  : Concurrency vs. Raw Speed Golang and C : Concurrency vs. Raw Speed Apr 21, 2025 am 12:16 AM

Golang is better than C in concurrency, while C is better than Golang in raw speed. 1) Golang achieves efficient concurrency through goroutine and channel, which is suitable for handling a large number of concurrent tasks. 2)C Through compiler optimization and standard library, it provides high performance close to hardware, suitable for applications that require extreme optimization.

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

MySQL: Structured Data and Relational Databases MySQL: Structured Data and Relational Databases Apr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

Python vs. C  : Learning Curves and Ease of Use Python vs. C : Learning Curves and Ease of Use Apr 19, 2025 am 12:20 AM

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.

Golang vs. C  : Performance and Speed Comparison Golang vs. C : Performance and Speed Comparison Apr 21, 2025 am 12:13 AM

Golang is suitable for rapid development and concurrent scenarios, and C is suitable for scenarios where extreme performance and low-level control are required. 1) Golang improves performance through garbage collection and concurrency mechanisms, and is suitable for high-concurrency Web service development. 2) C achieves the ultimate performance through manual memory management and compiler optimization, and is suitable for embedded system development.

Golang and C  : The Trade-offs in Performance Golang and C : The Trade-offs in Performance Apr 17, 2025 am 12:18 AM

The performance differences between Golang and C are mainly reflected in memory management, compilation optimization and runtime efficiency. 1) Golang's garbage collection mechanism is convenient but may affect performance, 2) C's manual memory management and compiler optimization are more efficient in recursive computing.

MySQL: A Beginner-Friendly Approach to Data Storage MySQL: A Beginner-Friendly Approach to Data Storage Apr 17, 2025 am 12:21 AM

MySQL is suitable for beginners because it is easy to use and powerful. 1.MySQL is a relational database, and uses SQL for CRUD operations. 2. It is simple to install and requires the root user password to be configured. 3. Use INSERT, UPDATE, DELETE, and SELECT to perform data operations. 4. ORDERBY, WHERE and JOIN can be used for complex queries. 5. Debugging requires checking the syntax and use EXPLAIN to analyze the query. 6. Optimization suggestions include using indexes, choosing the right data type and good programming habits.

See all articles