Skip to content

Commit 25c4a50

Browse files
committed
feat(backup): change dump directory to /backup
Fix shell sheebang Fix pep8
1 parent 78217f1 commit 25c4a50

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

backup.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
#!/bin/sh
1+
#!/usr/bin/env sh
22

33
OPTIONS=`python /usr/local/bin/mongouri`
44
BACKUP_NAME="$(date -u +%Y-%m-%d_%H-%M-%S)_UTC.gz"
55

66
# Run backup
7-
mongodump ${OPTIONS} -o /tmp/dump
7+
mongodump ${OPTIONS} -o /backup/dump
88
# Compress backup
9-
cd /tmp/ && tar -cvzf "/backup/${BACKUP_NAME}" dump
9+
cd /backup/ && tar -cvzf "${BACKUP_NAME}" dump
1010
# Upload backup
1111
aws s3 cp "/backup/${BACKUP_NAME}" "s3://${S3_BUCKET}/${S3_PATH}/${BACKUP_NAME}"
1212
# Delete temp files
13-
rm -rf /tmp/dump
13+
rm -rf /backup/dump
1414

1515
# Delete backup files
1616
if [ -n "${MAX_BACKUPS}" ]; then

entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/usr/bin/env sh
22

33
set +e
44

mongouri.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
#!/usr/bin/env python
22

3-
import pymongo
43
import os
4+
import pymongo
55

66
uri = os.environ['MONGO_URI']
77
data = pymongo.uri_parser.parse_uri(uri)
8-
auth = '' if data['username'] is None else '-u %s -p %s' % (data['username'], data['password'])
8+
if data['username'] is None:
9+
auth = ''
10+
else:
11+
auth = '-u %s -p %s' % (data['username'], data['password'])
912
host = '-h %s:%s' % (data['nodelist'][0][0], data['nodelist'][0][1])
10-
dbname = '-d %s' % data['database'] if os.environ.get('MONGO_COMPLETE') is None else ''
13+
if os.environ.get('MONGO_COMPLETE') is None:
14+
dbname = '-d %s' % data['database']
15+
else:
16+
dbname = ''
1117
options = '%s %s %s' % (auth, host, dbname)
1218

13-
print options
19+
print(options)

0 commit comments

Comments
 (0)