aws-ec2-ebs-automatic-snapshot-bash icon indicating copy to clipboard operation
aws-ec2-ebs-automatic-snapshot-bash copied to clipboard

Add command line params and dockerize

Open bkrodgers opened this issue 10 years ago • 2 comments

Hi, great work on your script! I made a few changes I'd like to submit back to you.

  1. I added an optional command line parameter to specify which volume on the machine you want to back up, based on the device name it's attached as. If it's not specified, it will back up everything as it normally would.
  2. I added an optional command line parameter to specify retention days.
  3. I created a Dockerfile to build a docker image for this script. (I use coreOS). For now I just am publishing to my private docker repo, but if you're interested in having this on docker hub, you can look into setting up an automated build that would be triggered when you make changes: https://docs.docker.com/docker-hub/builds/
  4. I added an explicit exit 0. I'm not sure if it was docker or systemd, but one or the other wasn't seeing it as successfully completing without it and was going into a restart loop.
  5. Instead of tagging the snapshots with $(hostname), I switched it to use the instance ID. This was primarily to make it docker friendly, as hostname in a docker container gives back a meaningless internal docker hostname.

Let me know if there's anything you'd like me to change!

bkrodgers avatar Sep 02 '15 23:09 bkrodgers

For 5., there is value in many cases in using the hostname, so I think it should probably stay, but do like the idea of having the instance ID in there, so maybe a compromise would be to have both? Something like:

snapshot_description="$(hostname)-$instance_id-$device_name-backup-$(date +%Y-%m-%d)"

It's a little long, but gives a pretty comprehensive summary of what the particular snapshot represents. Another option would be to add it as a tag to the snapshot, rather than the description.

jboeshart avatar Sep 03 '15 13:09 jboeshart

OK, I just pushed an option that checks if you're running inside docker (docker containers get a /.dockerinit file mounted inside them). If inside docker, it'll leave the hostname out, otherwise it includes it along with the instance id.

I also added two tags "CreatedFromInstance" and "InstanceDevice" to the snapshot, to make it a bit easier to search by those if needed. We could add a hostname tag as well if you think that's valuable.

bkrodgers avatar Sep 03 '15 21:09 bkrodgers