Adding backup mongo task to be run by cron instead.

This commit is contained in:
Samuel Clay 2012-12-10 11:37:35 -08:00
parent 365e60ad64
commit edc3a80667
3 changed files with 42 additions and 1 deletions

View file

@ -0,0 +1,8 @@
from django.core.management.base import BaseCommand
from apps.rss_feeds.tasks import BackupMongo
class Command(BaseCommand):
option_list = BaseCommand.option_list
def handle(self, *args, **options):
BackupMongo.apply()

View file

@ -1,4 +1,8 @@
import datetime
import os
import shutil
import time
import s3
from celery.task import Task
from utils import log as logging
from django.conf import settings
@ -105,3 +109,32 @@ class PushFeeds(Task):
}
feed = Feed.get_by_id(feed_id)
feed.update(options=options)
class BackupMongo(Task):
name = 'backup-mongo'
max_retries = 0
ignore_result = True
def run(self, **kwargs):
COLLECTIONS = "classifier_tag classifier_author classifier_feed classifier_title userstories starred_stories shared_stories category category_site sent_emails social_profile social_subscription social_services statistics feedback"
date = time.strftime('%Y-%m-%d-%H-%M')
collections = COLLECTIONS.split(' ')
db_name = 'newsblur'
dir_name = 'backup_mongo_%s' % date
filename = '%s.tgz' % dir_name
os.mkdir(dir_name)
for collection in collections:
cmd = 'mongodump --db %s --collection %s -o %s' % (db_name, collection, dir_name)
logging.debug(' ---> ~FMDumping ~SB%s~SN: %s' % (collection, cmd))
os.system(cmd)
cmd = 'tar -jcf %s %s' % (filename, dir_name)
os.system(cmd)
logging.debug(' ---> ~FRUploading ~SB~SK%s~SN~FR to S3...' % filename)
s3.save_file_in_s3(filename)
shutil.rmtree(dir_name)
os.remove(filename)

2
fabfile.py vendored
View file

@ -42,7 +42,7 @@ env.roledefs ={
],
'db': ['db01.newsblur.com',
'db02.newsblur.com',
'db03.newsblur.com',
# 'db03.newsblur.com',
'db04.newsblur.com',
'db05.newsblur.com',
],