Estoy intentando una secuencia de comandos para hacer una copia de seguridad de un volumen de forma automática.Cómo capturar automáticamente un volumen de una instancia de Amazon EC2?
que siga esta secuencia de comandos que se encuentran en EBS-Snapshot.sh
github:
#!/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 it
source /etc/environment
PURGE_SNAPSHOT_IN_DAYS=10
EC2_BIN=$EC2_HOME/bin
# store the certificates and private key to your amazon account
MY_CERT='/path/to/certificate-file'
MY_KEY='/path/to/private-file'
# fetching the instance-id from the metadata repository
MY_INSTANCE_ID='your ec2-instance-id'
# temproary file
TMP_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 $2 }')
sync
#create the snapshots
echo "Create EBS Volume Snapshot - Process started at $(date +%m-%d-%Y-%T)"
echo ""
echo $VOLUME_LIST
for volume in $(echo $VOLUME_LIST); do
NAME=$(cat $TMP_FILE | grep Name | grep $volume | awk '{ print $5 }')
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 ""
done
echo "Process ended at $(date +%m-%d-%Y-%T)"
echo ""
rm -f $TMP_FILE
#remove those snapshot which are $PURGE_SNAPSHOT_IN_DAYS old
tengo los dos archivos para la autenticación X509, el identificador de instancia, pero no entiendo el guión y cómo parametrizar el volumen que quiero hacer copias de seguridad.
No entiendo la primera línea (origen) y el EC2_BIN. Con esa configuración, enumera todos los volúmenes y hace una instantánea de todos estos ...
Para el comentario de la instantánea, ¿cómo puedo cambiar esta línea para agregar texto?
DESC=$NAME-$(date +%m-%d-%Y)
lo siento de ser un principiante, pero no entiendo todo el guión
EDIT:
consigo este error con este nuevo código:
Creación de instantáneas para el volumen: ([EC2-describe-volúmenes]) con Descripción: -03-13-2012 información instantánea a continuación: Client.InvalidParame terValue: Valor (([EC2-describe-volúmenes])) para parámetro VolumeID no es válido. Esperado: 'vol -...'. Proceso terminó a las 03-13-2012-08: 11: 35 -
Y este es el código:
#!/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 tools
export 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 it
source /etc/environment
PURGE_SNAPSHOT_IN_DAYS=60
#EC2_BIN=$EC2_HOME/bin
# store the certificates and private key to your amazon account
MY_CERT='cert-xx.pem'
MY_KEY='pk-xx.pem'
# fetching the instance-id from the metadata repository
MY_INSTANCE_ID=`curl http://169.254.169.254/1.0/meta-data/instance-id`
# temproary file
TMP_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 $2 }')
VOLUME_LIST=(`ec2-describe-volumes --filter attachment.instance-id=$MY_INSTANCE_ID | awk '{ print $2 }'`)
sync
#create the snapshots
echo "Create EBS Volume Snapshot - Process started at $(date +%m-%d-%Y-%T)"
echo ""
echo $VOLUME_LIST
echo "-------------"
for volume in $(echo $VOLUME_LIST); do
NAME=$(cat $TMP_FILE | grep Name | grep $volume | awk '{ print $5 }')
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 ""
done
echo "Process ended at $(date +%m-%d-%Y-%T)"
echo ""
rm -f $TMP_FILE
#remove those snapshot which are $PURGE_SNAPSHOT_IN_DAYS old
bien mucho gracias por las explicaciones, me buscaron todo el día y me preguntó a mí mismo por las preguntas sobre "global" vars :-) Gracias por los pequeños realizando alguna mejora sobre la identificación de la instancia y la lista de volúmenes, la lista de volúmenes me causó algunos problemas. Voy a modificar la descripción y corregiré el "Client.InvalidParameterValue: Value (([ec2-describe-volumes])) para el parámetro volumeId no es válido. Esperado: 'vol -...'. ' error que todavía :-) – clement
Tenga cuidado al cambiar la descripción. Asegúrese de agregar comillas para tener cuidado. Si está obteniendo un error Client.InvalidParameterValue, es porque o bien el ID de volumen está vacío o el texto está usando para la descripción tiene espacios y su parte de lectura de la descripción para el id. de volumen – bwight
Tengo nuevamente ese problema. Este es todo el proceso impreso en la pantalla: Creación de instantánea para el volumen: ([ec2-describe-volumes]) con description: -03-13-2012 Información de instantánea a continuación: Client.InvalidParameterValue: Value (([ec2-describe-volumes])) para el parámetro volumeId no es válido. Esperado: 'vol -...'. Proceso finalizado al 03-13-2012-08: 11: 35 – clement