fix syntax for backup_redis and duse socket for getting hostname instead of passing in as an argument

This commit is contained in:
Jonathan Math 2021-06-27 14:36:24 -06:00
parent 4846457bc4
commit a78dec3ed9
2 changed files with 4 additions and 3 deletions

View file

@ -75,4 +75,5 @@
-v /srv/newsblur:/srv/newsblur
-v /srv/newsblur/docker/volumes/redis.var.lib/dump.rdb:/var/lib/redis/dump.rdb
--network=newsblurnet
/srv/newsblur/utils/backups/backup_redis.py {{ ansible_hostname }}"
--hostname={{ ansible_hostname }}
newsblur/newsblur_python3 /srv/newsblur/utils/backups/backup_redis.py

View file

@ -1,7 +1,7 @@
#!/usr/bin/python3
import os
import sys
import socket
CURRENT_DIR = os.path.dirname(__file__)
NEWSBLUR_DIR = ''.join([CURRENT_DIR, '/../../'])
sys.path.insert(0, NEWSBLUR_DIR)
@ -14,7 +14,7 @@ from django.conf import settings
s3 = boto3.resource('s3')
bucket = s3.Bucket(settings.get('S3_BACKUP_BUCKET'))
hostname = sys.argv[1][3:].replace('-','_')
hostname = socket.gethostname().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))