快照:创建快照时,存储每个数据块的元数据记录将复制到快照中。占用很少的空间,快照创建得非常快。
快照常见的两种技术:
(1)第一次写时复制(也简称写时复制,英文简称:COW):每当覆盖一个数据块时,该块就会先被复制到快照中(称之为:快照空间),然后再将要写入的数据覆盖到该数据块中(备注:只有快照创建之后的第一次覆盖会有此复制行为产生)。相当于流程为: 读-->写-->写
优点:空间的高效利用,因为快照只需要保留发生过变化的数据块,与数据卷相比要小得多。
缺点:引起数据卷性能的下降,这是因为创建快照之后,对数据卷的写操作会增加一个等待的过程 –即旧数据块复制到快照空间的过程。另外一个关键问题是每个快照必须依赖一个完整的数据卷。
(2)写时重定向(英文简称:ROW):要写入的数据直接写入到快照中。即数据卷存放的是创建快照时间点的旧数据,新数据最终存放在预留的快照空间。
优点:只需要1次写即可实现快照,不需要像写时复制一样需要1读+2写,写入效率上有了提升。
缺点:被删除的快照上的数据必须被复制到原始数据卷,并且做一致性回退。创建的快照越多,维护快照的复杂度也会以指数级别上升。此外原始数据集中会产生大量的碎片。
备份:完整复制,数据块全部拷贝的方式。
如下是QNAP(该产品采用写时复制机制)对于快照和备份之间的区别的凝练总结:
What a snapshot does?
In short Snapshot is versioning, or the ability to undo a change. If you take a snapshot every hour, for example, then all your files or folders can be reverted back to the sate they were at the time of any of your snapshots. So, if you get a virus, then you can just revert your files, folders, or whole volume to the state it was in before you got the virus
How is this different than a backup?
A backup is a complete copy of your data. So, if you have 5TB of data each copy will take up an additional 5TB of data. If you made a backup every 1 hour, then after just 10 hours, your backups would take 50TB of space. For this reason, it is not common to save many versions of your backups and backups are not good for versioning.Snapshots are great for versioning because they are not backups and they can have many versions without taking up much space. A Snapshot only needs to save enough information to undo a change and that makes it take less space than a backup.
When are Snapshots Small?
When you only add files to the NAS, you don’t need to save blocks of data to the snapshot. The Snapshot just needs to have the metadata recording what blocks have been added to the NAS since the creation of the snapshot.
What makes Snapshots Big?
When you delete files, the snapshot needs to be able to restore the files you deleted. To do that, any block of data you delete and overwrite will be saved to the snapshot. Saving blocks of data to the snapshot takes much more space than just saving metadata. So, deleting files makes your snapshot size grow much more than adding file
Conclusion:
Most people delete some files and make some changes to their files, but not enough to make the snapshots get too big. You could never get close to this many complete backups without taking up huge amounts of space. That is why Snapshots are much better than backups for versioning. But snapshots don’t protect you from drive failure so it is still good to have RAID redundancy and at least one backup of your data to another device.