storage snapshot-存储快照
2012-09-19 13:52:51 阿炯

In computer systems, a snapshot is the state of a system at a particular point in time. The term was coined as an analogy to that in photography. It can refer to an actual copy of the state of a system or to a capability provided by certain systems.

Rationale(基本原理)

A full backup of a large data set may take a long time to complete. On multi-tasking or multi-user systems, there may be writes to that data while it is being backed up. This prevents the backup from being atomic and introduces a version skew that may result in data corruption. For example, if a user moves a file into a directory that has already been backed up, then that file would be completely missing on the backup media, since the backup operation had already taken place before the addition of the file. Version skew may also cause corruption with files which change their size or contents underfoot while being read.

One approach to safely backing up live data is to temporarily disable write access to data during the backup, either by stopping the accessing applications or by using the locking API provided by the operating system to enforce exclusive read access. This is tolerable for low-availability systems (on desktop computers and small workgroup servers, on which regular downtime is acceptable). High-availability 24/7 systems, however, cannot bear service stoppages.

To avoid downtime, high-availability systems may instead perform the backup on a snapshot—a read-only copy of the data set frozen at a point in time—and allow applications to continue writing to their data. Most snapshot implementations are efficient and can create snapshots in O(1). In other words, the time and I/O needed to create the snapshot does not increase with the size of the data set, whereas the same for a direct backup is proportional to the size of the data set. In some systems once the initial snapshot is taken of a data set, subsequent snapshots copy the changed data only, and use a system of pointers to reference the initial snapshot. This method of pointer-based snapshots consumes less disk capacity than if the data set was repeatedly cloned.

Read-write snapshots are sometimes called branching snapshots, because they implicitly create diverging versions of their data. Aside from backups and data recovery, read-write snapshots are frequently used in virtualization, sandboxing and virtual hosting setups because of their usefulness in managing changes to large sets of files.

Volume managers
Some Unix systems have snapshot-capable logical volume managers. These implement copy-on-write on entire block devices by copying changed blocks—just before they are to be overwritten—to other storage, thus preserving a self-consistent past image of the block device. Filesystems on this image can later be mounted as if it were on read-only media.

Snapshots, Clones, Mirrors & Replicas

Application data is the intellectual property of most organizations today, and continuous data access is vital for ongoing operations.

Snapshots are space-efficient, any-point-in-time copies of changed bits or volumes, achieving time, cost and capacity efficiency. Snapshots can be read-only or read-write copies of files, LUNs, file systems or any other type of container.

Clones closely resemble snapshots, as they are bit-identical copies of full volumes, and thus require the same storage capacity as the primary volume.

Synchronous and asynchronous replication creates a second copy of volumes and snapshots to capture continuous changes. Synchronous replication is used by mission critical environments to ensure application consistency, an RPO of no data loss and RTO of seconds, scalability and highest performance SLA’s. Asynchronous replication is used when RTOs of seconds to 30 minutes or longer are allowable.

Disk mirroring is replication within locally connected disks, and is the fault-tolerant mechanism used to define RAID policies.

Key Benefits

High levels of data protection, recoverability and availability while maximizing uptime

Automated and synchronized data copies through the combination of replication, snapshot, clone and mirroring technologies best suited to each application

Replication, snapshot, clone and mirroring techniques that ensure application consistency for databases, email and hypervisors

Zero data loss, recovery point objectives (RPOs) of seconds, and continuous data protection without impacting performance

Cost-effective data protection and load balancing

SNIA(存储网络行业协会)对快照(Snapshot)的定义是:关于指定数据集合的一个完全可用拷贝,该拷贝包括相应数据在某个时间点(拷贝开始的时间点)的映像。快照可以是其所表示的数据的一个副本,也可以是数据的一个复制品。
目前snapshot技术分为:

镜像分离(split mirror)
镜像分离,是为了让镜像卷保持拆分一瞬间的状态,而不再继续被写入数据。而拆分之后,主卷所做的所有写IO动作,会以bitmap的方式记录下来。bitmap就是一份位图文件,文件中每个位都表示卷上的一个块(扇区,或者由多个扇区组成的逻辑块),如果这个块在镜像分离之后,被写入了数据,则程序就将bitmap文件中对应的位从0变成1。待备份完成之后,可以将镜像关系恢复,此时主卷和镜像卷上的数据是不一致的,需要重新做同步。程序搜索bitmap中所有为1的位,对应到卷上的块,然后将这些块上的数据,同步到镜像卷,从而恢复实时镜像关系。

改变块(changed block)
快照创建成功后,源和快照共享同一份物理数据拷贝,直到数据发生写操作,此时源上老数据或者新增数据将被写向新的存储空间。为了记录和追踪块的变化和复制信息,需要一个位图(bitmap),它用于确定实际拷贝数据的位置,以及确定从源还是目标来获取数据。

并发(concurrent)
它与改变块非常相似,但它总是物理地拷贝数据。当即时拷贝执行时,没有数据被复制。取而代之,它创建一个位图来记录数据的复制情况,并在后台进行真正的数据物理复制。由改变块和并发发展而来的写时复制(copy-on-write,COW)和写重定向(Redirect-on-write,ROW)目前还是比较主流的。

写时复制(copy-on-write,COW)
写时复制快照在快照时间点之后,没有物理数据复制发生,仅仅复制了原始数据物理位置的元数据。因此,快照创建非常快,可以瞬间完成。然后,快照副本跟踪原始卷的数据变化(即原始卷写操作),一旦原始卷数据块发生写操作,则先将原始卷数据块读出并写入快照卷,然后用新数据块覆盖原始卷。这样我们访问快照卷上的数据仍旧是写操作前的,可以保证我们备份数据的一致性。


写重定向(Redirect-on-write,ROW)
对于原始数据卷的首次写操作将被重定向到预留的快照空间。该快照维持的是指向所有源数据的指针和拷贝数据。当数据被重写时,将会给更新过的数据选择一个新的位置,同时指向该数据的指针也被重新映射,指向更新后的数据。如果拷贝是只读的,那么指向该数据的指针就根本不会被修改。重定向写操作提升了快照I/O 性能,只需一次写操作,直接将新数据写入快照卷,同时更新位图映射指针;而写时拷贝需要一次读和两次写操作,即将原始卷数据块读入并写入快照卷,然后将更新数据写入原始卷。不难发现,快照卷保存的是原始副本,而原始卷保存的则是快照副本。这导致删除快照前需要将快照卷中的数据同步至原始卷,而且当创建多个快照后,原始数据的访问、快照卷和原始卷数据的追踪以及快照的删除将变得异常复杂。此外,快照副本依赖与原始副本,原始副本数据集很快变得分散。