from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
args = '<local_file cloud_file>'
help = 'Uploads a local backup file to the Rackspace Cloud'
def handle(self, *args, **options):
if len(args) != 2:
raise CommandError('2 arguments required: local_file cloud_file')
conn = cloudfiles.get_connection(settings.CLOUD_FILES_USER, settings.CLOUD_FILES_API_KEY)
cont = conn.get_container(settings.CLOUD_CONTAINER_NAME)
obj = cont.create_object(args)
local_file = open(args, 'r+')
for line in local_file:
Here's a Django management command that uploads a local file to Rackspace Cloud Files. This is one bit from a larger collection of scripts that I wrote to dump an app's data to a json file, tarball the json, and upload the tarball to Rackspace Cloud Files.
It's pretty quick 'n dirty at this point, not a lot of error checking going on, so there's room for improvement. But it does what I needed it to do. Thought I'd pass it on.
A couple implementation notes:
- Drop it in
./manage.py backup_to_cloud local_file_name cloud_file_name
- Requires CLOUD_FILES_USER, CLOUD_FILES_API_KEY and CLOUD_CONTAINER_NAME to be in your site's settings.py file.
- Requires python-cloudfiles
- Requires a Rackspace Cloud Files account ;)