自动创建和管理 EC2 EBS 快照的脚本

发布于 2024-10-07 20:55:33 字数 176 浏览 5 评论 0原文

自动执行 EBS 卷 (2) 的(每日)快照并管理它们的最佳方式是什么?

我所说的“管理”是指我正在寻找一个脚本,它不仅可以创建每日备份(我猜测将涉及 cron 作业),而且还可以删除早于 x 天的快照,以避免过多的数据使用。

我相信这样的脚本确实存在于某个地方,但我似乎无法确定一个。

What is the best way to automate (daily) snapshots of my EBS volumes (2) and manage them.

By 'manage' I mean that I am looking for a script that will not only create daily backups (I am guessing a cron job will be involved) but that will also delete snapshots that are older than x days so as to avoid excessive data usage.

I believe that such scripts do exist somewhere out there but I cant seem to pin one down.

Ty

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

み零 2024-10-14 20:55:33

我在 http://awsmissingtools.com 使用了类似的开源工具 - “ec2-automate-backup”工具按如下方式运行时“ec2-automate-backup -s tag -t Backup-true -k 14 -p”将备份带有标签 Backup=true 的所有 EBS 卷,并将设置这些快照在 -k 天后删除 - 您可以使用 -k 14 将快照保留 14 天,或者使用 -k 365 将快照保留一整年。

I've used a similar open-source tool at http://awsmissingtools.com - the "ec2-automate-backup" tool when run as follows "ec2-automate-backup -s tag -t Backup-true -k 14 -p" will backup all EBS volumes with the tag Backup=true and will set these snapshots to be removed after -k days - you could keep snapshots for 14 days by using -k 14 or keep snapshots for an entire year by using -k 365.

爱殇璃 2024-10-14 20:55:33

我确信这种脚本还有其他实现,但这是我的:

http://www.capsunlock.net/2009/10/deleting-old-ebs-snapshots.html

I'm sure there are other implementation of this kind of script but here's mine:

http://www.capsunlock.net/2009/10/deleting-old-ebs-snapshots.html

风和你 2024-10-14 20:55:33

我遇到了同样的问题。结果我创建了一个特殊的脚本。如果您的服务器上安装了 PHP,您可以执行以下操作。

该脚本不仅会按照您设置的时间间隔创建备份,还会删除指定的较旧的快照。

  1. 打开与您的服务器的 SSH 连接。
  2. 导航到文件夹

    <前><代码>$ cd /usr/local/

  3. 将此要点克隆到 ec2 文件夹

    $ git 克隆 https://gist.github.com/9738785.git ec2
    
  4. 转到该文件夹​​

    <前><代码>$ cd ec2

  5. ​​

    使 backup.php 可执行

    <前><代码>$ chmod +x backup.php

  6. 打开 发布 AWS PHP SDK github 项目并复制 aws.zip 按钮的 URL。现在将其下载到您的服务器中。

    $ wget https://github.com/aws/aws-sdk-php/releases/download/2.6.0/aws.zip
    
  7. 将此文件解压缩到 aws 目录中。

    $ unzip aws.zip -d aws 
    
  8. 编辑backup.php php文件并在5-12行中设置所有设置

    <前><代码>$dryrun = FALSE;
    $interval = '24 小时';
    $keep_for = '10 天';
    $volumes = array('vol-********');
    $api_key = '************************';
    $api_secret = '****************************************';
    $ec2_region = 'us-east-1';
    $snap_descr = "每日备份";

  9. 测试它。运行此脚本

    <前><代码>$ ./backup.php

    测试快照已创建。 测试一下

  10. 如果一切正常,只需添加 cronjob。

    <前><代码>* 23 * * * /usr/local/ec2/backup.php

I was running into the same problem. As a result I create a special script. If you have PHP installed on your server here is what you can do.

This script will not only create backup with interval you set, but delete snapshots that are older that indicated.

  1. Open SSH connection to your server.
  2. Navigate to folder

    $ cd /usr/local/
    
  3. Clon this gist into ec2 folder

    $ git clone https://gist.github.com/9738785.git ec2
    
  4. Go to that folder

    $ cd ec2
    
  5. Make backup.php executable

    $ chmod +x backup.php
    
  6. Open releases of the AWS PHP SDK github project and copy URL of aws.zip button. Now download it into your server.

    $ wget https://github.com/aws/aws-sdk-php/releases/download/2.6.0/aws.zip
    
  7. Unzip this file into aws directory.

    $ unzip aws.zip -d aws 
    
  8. Edit backup.php php file and set all settings in line 5-12

    $dryrun     = FALSE;
    $interval   = '24 hours';
    $keep_for   = '10 Days';
    $volumes    = array('vol-********');
    $api_key    = '*********************';
    $api_secret = '****************************************';
    $ec2_region = 'us-east-1';
    $snap_descr = "Daily backup";
    
  9. Test it. Run this script

    $ ./backup.php
    

    Test is snapshot was created.

  10. If everything is ok just add cronjob.

    * 23 * * * /usr/local/ec2/backup.php
    
鹿港巷口少年归 2024-10-14 20:55:33

我遇到很多人在寻找管理 EBS 快照的工具。我在互联网上找到了一些工具,但它们只是脚本和不完整的解决方案。最后我决定创建一个更加灵活、集中且易于管理的程序。

这个想法是有一个集中式程序来管理所有 EBS 快照(实例本地或远程)

我创建了一个小型 Perl 程序, https://github.com/sciclon/EBS_Snapshots

一些功能:
* 程序以守护程序模式或脚本模式(crontab)运行

  • 您也可以仅选择本地附加卷或远程

  • 您可以定义日志文件< /p>

  • 您可以为每个卷定义快照数量

  • 您可以为每个卷定义快照的频率

  • 当达到删除最旧快照的限制时,频率和数量将像“循环”一样工作。

  • 您可以一步重新调整数量,我的意思是,如果您有 6 个快照,并且您修改了 3 个快照的数量,该过程将自动重新调整。

  • 您可以定义一个“规定”执行,您可以在执行快照之前添加要执行的代码,例如您想尝试卸载卷或停止某些服务,或者可能检查实例负载。父进程会等待退出码,“0”表示成功,您可以根据退出码定义是否继续。

    • 您可以定义一个“postscript”执行来在拍摄快照后执行任何脚本(例如告诉您相关信息的电子邮件)

    • 您可以添加“受保护的快照”来跳过您定义的快照,我的意思是它们将处于“只读”状态并且永远不会被删除。

    当脚本在守护进程模式下运行时,您可以“即时”重新配置脚本,脚本接受信号和 IPC。

    它有一个“本地缓存”以避免多次请求 API。您可以添加或修改配置文件中的任何配置并重新加载,而无需终止进程。

I came across with many people looking for a tool to administrate the EBS snapshots. I found several tools in Internet but they were just scripts and incomplete solutions. Finally I decided to create a program more flexible, centralized and easy to administrate.

The idea is to have a centralized program to rule all the EBS snapshots (local to the instance or remotes)

I have created a small Perl program, https://github.com/sciclon/EBS_Snapshots

Some features:
* Program runs in daemon mode or script mode (crontab)

  • You can chose only local attached volumes or remotes as well

  • You can define log file

  • You can define for each volume quantity of snapshots

  • You can define for each volume the frequency among them

  • Frequency and quantity will work like a "round-robin" when it reaches the limit removing the oldest snapshot.

  • you can readjust in one step the quantity I mean if you have 6 snapshots and you modify the quantity in 3 the process will readjust it automatically.

  • You can define a "prescript" execution, You can add your code to execute before executing the snapshot, for example you would like to try to umount the volume or stop some service, or maybe to check the instance load. The parent process will wait for the exit code, "0" means success, you can define if continue or not depending on the exit code.

    • You can define a "postscript" execution to execute any scrip after taking the snapshot (for example a email telling you about it)

    • You can add "Protected Snapshots" to skip the snapshot you define, I mean they will be in "read only" and they will never been erased.

    you can reconfigure the script "on the fly" when it is running in daemon mode, the script accepts signals and IPC.

    It has a "local-cache" to avoid requesting the API several times. You can add or modify any configuration in the config file and reload without killing the process.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文