从快照恢复卷
假设我有一个带有附加 EBS 卷的 AMI。
我还有一张快照。
我想将 EBS 卷“恢复”到快照。
执行此操作的最佳流程是什么?
Let's say I have an AMI with an attached EBS Volume.
I also have a snapshot.
I want to "restore" the EBS Volume to the snapshot.
What's the best process to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我不知道有什么方法可以“恢复”附加卷,但我的方法是从快照创建一个卷,然后分离原始卷并附加新卷。
I don't know of a way that you can 'restore' an attached volume, but the way i would do it is to create a volume from the snapshot, then detach the original and attach the new one.
如果您有一个正在运行的 EC2 实例,并且想要将其恢复到先前快照中捕获的状态,那么您需要停止该实例,分离其当前卷,从快照创建一个新卷,将新卷附加到您的实例。实例,然后重新启动您的实例。此外,在指定新卷的可用区域以及分离/重新附加卷时的设备名称方面存在一些微妙之处。
如果您从命令行而不是从 AWS Web UI 执行此操作,则可能更容易查看逻辑。
以下 bash 脚本不适合生产使用,因为它缺乏任何错误检查,并且仅使用
sleep
而不是轮询来确保 AWS 命令已完成。但它确实成功执行了所有这些步骤:If you have a running EC2 instance, and you want to restore it to the state captured in an earlier snapshot, then you need to stop the instance, detach its current volume, create a new volume from the snapshot, attach the new volume to your instance, and restart your instance. Furthermore, there are a couple subtleties around specifying the availability zone of the new volume, and the device name when detaching/re-attaching the volume.
The logic might easier to see if you do it from the command line, instead of from the AWS web UI.
The following bash script is not fit for production use, since it lacks any error-checking and it just uses
sleep
instead of polling to ensure AWS commands have completed. But it does perform all these steps successfully:我已经修改了 @algal 提供的脚本,以使用 aws cli 和轮询而不是睡眠。它还将查找给定卷的最新快照。
如果您想了解此脚本的最新情况或做出贡献:
https://github.com/karimtabet/ ebs_snapshot_recovery
I have touched up the script provided by @algal to use the aws cli and polling instead of sleep. It will also look for the latest snapshot of the given volume.
If you'd like to stay up to date with this script or contribute:
https://github.com/karimtabet/ebs_snapshot_recovery
要将附加到实例的卷替换为从快照创建的新卷:
To replace a volume attached to an instance with a new volume created from a snapshot:
从快照创建一个卷,以将该卷挂载到现有 EC2 计算机上并从中复制文件。
检查 EC2 机器。
创建一个卷。
o 大小必须大于快照大小(免费微实例获得 8GB 卷)。
o 可用区必须与 EC2 机器的可用区相同。
o 快照已被选择,或多或少类似于 snap12345678 - 我的描述。
附加卷。
Make a volume from the snapshot to mount the volume on an existing EC2 machine and copy files from it.
Check the EC2 machine.
Create a volume.
o The Size must be bigger than the snapshot size (free micro-instances get an 8GB volume).
o The Availability Zone must be the same as the EC2 machine’s.
o The Snapshot is already selected, more or less like snap12345678 - my description.
Attach the volume.