ec2-automate-backup supports -c cron-primer mode for loading environment configuration.
This commit is contained in:
parent
18a97a7714
commit
b122dcfff8
|
@ -22,6 +22,7 @@ ec2-automate-backup requires one of the following two parameters be provided:
|
|||
#
|
||||
-r <region> - the region that contains the EBS volumes for which you wish to have a snapshot created.
|
||||
-s <selection_method> - the selection method by which EBS volumes will be selected. Currently supported selection methods are "volumeid" and "tag." The selection method "volumeid" identifies EBS volumes for which a snapshot should be taken by volume id whereas the selection method "tag" identifies EBS volumes for which a snapshot should be taken by a key=value format tag.
|
||||
-c <cron_primer_file> - running with the -c option and a providing a file will cause ec2-automate-backup to source a file for environmental configuration - ideal for running ec2-automate-backup under cron. An example cron primer file is located in the "Resources" directory and is called cron-primer.sh.
|
||||
-n - tag snapshots "Name" tag as well as description
|
||||
-k <purge_after_days> - the period after which a snapshot can be purged. For example, running "ec2-automate-backup.sh -v "vol-6d6a0527 vol-636a0112" -k 31" would allow snapshots to be removed after 31 days. purge_after_days creates two tags for each volume that was backed up - a PurgeAllow tag which is set to PurgeAllow=true and a PurgeAfter tag which is set to the present day (in UTC) + the value provided by -k.
|
||||
-p - the -p flag will purge (meaning delete) all snapshots that were created more than "purge after days" ago. ec2-automate-backup looks at two tags to determine which snapshots should be deleted - the PurgeAllow and PurgeAfter tags. The tags must be set as follows: PurgeAllow=true and PurgeAfter=YYYY-MM-DD where YYYY-MM-DD must be before the present date.
|
||||
|
|
11
ec2-automate-backup/Resources/cron-primer.sh
Normal file
11
ec2-automate-backup/Resources/cron-primer.sh
Normal file
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
#EC2_HOME required for EC2 API Tools
|
||||
export EC2_HOME=/opt/aws/apitools/ec2
|
||||
#JAVA_HOME required for EC2 API Tools
|
||||
export JAVA_HOME=/usr/lib/jvm/jre
|
||||
#export PATH=/bin is required for cut, date, grep
|
||||
#export PATH=/opt/aws/bin/ is required for EC2 API Tools
|
||||
#typical system path PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/bin
|
||||
export PATH=/bin:/opt/aws/bin/
|
||||
export AWS_ACCESS_KEY=<your_access_key>
|
||||
export AWS_SECRET_KEY=<your_secret_key>
|
|
@ -139,9 +139,6 @@ purge_EBS_Snapshots()
|
|||
done
|
||||
}
|
||||
|
||||
#calls prerequisitecheck function to ensure that all executables required for script execution are available
|
||||
prerequisite_check
|
||||
|
||||
app_name=`basename $0`
|
||||
|
||||
#sets defaults
|
||||
|
@ -155,10 +152,11 @@ name_tag_create=false
|
|||
#sets the Purge Snapshot feature to false - this feature will eventually allow the removal of snapshots that have a "PurgeAfter" tag that is earlier than current date
|
||||
purge_snapshots=false
|
||||
#handles options processing
|
||||
while getopts :s:r:v:t:k:pn opt
|
||||
while getopts :s:c:r:v:t:k:pn opt
|
||||
do
|
||||
case $opt in
|
||||
s) selection_method="$OPTARG";;
|
||||
c) cron_primer="$OPTARG";;
|
||||
r) region="$OPTARG";;
|
||||
v) volumeid="$OPTARG";;
|
||||
t) tag="$OPTARG";;
|
||||
|
@ -169,6 +167,18 @@ while getopts :s:r:v:t:k:pn opt
|
|||
esac
|
||||
done
|
||||
|
||||
#sources "cron_primer" file for running under cron or other restricted environments - this file should contain the variables and environment configuration required for ec2-automate-backup to run correctly
|
||||
if [[ -n $cron_primer ]]
|
||||
then if [[ -f $cron_primer ]]
|
||||
then source $cron_primer
|
||||
else
|
||||
echo "Cron Primer File \"$cron_primer\" Could Not Be Found." 1>&2 ; exit 70
|
||||
fi
|
||||
fi
|
||||
|
||||
#calls prerequisitecheck function to ensure that all executables required for script execution are available
|
||||
prerequisite_check
|
||||
|
||||
#sets date variable
|
||||
date_current=`date -u +%Y-%m-%d`
|
||||
#sets the PurgeAfter tag to the number of days that a snapshot should be retained
|
||||
|
|
Loading…
Reference in New Issue
Block a user