Created
October 25, 2015 20:57
-
-
Save anonymous/aebc9414669ae692236d to your computer and use it in GitHub Desktop.
Basic script to upload a backup from the Boss RC-300 loop station to S3.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import os | |
import StringIO | |
import tarfile | |
import boto | |
MOUNT_LOCATION = '/Volumes/BOSS_RC-300' | |
UPLOAD_REGION = '<your-region-here>' | |
UPLOAD_BUCKET = '<your-bucket-here>' | |
UPLOAD_PATH = 'rc300/%Y-%m-%d.tgz' | |
def get_backup_bucket(): | |
return boto.s3.connect_to_region(UPLOAD_REGION).get_bucket(UPLOAD_BUCKET) | |
def make_backup(): | |
# Make a tgz backup. | |
print 'Building tar file from directory: {}'.format(MOUNT_LOCATION) | |
buf = StringIO.StringIO() | |
with tarfile.open(fileobj=buf, mode='w:gz') as tar: | |
tar.add(MOUNT_LOCATION, os.path.basename(MOUNT_LOCATION)) | |
buf.seek(0) | |
print 'Finished building backup file' | |
# Create a new key at UPLOAD_BUCKET:UPLOAD_PATH to house the backup | |
now = datetime.datetime.now() | |
upload_path = now.strftime(UPLOAD_PATH) | |
print 'Uploading backup to {}:{}'.format(UPLOAD_BUCKET, upload_path) | |
bucket = get_backup_bucket() | |
key = bucket.new_key(upload_path) | |
key.set_contents_from_file(buf) | |
print 'Backup was successful!' | |
if __name__ == '__main__': | |
make_backup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment