Home > Sql Server > SQL Server 数据库快照(Database Snapshot)

SQL Server 数据库快照(Database Snapshot)

A database snapshot is a read-only, static view of a database (the source database). Multiple snapshots can exist on a source database and always reside on the same server instance as the database. Each database snapshot is transactionally consistent with the source database as of the moment of the snapshot’s creation. A snapshot persists until it is explicitly dropped by the database owner.

数据库快照(Database snapshot)是一个只读的,静态的数据库视图。一个数据库可以有多个数据库快照,每个数据库快照在被显性的删除之前将一直存在。数据库快照将保持和源数据库快照被创建时刻一致,所以可被用来做一些报表。并且由于数据库快照的存在,我们可以很容易的把数据库回复到快照创建时刻。

  • 创建一个Snapshot.

CREATE DATABASE zhimaData_dbss ON

( NAME = zhimaData, FILENAME =

‘C:\Test.ss’ )
AS SNAPSHOT OF zhimaData;
GO
  • 删除更容易啦.
Drop database zhimaData_dbss
Go
  • 利用snapshot 来恢复database

USE master;
RESTORE DATABASE zhimaData FROM DATABASE_SNAPSHOT = ‘zhimaData_dbss’;
GO

How Database Snapshots Work

Understanding how snapshots work is helpful though not essential to using them. Database snapshots operate at the data-page level. Before a page of the source database is modified for the first time,

sql server snapshots

the original page is copied from the source database to the snapshot. This process is called a copy-on-write operation. The snapshot stores the original page, preserving the data records as they existed when the snapshot was created. Subsequent updates to records in a modified page do not affect the contents of the snapshot. The same process is repeated for every page that is being modified for the first time. In this way, the snapshot preserves the original pages for all data records that have ever been modified since the snapshot was taken.

To store the copied original pages, the snapshot uses one or more sparse files. Initially, a sparse file is an essentially empty file that contains no user data and has not yet been allocated disk space for user data. As more and more pages are updated in the source database, the size of the file grows. When a snapshot is taken, the sparse file takes up little disk space. As the database is updated over time, however, a sparse file can grow into a very large file. For more information about sparse files, see Understanding Sparse File Sizes in Database Snapshots.



Categories: Sql Server Tags: ,
  1. June 24th, 2010 at 12:04 | #1

    Nice post and this fill someone in on helped me alot in my college assignement. Say thank you you seeking your information.

  1. No trackbacks yet.