Avoid Disaster: Script backups easily to Amazon S3

Avoid disaster

I released avoid_disaster today, it let's you do following things:
  • script backups easily via Python and upload them to Amazon S3
  • easily create daily, weekly or monthly backups
  • Amazon S3 is a cheap backup option and your backups are stored on 3 different data centers

The script is super simple, but it should be quite useful for anyone that wants to create cheap backups.

You are also welcome to fork the code on GitHub and supply extensions and patches :-)

Example usage

First install boto and avoid_disaster:

$ sudo easy_install boto
$ sudo easy_install avoid_disaster

Here is some example code that can get you started:

import os
from avoid_disaster import S3Uploader, gunzip_dir, generate_file_key

#--- Globals ----------------------------------------------
AWS_KEY = 'YOUR AWS KEY'
AWS_SECRET = 'YOUR AWS SECRET'

s3_uploader = S3Uploader(AWS_KEY,
                         AWS_SECRET,
                         'backups.your_domain.com')

#--- Easy usage ----------------------------------------------
#Daily
s3_uploader.compress_and_upload('test_dir/',
                                'test_dir.%(weekday)s.tgz',
                                replace_old=True)

#Monthly
s3_uploader.compress_and_upload('test_dir/',
                                'test_dir.%(month_name)s.tgz',
                                replace_old=True)

#Weekly
s3_uploader.compress_and_upload('test_dir/',
                                'test_dir.%(week_number)s.tgz',
                                replace_old=True)


#--- Generic usage ----------------------------------------------
file_key = generate_file_key('test_dir.%(weekday)s.tgz')
gz_filename = gunzip_dir('test_dir/', file_key)
s3_uploader.upload(file_key, gz_filename, replace_old=True)
os.remove(gz_filename)
29. Jun 2010 Announcements · Python · Stuff · Todoist · Wedoist
© Amir Salihefendic