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(2) dev(2) gems(1) howto(3) mac(1) ops(7) projects(2) script(1) tools(1) tutorial(4)

* Tags *

api(1) apple(2) aws(3) bash(1) cloud(4) cluster(1) ec2(1) elasticsearch(1) gem(1) github(1) google-authenticator(1) google-cloud(1) iptables(1) linux(2) logging(1) mac(2) opensource(1) openvpn(1) osx(2) pci-compliance(1) ruby(2) security(2) ssh(1) ubuntu(1) wykop(1) yubikey(1)
comments powered by Disqus