在 Windows Server 2012 AWS EC2 实例上没有停机的一致 EBS 快照

Consistent EBS snapshot without downtime on a Windows Server 2012 AWS EC2 instance

我有一个 AWS EC2 Windows Server 2012 R2 实例,带有磁性 EBS 卷 D:\(Windows SO 在 C:\ 上)。

我的服务器在 D:\ 上工作,每次在 D:\temp 中写入一些临时文件(会话文件、缓存等)并在 D:\htdocs 中读取一些静态文件。

我需要在不停机的情况下每天对 EBS 卷做一个一致的快照

关于这个问题很多人说:

Snapshot EBS if the volume is in use it is possible but not recommended

来自official documentation

You can take a snapshot of an attached volume that is in use. However, snapshots only capture data that has been written to your Amazon EBS volume at the time the snapshot command is issued. If you can pause any file writes to the volume long enough to take a snapshot, your snapshot should be complete.

here:

EBS volumes and snapshots operate at a block level - a consequence of which allows snapshots to be taken while an instance is running, even if the EBS volume is in use. However, only data that is actually on the disk (i.e. not in a file cache) will be included in the snapshot. It is the latter reason that gives rise to the idea of consistent snapshots. The recommended way is to detach the volume, snapshot it, and reattach it

我的问题是: 如果快照不一致,因为我做的时候有写操作,我可以重新挂载吗?因为只有写入的文件是临时文件,但它们对我来说并不重要,如果损坏了,我可以简单地删除它们吗(在我重新安装快照后)?我唯一的目标是保证静态文件的安全。

如果您创建了快照,您将能够从中创建一个卷,并且可以毫无问题地重新安装它。

HOWEVER:不能保证卷中的数据是一致的。

考虑这种情况:您将一个 1 MB 的文件提交到一个 SSD 支持的 EBS 卷。这将需要 4 x 256k IO 操作。所以前 3 个完成,然后拍摄快照,然后写入第 4 个块。

您将能够从您的快照创建卷,但您的文件大小仅为 768k - 最终块将不存在,因为它是在快照创建后写入的。

如果您可以控制写入磁盘的内容,暂停它并刷新所有缓存确实是确保生成的快照上的数据一致的唯一方法。