linux – 运行Ubuntu的EBS支持的EC2实例的自动快照

我正在运行一个 EBS-backed instance,它充当软件开发团队的构建服务器(运行Jenkins和其他服务的主机).服务器正在运行Linux(最新的Ubuntu来自 official AMIs).

我想对实例关联的EBS卷进行定期的自动快照.我只需要保留一个最新的备份(即旧的快照应该被修剪),并且一个好的频率将是每天一次.

亚马逊似乎没有提供开箱即用的备份服务,因此您必须使用第三方脚本或推出自己的解决方案.

我的问题是,实现这一目标的最简单方法是什么?我想要最少量的麻烦,配置和外部依赖.据我所知,将此设置为Linux机箱上的某种定时脚本是一个有效的选项.

解决方法

基于Jonik的概念,我使用boto创建了一个python脚本.您可以为快照提供卷列表,以及为每个卷保留多少尾随快照:
# Define the snapshots manage. We'll snapshot the specified volume ID,and only keep the X newest ones.
snapshots = [("vol-XXXXXXXX",30),("vol-YYYYYYYY",180)]

import boto.ec2
auth = {"aws_access_key_id": "YOURACCESSKEY","aws_secret_access_key": "YOURSECRETKEY"}
ec2 = boto.ec2.connect_to_region("YOURREGIONNAME",**auth)
description = "automated backup"
for volume,num_trailing in snapshots:
  snaps = ec2.get_all_snapshots(filters={"volume-id": volume,"description": description})
  print "%s: Creating new snapshot. %s automated snapshots currently exist." % (volume,len(snaps))
  ec2.create_snapshot(volume,description)
  purgeable = sorted(snaps,key=lambda x: x.start_time)[:-num_trailing]
  print "Deleting snapshots for %s > %s: %s" % (volume,num_trailing,purgeable)
  for snap in purgeable:
    ec2.delete_snapshot(snap.id)

我将其设置为Jenkins作业(通过Python插件),配置为每天运行.如果您使用IAM来管理凭据,请注意这将需要ec2策略:DescribeRegions,DescribeVolumes,CreateSnapshot,DeleteSnapshot,DescribeSnapshots,CreateTags(因为boto的实现).

相关文章

查找全部容器的日志文件 $ sudo find /var/lib/docker/conta...
Linux日志文件中列属性的详细解析
在Linux系统中没有duf命令,如何有效地管理磁盘空间?
深入探讨EncryptPad在Linux操作系统中的功能和优势
原理和应用场景:Linux中ttyload工具的工作原理和实际用途
深度解析SELinux的三种策略类型