Added an -a switch for 'auto tagging'.
This currently only creates two tags, but they are immensely helpful in automating restores of snapshots to volumes. If this feature is liked, I can extend it to do more api work for adding instance_id and other metadata to tags, but did not want to initially increase dependencies or complexity. anthroprose@gmail.com
This commit is contained in:
parent
979fb3c431
commit
b2c8d872d8
|
@ -61,6 +61,13 @@ create_EBS_Snapshot_Tags()
|
||||||
then
|
then
|
||||||
snapshot_tags="$snapshot_tags --tag PurgeAfter=$purge_after_date --tag PurgeAllow=true"
|
snapshot_tags="$snapshot_tags --tag PurgeAfter=$purge_after_date --tag PurgeAllow=true"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if $auto_tag
|
||||||
|
then
|
||||||
|
snapshot_tags="$snapshot_tags --tag Volume=${ebs_selected} --tag Created=$date_current"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
#if $snapshot_tags is not zero length then set the tag on the snapshot using ec2-create-tags
|
#if $snapshot_tags is not zero length then set the tag on the snapshot using ec2-create-tags
|
||||||
if [[ -n $snapshot_tags ]]
|
if [[ -n $snapshot_tags ]]
|
||||||
then echo "Tagging Snapshot $ec2_snapshot_resource_id with the following Tags:"
|
then echo "Tagging Snapshot $ec2_snapshot_resource_id with the following Tags:"
|
||||||
|
@ -149,10 +156,12 @@ 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
|
#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
|
name_tag_create=false
|
||||||
|
#sets the auto_tagging feature to false - requires same as Name tag, auto sets tags like Volume with volume_id and Created with timestamp for easy searching
|
||||||
|
auto_tag=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
|
#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
|
purge_snapshots=false
|
||||||
#handles options processing
|
#handles options processing
|
||||||
while getopts :s:c:r:v:t:k:pn opt
|
while getopts :s:c:r:v:t:k:pna opt
|
||||||
do
|
do
|
||||||
case $opt in
|
case $opt in
|
||||||
s) selection_method="$OPTARG";;
|
s) selection_method="$OPTARG";;
|
||||||
|
@ -163,6 +172,7 @@ while getopts :s:c:r:v:t:k:pn opt
|
||||||
k) purge_after_days="$OPTARG";;
|
k) purge_after_days="$OPTARG";;
|
||||||
n) name_tag_create=true;;
|
n) name_tag_create=true;;
|
||||||
p) purge_snapshots=true;;
|
p) purge_snapshots=true;;
|
||||||
|
a) auto_tag=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;;
|
*) 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;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in New Issue
Block a user