mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
add redis backup and remove redundant redis backup scripts. Use one script and pass in hostname argument instead
This commit is contained in:
parent
c2bef5565b
commit
4cea718d40
4 changed files with 15 additions and 35 deletions
|
@ -60,3 +60,10 @@
|
|||
when: "'redis' in inventory_hostname"
|
||||
tags:
|
||||
- sanity-checker
|
||||
|
||||
- name: Add redis backup
|
||||
cron:
|
||||
name: "{{ ansible_hostname }} backup"
|
||||
minute: "0"
|
||||
hour: "4"
|
||||
job: "/srv/newsblur/utils/backups/backup_redis.py {{ ansible_hostname}}"
|
|
@ -1,3 +1,4 @@
|
|||
#!/usr/bin/python3
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
@ -7,10 +8,14 @@ sys.path.insert(0, NEWSBLUR_DIR)
|
|||
os.environ['DJANGO_SETTINGS_MODULE'] = 'newsblur_web.settings'
|
||||
|
||||
import time
|
||||
import s3
|
||||
import boto3
|
||||
from django.conf import settings
|
||||
|
||||
filename = 'backup_redis/backup_redis_%s.rdb.gz' % time.strftime('%Y-%m-%d-%H-%M')
|
||||
s3 = boto3.resource('s3')
|
||||
bucket = s3.Bucket(settings.get('S3_BACKUP_BUCKET'))
|
||||
|
||||
hostname = sys.argv[1][3:].replace('-','_')
|
||||
filename = f'backup_{hostname}/backup_{hostname}_{time.strftime("%Y-%m-%d-%H-%M")}.rdb.gz'
|
||||
path = '/var/lib/redis/dump.rdb'
|
||||
print('Uploading %s (from %s) to S3...' % (filename, path))
|
||||
s3.save_file_in_s3(path, name=filename)
|
||||
bucket.upload_file(path, name=filename)
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
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'] = 'newsblur_web.settings'
|
||||
|
||||
import time
|
||||
import s3
|
||||
from django.conf import settings
|
||||
|
||||
filename = 'backup_redis_sessions/backup_redis_sessions_%s.rdb.gz' % time.strftime('%Y-%m-%d-%H-%M')
|
||||
path = '/var/lib/redis/dump.rdb'
|
||||
print('Uploading %s (from %s) to S3...' % (filename, path))
|
||||
s3.save_file_in_s3(path, name=filename)
|
|
@ -1,16 +0,0 @@
|
|||
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'] = 'newsblur_web.settings'
|
||||
|
||||
import time
|
||||
import s3
|
||||
from django.conf import settings
|
||||
|
||||
filename = 'redis_story/backup_redis_story_%s.rdb.gz' % time.strftime('%Y-%m-%d-%H-%M')
|
||||
path = '/var/lib/redis/dump.rdb'
|
||||
print('Uploading %s (from %s) to S3...' % (filename, path))
|
||||
s3.save_file_in_s3(path, name=filename)
|
Loading…
Add table
Reference in a new issue