Created
          November 6, 2012 17:26 
        
      - 
      
- 
        Save zircote/4026181 to your computer and use it in GitHub Desktop. 
    Recursive S3 RRS with Celery
  
        
  
    
      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 boto, logging, os, sys, re, awscreds | |
| from celery import Celery | |
| from celery.utils.log import get_task_logger | |
| from boto.s3.connection import S3ResponseError | |
| def searchDirs(): | |
| import shlex, subprocess | |
| command = "find %s -maxdepth 4 -mindepth 4 -type d " % root_path; | |
| args = shlex.split(command) | |
| process = subprocess.Popen(args, stdout=subprocess.PIPE) | |
| while True: | |
| line = process.stdout.readline() | |
| if line != '': | |
| processRemoteRRS.delay(line.rstrip()) | |
| else: | |
| break | |
| @celery.task | |
| def processRemoteRRS(path): | |
| path = re.sub(root_path,'',path) | |
| try: | |
| logger= get_task_logger(__name__) | |
| logging.getLogger('boto').setLevel(logging.INFO) | |
| conn = boto.connect_s3(awscreds.access, awscreds.secret) | |
| b = conn.get_bucket('user_recordings') | |
| for key in b.list(path): | |
| if key.storage_class == 'STANDARD': | |
| logger.info('Setting RRS on KEY:[%s]' % key) | |
| key.change_storage_class('REDUCED_REDUNDANCY') | |
| except (S3ResponseError, OSError), exc: | |
| raise processRemoteRRS.retry(exc=exc, countdown=600) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment