Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transfer Custom tags to backup #114

Closed
Gerben-W opened this issue Nov 27, 2015 · 4 comments
Closed

Transfer Custom tags to backup #114

Gerben-W opened this issue Nov 27, 2015 · 4 comments

Comments

@Gerben-W
Copy link

I love the script, but I still have a question.
We use custom tags for different CostLocations, now we would like to transfer the custom values for a "Billing" and a "CostLocation" tag to the snapshot.
Is this possible?

@toby1kenobi
Copy link

Yes, this would be very useful to us too

@toby1kenobi
Copy link

Ok, this is what I did (possibly inelegant/wrong, I'm no shell expert!) - I wanted to copy across our tags 'client' and 'project':

create_EBS_Snapshot_Tags() {
  #snapshot tags holds all tags that need to be applied to a given snapshot - by aggregating tags we ensure that ec2-create-tags is called only onece
  snapshot_tags=""

  # Apply client and project tags to snapshot
  ec2_tag_list=$(aws ec2 describe-tags --filters "Name=resource-id,Values=${ebs_selected}" --query 'Tags[?Key==`project` || Key==`client`].[Key,Value]' --output text 2>&1)

  if [ !"$ec2_tag_list" ]; then
    IFS=$'\n' read -d '' -r -a lines <<< "$ec2_tag_list"

    for i in "${lines[@]}"; do
      parts=($i)
      snapshot_tags="$snapshot_tags Key=${parts[0]},Value=${parts[1]}"
    done
  fi

This is in an older version of the automate backup script, hopefully gives the idea though.

@toby1kenobi
Copy link

FYI, I did a better version of this, which is in a pull request #123

@Gerben-W
Copy link
Author

@toby1kenobi Thanks for the change. It works like a charm.
Both the Tags are working if I add them with "-d Billing,CostLocation" to the command.

Thanx again

@Gerben-W Gerben-W reopened this Apr 1, 2016
@Gerben-W Gerben-W closed this as completed May 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants