Added script flag -h to enable InitiatingHost as a tag to the snapshot

This commit is contained in:
Jeff Vogt 2013-10-14 19:51:06 -07:00
parent 0f8060ab26
commit 6759a97c3d
2 changed files with 11 additions and 0 deletions

View File

@ -25,6 +25,8 @@ ec2-automate-backup requires one of the following two parameters be provided:
`-n` - tag snapshots "Name" tag as well as description
`-h` - tag snapshots "InitiatingHost" tag to specify which host ran the script
`-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.

View File

@ -56,6 +56,12 @@ create_EBS_Snapshot_Tags()
ec2_snapshot_resource_id=`echo "$ec2_create_snapshot_result" | cut -f 2`
snapshot_tags="$snapshot_tags --tag Name=ec2ab_${ebs_selected}_$date_current"
fi
#if $hostname_tag_create is true then append --tag InitiatingHost=`hostname -f` to the variable $snapshot_tags
if $hostname_tag_create
then
ec2_snapshot_resource_id=`echo "$ec2_create_snapshot_result" | cut -f 2`
snapshot_tags="$snapshot_tags --tag InitiatingHost='`hostname -f`'"
fi
#if $purge_after_days is true, then append $purge_after_date to the variable $snapshot_tags
if [[ -n $purge_after_days ]]
then
@ -156,6 +162,8 @@ date_binary=""
#sets the "Name" tag set for a snapshot to false - using "Name" requires that ec2-create-tags be called in addition to ec2-create-snapshot
name_tag_create=false
#sets the "InitiatingHost" tag set for a snapshot to false
hostname_tag_create=false
#sets the user_tags feature to false - user_tag creates tags on snapshots - by default each snapshot is tagged with volume_id and current_data timestamp
user_tags=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
@ -171,6 +179,7 @@ while getopts :s:c:r:v:t:k:pnu opt
t) tag="$OPTARG";;
k) purge_after_days="$OPTARG";;
n) name_tag_create=true;;
h) hostname_tag_create=true;;
p) purge_snapshots=true;;
u) user_tags=true;;
*) echo "Error with Options Input. Cause of failure is most likely that an unsupported parameter was passed or a parameter was passed without a corresponding option." 1>&2 ; exit 64;;