I am trying to create a script to back up a volume automatically.
I follow this EBS-Snapshot.shscript as shown on github :
#!/bin/bash
source /etc/environment
PURGE_SNAPSHOT_IN_DAYS=10
EC2_BIN=$EC2_HOME/bin
MY_CERT='/path/to/certificate-file'
MY_KEY='/path/to/private-file'
MY_INSTANCE_ID='your ec2-instance-id'
TMP_FILE='/tmp/rock-ebs-info.txt'
$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
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
I have two X509 authentication files, an instance ID, but I do not understand the script and how to parameterize the volume that I want to backup.
I do not understand the first line (source) and EC2_BIN. With this configuration, it lists all volumes and takes a snapshot of all of these ...
For a snapshot comment, how can I change this line to add text?
DESC=$NAME-$(date +%m-%d-%Y)
I'm sorry I'm new, but I don't understand the whole script
EDIT:
I get this error with this new code:
: ([ec2-describe-volume]) : -03-13-2012 : Client.InvalidParameterValue: (([ec2-describe-volume])) volumeId . : "vol...". 03-13-2012-08: 11: 35 -
:
#!/bin/bash
export JAVA_HOME=/usr
export EC2_BIN=/usr/bin/
source /etc/environment
PURGE_SNAPSHOT_IN_DAYS=60
MY_CERT='cert-xx.pem'
MY_KEY='pk-xx.pem'
MY_INSTANCE_ID=`curl http://169.254.169.254/1.0/meta-data/instance-id`
TMP_FILE='/tmp/rock-ebs-info.txt'
$EC2_BIN/ec2-describe-volumes -C $MY_CERT -K $MY_KEY > $TMP_FILE
VOLUME_LIST=(`ec2-describe-volumes --filter attachment.instance-id=$MY_INSTANCE_ID | awk '{ print $2 }'`)
sync
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