NewsBlur/utils/backups/backup_mongo.py

20 lines
534 B
Python
Raw Normal View History

#!/usr/bin/python3
import os
2011-05-18 14:59:05 -04:00
import shutil
from newsblur_web import settings
import boto3
2021-07-23 19:06:00 -04:00
from botocore.exceptions import ClientError
filenames = [f for f in os.listdir('/opt/mongo/newsblur/backup/') if '.tgz' in f]
2021-06-27 14:32:37 -06:00
for filename in filenames:
print('Uploading %s to S3...' % filename)
try:
2021-07-23 19:04:30 -04:00
s3 = boto3.client('s3')
2021-07-23 19:06:00 -04:00
s3.upload_file(f"mongo/{filename}", settings.S3_BACKUP_BUCKET)
except ClientError as e:
print(" ****> Exceptions: %s" % e)
shutil.rmtree(filename[:-4])
os.remove(filename)