在SQL SEVER 2000中还原数据库到指定POINT。


我自己并没有实验成功。当restore dabase之后,进行restore log是,总提示我还有一个更早的backup可用,但是实际上是没有这个所谓的更早的backup的。

使用是需要注意两点:

1. 数据库必须是Full Reconvery模式的,可以在数据库的属性页中设置。
2. 必须在server的管理中的backup节点创建一个backup device。

SQL Server Exercises / SQL Server 2000 / Using STOPATMARK and STOPBEFOREMARK in SQL Server 2000

Using STOPATMARK and STOPBEFOREMARK in SQL Server 2000

Restore Your Database to a Point in Time At a Transactional Level

Description:

In this exercise we are going to do a point in time recovery using the STOPATMARK and STOPBEFOREMARK clauses. This will allow us to recover the database right down to an individual transaction - or immediately prior to a given transaction. This probably won't be used very much in production environments, but in test and development environments, these RESTORE clauses can be handy to take the database to a point in time prior to an event that had negative results.

(back to top)

Requirements:

  • As with all of the exercises on this site, do not perform this exercise on a production server.  Perform this exercise in a closed development environment
  • The database needs to be using the Full Recovery Model - for the exercise on changing the recovery model, click here
  • You will need to have a backup device already created - for the exercise on creating a backup device, click here

(back to top)

Setup:

None.

(back to top)

GUI Steps:

There are no GUI steps for this exercise. This exercise is T-SQL intensive, and I don't believe that there is a way to recover to marks using solely GUI interfaces.

(back to top)

T-SQL Steps:

 

1) Backup the Northwind database as shown below

Query analyzer screen shot of command BACKUP DATABASE Northwind TO markingdev WITH NAME = 'MARK FULL'  

 

2) Get a Transaction Log backup of the database

 Screen shot in query analyzer using the BACKUP LOG statement to do a transaction log backup

 

3) In Query Analyzer, add multiple rows to the shippers table. Two of the inserts below are within a marked transaction. SQL Server 2000 is autocommit by default - but when you are using marked transactions, you must explicitly end any transaction (usually with a COMMIT or ROLLBACK) which is why we have a COMMIT statement.

Screen shot in query analyzer of repeated INSERT statements that includes a transaction delineated with the BEGIN TRANSACTION and COMMIT TRANSACTION statements

 

4) Query the shippers table so that we know what the table currently looks like

Query Analyzer screen shot of querying the shippers table in the Northwind database

 

5) Get another transaction log backup so that we'll be able to recover right up to the mark or right after the mark

Query Analyzer screen shot of a transaction log backup in the Northwind database  

 

6) While connected to Northwind in Query Analyzer, determine which files we are going to delete by using exec sp_helpfile. We're going to delete both the transaction log and the data file.

Query Analyzer screen shot - using sp_helpfile to determine file locations for the Northwind database

 

7) In Query Analyzer, shut down the database.

Query Analyzer screen shot of shutting down the database using the SHUTDOWN WITH NOWAIT statement

 

8) In the operating system, delete the files that we found in step 6.

9) Right click on the SQL Server icon in the systray and select "MSSQL Server - Start"

10) Find the file numbers on the device that we need to restore. Note that the only backups on the marking device are the ones that we just did.

Query Analyzer screen shot using RESTORE HEADERONLY command to determine the files required for the RESTORE DATABASE statement  

 

11) Now we're going to do the first of our two restores. First restore using STOPBEFOREMARK. We are using the STANDBY statement to put the database in read-only mode, but we'll still be able to perform further transaction log restores.

Query Analyzer screen shot using RESTORE DATABASE with the STANDBY and STOPBEFOREMARK options  

 

12) Now query the shippers table. From Step 3, you can see that Company1 and Company2 were inserted before the TIMETOMARK transaction. They are both present as we expected they would be.

Query Analyzer screen shot of the shippers table in the Northwind database being queried

 

13) Now we're going to move further on and use STOPATMARK and leave the database operational after our recovery.

Query Analyzer screen shot using the RESTORE LOG statement with the STOPATMARK option

 

14) Querying the shippers table, we can see that STOPATMARK has restored all rows that were committed during the STOPATMARK transaction, but no transactions that occurred after this point. Company5 is missing from the result set as we knew it would be when we included the STOPATMARK in our restore statement.

Querying the shippers table in the Northwind database

 

Our STOPBEFOREMARK, STOPATMARK operations are complete.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值