linux– 如何自动为Amazon EC2实例的卷创建快照?

linux– 如何自动为Amazon EC2实例的卷创建快照?,第1张

概述我正在尝试使用脚本自动备份卷.我按照github上的EBS-Snapshot.sh脚本进行 *** 作:#!/bin/bash # export EC2_HOME='/etc/ec2' # Make sure you use the API tools, not the AMI tools # export EC2_BIN=$EC2_HOME/bin # exp

我正在尝试使用脚本自动备份卷.

我按照github上的EBS-Snapshot.sh脚本进行 *** 作:

#!/bin/bash# export EC2_HOME='/etc/ec2'  # Make sure you use the API tools,not the AMI tools# export EC2_BIN=$EC2_HOME/bin# export PATH=$PATH:$EC2_BIN# I kNow all of the above is good to have solution,but not re-usable# I have captured all of the above in a particular file and lemme execute itsource /etc/environmentPURGE_SNAPSHOT_IN_DAYS=10EC2_BIN=$EC2_HOME/bin# store the certificates and private key to your amazon accountMY_CERT='/path/to/certificate-file'MY_KEY='/path/to/private-file'# fetching the instance-ID from the Metadata repositoryMY_INSTANCE_ID='your ec2-instance-ID'# temproary fileTMP_file='/tmp/rock-ebs-info.txt'# get List of locally attached volumes via EC2 API:$EC2_BIN/ec2-describe-volumes -C $MY_CERT -K $MY_KEY > $TMP_fileVolUME_List=$(cat $TMP_file | grep ${MY_INSTANCE_ID} | awk '{ print  }')sync#create the snapshotsecho "Create EBS Volume Snapshot - Process started at $(date +%m-%d-%Y-%T)"echo ""echo $VolUME_Listfor volume in $(echo $VolUME_List); do   name=$(cat $TMP_file | grep name | grep $volume | awk '{ print  }')   DESC=$name-$(date +%m-%d-%Y)   echo "Creating Snapshot for the volume: $volume with description: $DESC"   echo "Snapshot info below:"   $EC2_BIN/ec2-create-snapshot -C $MY_CERT -K $MY_KEY -d $DESC $volume   echo ""doneecho "Process ended at $(date +%m-%d-%Y-%T)"echo ""rm -f $TMP_file#remove those snapshot which are $PURGE_SNAPSHOT_IN_DAYS old

我有两个用于X509身份验证的文件,实例ID,但我不了解脚本以及如何参数化我要备份的卷.

我不明白第一行(源)和EC2_BIN.
通过该配置,它列出了所有这些卷并创建了所有这些卷的快照……

对于快照的注释,如何更改此行以添加文本?

DESC=$name-$(date +%m-%d-%Y)

我很抱歉成为一名初学者,但我不明白整个剧本

编辑:

我用这个新代码得到了这个错误:

Creating Snapshot for the volume: ([ec2-describe-volumes]) with
description: -03-13-2012 Snapshot info below:
ClIEnt.InvalIDParameterValue: Value (([ec2-describe-volumes])) for
parameter volumeID is invalID. Expected: ‘vol-…’. Process ended at
03-13-2012-08:11:35 –

这是代码:

#!/bin/bash#Java home for debian default install path:export JAVA_HOME=/usr#add ec2 tools to default path#export PATH=~/.ec2/bin:$PATH#export EC2_HOME='/etc/ec2'  # Make sure you use the API tools,not the AMI toolsexport EC2_BIN=/usr/bin/#export PATH=$PATH:$EC2_BIN# I kNow all of the above is good to have solution,but not re-usable# I have captured all of the above in a particular file and lemme execute itsource /etc/environmentPURGE_SNAPSHOT_IN_DAYS=60#EC2_BIN=$EC2_HOME/bin# store the certificates and private key to your amazon accountMY_CERT='cert-xx.pem'MY_KEY='pk-xx.pem'# fetching the instance-ID from the Metadata repositoryMY_INSTANCE_ID=`curl http://169.254.169.254/1.0/Meta-data/instance-ID`# temproary fileTMP_file='/tmp/rock-ebs-info.txt'# get List of locally attached volumes via EC2 API:$EC2_BIN/ec2-describe-volumes -C $MY_CERT -K $MY_KEY > $TMP_file#VolUME_List=$(cat $TMP_file | grep ${MY_INSTANCE_ID} | awk '{ print  }')VolUME_List=(`ec2-describe-volumes --filter attachment.instance-ID=$MY_INSTANCE_ID | awk '{ print  }'`)sync#create the snapshotsecho "Create EBS Volume Snapshot - Process started at $(date +%m-%d-%Y-%T)"echo ""echo $VolUME_Listecho "-------------"for volume in $(echo $VolUME_List); do   name=$(cat $TMP_file | grep name | grep $volume | awk '{ print  }')   DESC=$name-$(date +%m-%d-%Y)   echo "Creating Snapshot for the volume: $volume with description: $DESC"   echo "Snapshot info below:"   $EC2_BIN/ec2-create-snapshot -C $MY_CERT -K $MY_KEY -d $DESC $volume   echo ""doneecho "Process ended at $(date +%m-%d-%Y-%T)"echo ""rm -f $TMP_file#remove those snapshot which are $PURGE_SNAPSHOT_IN_DAYS old
最佳答案好吧好吧,

>他跑的第一行(来源).那是一样的.在/ etc /环境.无论如何,他所做的只是加载一个文件,其中包含亚马逊所需的环境变量列表.至少这是我的假设.
>他使这个脚本比它需要的复杂得多.他不需要运行ec2-describe-instances命令并将输出保存到文件然后grep输出等….
>你可以把任何你想要的东西放到DESC.您可以将=右侧的所有内容替换为您想要的任何文本.只要确保在它周围加上引号.

我会改变关于这个脚本的两件事.

>在脚本中运行时获取InstanceID.不要硬编码到脚本中.无论脚本在何处运行,此行都将起作用.

MY_INSTANCE_ID=`curl http://169.254.169.254/1.0/Meta-data/instance-ID`

>而不是调用ec2-describe-volumes并将输出保存到临时文件等…只需在命令上使用过滤器并告诉它您想要的实例ID.

VolUME_List=(`ec2-describe-volumes --filter attachment.instance-ID=$MY_INSTANCE_ID | awk '{ print  }'`)
总结

以上是内存溢出为你收集整理的linux – 如何自动为Amazon EC2实例的卷创建快照?全部内容,希望文章能够帮你解决linux – 如何自动为Amazon EC2实例的卷创建快照?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/1047129.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存