正确的拍照方法
我以前问过这个问题,但我仍然很困惑。拍摄快照的正确且最快的方法是什么(我只使用 EBS 支持的 Unix 和 Windows 机器,所以这就是我现在的全部兴趣)。一些想法:
- 只需拍摄快照...这似乎有时会导致系统损坏。
- 停止机器,拍摄快照,然后启动机器。我想这也意味着我需要等待每个单独的任务完成,这使得脚本编写有点挑战?
- 拍摄设置了“重新启动计算机”标志的快照。文档中几乎没有说明为什么需要重新启动...
希望 EC2 专家可以帮助我。
I've asked this question before, but I am still confused. What's the correct and quickest way to take a snapshot (I only use EBS-backed Unix and Windows machines, so that's all my interest right now). Some ideas:
- Just take the snapshot... This seems to sometimes cause system corruption.
- Stop the machine, take the snapshot and then start the machine. I guess this also means I need to wait for each individual task to complete, making scirpting a bit of a challenge?
- Take a snapshot with the 'reboot machine' flag set. There is very little in the documentation to specify why a reboot is needed...
Hope you EC2 experts can help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果可以接受一点数据丢失,则只需在实例运行时拍摄快照即可。
如果这是不可接受的,请编写一些脚本魔法以确保应用程序正在处理的所有内容都保存到磁盘,拍摄快照,然后让您的应用程序恢复工作。
对于我所做的,我发现最好保留一个单独的 EBS 卷,其中包含我的应用程序及其数据,当我需要快照时,我只需停止应用程序一会儿,拍摄快照,然后将其重新启动。这样,您就不必担心操作系统在快照期间正在做什么,而且它还具有额外的好处,能够快速将您的应用程序及其数据移动到更强大的硬件,并拥有更小的快照。
If a bit of data loss is acceptable, just take the snapshot while the instance is running.
If it's not acceptable, write some script magic to ensure everything your application is working on is saved to disk, take the snapshot, then let your app resume work.
For what I do, I find it best to keep a separate EBS volume with my application and its data on it, and when I need a snapshot, I just stop the app for a moment, snapshot, and fire it back up. That way you don't have to worry about what the OS is doing during the snapshot, and it also comes with the added bonuses of being able to quickly move your app and its data to more powerful hardware, and having much smaller snapshots.
快速回答 - 两种操作系统都具有安全卸载驱动器的功能。可以对未安装的驱动器进行快照,而不必担心损坏。
长答案
EBS 快照是时间点和差异的(它本身不会“复制”您的数据),因此只要您的驱动器在开始时处于一致且可恢复的状态,您就可以避免损坏(因为快照是原子的)。
正如您所暗示的,无论整个驱动器启动时处于什么状态,这就是您的快照映像在恢复时的状态(如果您在写入文件一半时进行快照,那么天哪,该文件恢复时会写到一半)。
对于 Linux 和 Windows,可以通过卸载驱动器来实现一致的状态。这将保证您的缓冲区被刷新到磁盘并且不会发生写入。在 Linux 和 Windows 中,都有命令列出哪些进程正在使用该驱动器;一旦您停止这些进程或以其他方式让它们停止将驱动器标记为使用(每个程序/服务不同),您就可以卸载。在 Windows 中,通过将驱动器设置为“可移动驱动器”,然后使用“安全删除硬件”功能进行卸载,这非常容易。在linux中,可以使用“umount”命令卸载。
还有其他更偷偷摸摸的方法,但上面的方法相当普遍。
因此,假设您在开始之前达到可恢复状态,则快照启动后您就可以恢复使用驱动器(您无需等待快照完成后再解锁(或重新安装)并恢复使用)。此时您可以重新安装该卷。
AWS快照的工作原理:
您的卷和快照只是一组指针,当您拍摄快照时,您只需将从该点开始写入的任何块分开即可;它们实际上是与卷关联的新块,并且卷中该逻辑位置处的旧块保持不变,以便快照在逻辑上保持相同。
这也是为什么后续快照往往会变得更快(它们是有差异的)。
http://harish11g.blogspot.com /2013/04/understanding-Amazon-Elastic-block-store-EBS-snapshots.html
Quick answer - both operating systems have features for safely unmounting the drive. An unmounted drive can be snapshotted without fear of corruption.
Long answer
An EBS snapshot is point-in-time and differential (it does not "copy" your data per-se), so as long as your drive is in a consistent and restorable state when it begins, you'll avoid the corruption (since the snapshot is atomic).
As you have implied, whatever state the whole drive is in when it starts, that's what your snapshot image will be when it is restored (if you snapshot while you are half-way done writing a file, then, by-golly, that file will be half-written when you restore).
For both Linux and Windows, a consistent state can be this can be acheived by unmounting the drive. This will guarantee that your buffers are flushed to disk and no writes can occur. In both linux and windows there are commands to list which processes are using the drive; once you have stopped those processes or otherwise gotten them to stop marking the drive for use (different for each program/service), you can unmount. In windows, this is very easy by setting your drive as a "removable drive" and then using the "safely remove hardware" feature to unmount. In linux, you can unmount with the "umount" command.
There are other sneakier ways, but the above is pretty universal.
So assuming you get to a restorable state before you begin, you can resume using your drive as soon as the snapshot starts (you do not need to wait for the snapshot completes before you unlock (or remount) and resume use). At that point you can remount the volume.
How AWS snapshot works:
Your volume and the snapshot is just a set of pointers, when you take a snapshot, you just diverge any blocks that you write to from that point forward; they are effectively new blocks associated with the volume, and the old blocks at that logical place in the volume are left alone so that the snapshot stays the same logically.
This is also why subsequent snapshots will tend to go faster (they are differential).
http://harish11g.blogspot.com/2013/04/understanding-Amazon-Elastic-block-store-EBS-snapshots.html
拍摄快照通常需要安排停机时间。
步骤:
Afaik,这是获得一致快照的唯一可行方法。
如果您可以分享有关快照上的数据类型的更多信息(例如数据库?),那么我可能可以扩展我的答案。
我无法评论基于 Windows 的实例,因为我对它一点也不熟悉,但为了避免冗余,请查看此博客条目的解释,因为它解释了很多:
在简而言之,他们使用 xfs 文件系统,当他们冻结它来创建快照时,他们允许对文件系统的更新通过。根据评论,它似乎对大多数人都有效。
Taking a snapshot often requires scheduled downtime.
Procedure:
Afaik, the only viable way for a consistent snapshot.
If you could share more about what kind of data is on the snapshot (e.g. a database?), then I could probably extend my answer.
I cannot comment on Windows-based instances since I'm not at all familiar with it but in order to avoid redundancy, check out this blog entry explains as it explains a lot:
In a nutshell, they use the
xfs
file system and when they freeze it to create the snapshot, they allow updates to the filesystem to pass. According to the comments, it seems to work for most people.