mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Adding redis backup script.
This commit is contained in:
parent
7c32fea650
commit
4d014033b6
2 changed files with 19 additions and 2 deletions
17
utils/backups/backup_redis.py
Normal file
17
utils/backups/backup_redis.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
import os
|
||||
import sys
|
||||
|
||||
CURRENT_DIR = os.path.dirname(__file__)
|
||||
NEWSBLUR_DIR = ''.join([CURRENT_DIR, '/../../'])
|
||||
sys.path.insert(0, NEWSBLUR_DIR)
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
|
||||
|
||||
import time
|
||||
import s3
|
||||
from django.conf import settings
|
||||
|
||||
filename = 'backup_redis_%s.rdb.gz' % time.strftime('%Y-%m-%d-%H-%M')
|
||||
path = '/var/lib/redis/dump.rdb'
|
||||
print 'Uploading %s / %s to S3...' % (filename, path)
|
||||
s3.save_file_in_s3(path, name=filename)
|
||||
os.remove(filename)
|
|
@ -13,11 +13,11 @@ ACCESS_KEY = settings.S3_ACCESS_KEY
|
|||
SECRET = settings.S3_SECRET
|
||||
BUCKET_NAME = settings.S3_BACKUP_BUCKET # Note that you need to create this bucket first
|
||||
|
||||
def save_file_in_s3(filename):
|
||||
def save_file_in_s3(filename, name=None):
|
||||
conn = S3Connection(ACCESS_KEY, SECRET)
|
||||
bucket = conn.get_bucket(BUCKET_NAME)
|
||||
k = Key(bucket)
|
||||
k.key = filename
|
||||
k.key = name or filename
|
||||
|
||||
k.set_contents_from_filename(filename)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue