raczylo.com blog ~ #

Copy AWS EC2 snapshots between regions.

Created on 2013-09-10 in categories ops , cloud , aws
Tagged as: aws , cloud , ec2

If you need to copy multiple snapshots between regions - it's a real pain in the neck. With this little script you can use your time to have a pint, or two.

“Respect the laziness” and “avoid clickety click interfaces” are only two of my every-day commandments. As a result of unique connection between them I have created quick and simple php script to make your day easier to survive and even automate few tasks ( if you can code and use crontab ). Long story short - it’s available on github - ยป AWS copy snapshot between regions as little opensource ‘thingy’ - feel free to fork it / modify or contribute.

Sample output:

root@whatever:/home/nvm# php ec2-snapshot-copy.php vol-abc1234 eu-west-1
Current availability zone: us-east-1
Available regions: eu-west-1 sa-east-1 us-east-1 ap-northeast-1 us-west-2 us-west-1 ap-southeast-1 ap-southeast-2
[i] Using current endpoint ec2.us-east-1.amazonaws.com
[i] Volume vol-abc1234 found. Looking for snapshots.
[i] Most recent snapshot found: Thu 21 Feb 2013 - snap-1234
[i] Copying snapshot snap-1234 from us-east-1 to eu-west-1
[i] New snapshot id: snap-4321`

Features aka ‘how does it work’

  • execute script with volume id to copy it’s snapshot
  • detects current availability zone using ec2metadata output ( laziness FTW )
  • sets endpoint for current zone, checking if volume exists, if yes - checking for snapshots and picking latest one.
  • switching ( in background ) endpoint to desired one, copying snapshot.
  • returning ID of our source snapshot copy, in new region.

* Table of contents *

* Check other posts *

* Categories *

aws(1) cloud(3) dev(3) gems(1) howto(3) insights(1) internet(1) learning(1) lesson(1) mac(1) ops(8) post(1) projects(3) script(1) social(1) tools(1) tutorial(5)

* Tags *

api(2) apple(2) aws(3) bash(1) cloud(5) cluster(1) devices(1) docker(1) ec2(1) elasticsearch(1) gcp(1) gem(1) github(2) go(1) golang(2) google-authenticator(1) google-cloud(3) internet(1) iptables(1) kubernetes(1) linux(2) littleguardian(1) logging(1) mac(2) netgear(1) network(1) opensource(1) openvpn(1) osx(2) pci-compliance(1) review(1) ruby(2) security(2) ssh(1) tethering(1) tplink(1) ubuntu(1) wykop(1) yubikey(1)
comments powered by Disqus