Backing up Ubuntu Server to Amazon EC2

I need to get the backing up of my web server sorted out. The plan at the moment is:

* Periodically start an amazon ec2 ubuntu instance.
* Once the instance has started, copy files to the storage.
* On completion stop the instance.

It's more complicated as I am trying to save money by not having the instance running all the time. Also as the ip address will be different every time the instance is started, the script will have to adjust accordingly.

Install boto 2.0 from gz file downloaded from google code boto site:

http://code.google.com/p/boto/downloads/list

install python-duplicity from ubuntu repositories.

set environment variables for aws ec2:
export AWS_ACCESS_KEY_ID=[YOUR KEY ID]
export AWS_SECRET_ACCESS_KEY=[YOUR SECRET KEY]

 
import boto
import boto.ec2
import time
regions = boto.ec2.regions()
eu = regions[0] #eu-west-1
conn_eu = eu.connect()
rs = conn_eu.get_all_instances(instance_ids='<your instance id here>')
reservation = rs[0]
instance = reservation.instances[0]
#start an existing instance
instance.start()
print instance.state
while (instance.state != 'running'):
    time.sleep(5)
    instance.update()
    print 'pending ...'
print instance.ip_address
 

jonathan@V1104-J:~/Dropbox/amazonws$ duplicity --no-encryption --scp-command 'scp -o IdentityFile=/home/jonathan/Dropbox/amazonws/jonathlt.pem' --sftp-command 'sftp -o IdentityFile=/home/jonathan/Dropbox/amazonws/jonathlt.pem' /home/jonathan/Documents scp://ubuntu@xx.xx.xx.xx//home/ubuntu/backups/Documents

Bristol & Bath Spring 2011

Some pictures from our recent trip to the west country.

Powered by Flickr Gallery

Subscribe to RSS Feed Follow me on Twitter!