-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from silinternational/develop
Release 1.0.0
- Loading branch information
Showing
7 changed files
with
73 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM alpine:3.6 | ||
FROM alpine:3.8 | ||
|
||
RUN apk update \ | ||
&& apk add --no-cache rsyslog rsyslog-tls \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
#!/usr/bin/env sh | ||
|
||
for dbName in ${DB_NAMES}; do | ||
logger -p user.info "backing up ${dbName}..." | ||
logger -p user.info "backing up ${DB_NAME}..." | ||
|
||
start=$(date +%s) | ||
runny $(PGPASSWORD=${DB_PASSWORD} pg_dump --host=${DB_HOST} --username=${DB_USER} --create --clean ${DB_OPTIONS} --dbname=${dbName} > /tmp/${dbName}.sql) | ||
runny $(PGPASSWORD=${DB_USERPASSWORD} pg_dump --host=${DB_HOST} --username=${DB_USER} --create --clean ${DB_OPTIONS} --dbname=${DB_NAME} > /tmp/${DB_NAME}.sql) | ||
end=$(date +%s) | ||
|
||
logger -p user.info "${dbName} backed up ($(stat -c %s /tmp/${dbName}.sql) bytes) in $(expr ${end} - ${start}) seconds." | ||
logger -p user.info "${DB_NAME} backed up ($(stat -c %s /tmp/${DB_NAME}.sql) bytes) in $(expr ${end} - ${start}) seconds." | ||
|
||
runny gzip -f /tmp/${dbName}.sql | ||
runny s3cmd put /tmp/${dbName}.sql.gz ${S3_BUCKET} | ||
# runny aws s3 cp /tmp/${dbName}.sql.gz ${S3_BUCKET} | ||
runny gzip -f /tmp/${DB_NAME}.sql | ||
runny s3cmd put /tmp/${DB_NAME}.sql.gz ${S3_BUCKET} | ||
# runny aws s3 cp /tmp/${DB_NAME}.sql.gz ${S3_BUCKET} | ||
|
||
logger -p user.info "${dbName} backup stored in ${S3_BUCKET}." | ||
done | ||
logger -p user.info "${DB_NAME} backup stored in ${S3_BUCKET}." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,41 @@ | ||
#!/usr/bin/env sh | ||
|
||
for dbName in ${DB_NAMES}; do | ||
logger -p user.info "restoring ${dbName}..." | ||
# Does the database exist? | ||
logger -p user.info "checking for DB ${DB_NAME}..." | ||
result=$(psql --host=${DB_HOST} --username=${DB_ROOTUSER} --list | grep ${DB_NAME}) | ||
if [ -z "${result}" ]; then | ||
message="Database "${DB_NAME}" on host "${DB_HOST}" does not exist." | ||
logger -p 1 -t application.crit "${message}" | ||
exit 1 | ||
fi | ||
|
||
runny s3cmd get -f ${S3_BUCKET}/${dbName}.sql.gz /tmp/${dbName}.sql.gz | ||
runny gunzip -f /tmp/${dbName}.sql.gz | ||
# Ensure the database user exists. | ||
logger -p user.info "checking for DB user ${DB_USER}..." | ||
result=$(psql --host=${DB_HOST} --username=${DB_ROOTUSER} --command='\du' | grep ${DB_USER}) | ||
if [ -z "${result}" ]; then | ||
result=$(psql --host=${DB_HOST} --username=${DB_ROOTUSER} --command="create role ${DB_USER} with login password '${DB_USERPASSWORD}' inherit;") | ||
if [ "${result}" != "CREATE ROLE" ]; then | ||
message="Create role command failed: ${result}" | ||
logger -p 1 -t application.crit "${message}" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
start=$(date +%s) | ||
runny psql --host=${DB_HOST} --username=${DB_USER} ${DB_OPTIONS} < /tmp/${dbName}.sql | ||
end=$(date +%s) | ||
logger -p user.info "changing DB ownership to ${DB_USER}..." | ||
result=$(psql --host=${DB_HOST} --username=${DB_ROOTUSER} --command="alter database ${DB_NAME} owner to ${DB_USER};") | ||
if [ "${result}" != "ALTER DATABASE" ]; then | ||
message="Alter database command failed: ${result}" | ||
logger -p 1 -t application.crit "${message}" | ||
exit 1 | ||
fi | ||
|
||
logger -p user.info "${dbName} restored in $(expr ${end} - ${start}) seconds." | ||
done | ||
logger -p user.info "restoring ${DB_NAME}..." | ||
|
||
runny s3cmd get -f ${S3_BUCKET}/${DB_NAME}.sql.gz /tmp/${DB_NAME}.sql.gz | ||
runny gunzip -f /tmp/${DB_NAME}.sql.gz | ||
|
||
start=$(date +%s) | ||
runny psql --host=${DB_HOST} --username=${DB_USER} --dbname=${DB_NAME} ${DB_OPTIONS} < /tmp/${DB_NAME}.sql | ||
end=$(date +%s) | ||
|
||
logger -p user.info "${DB_NAME} restored in $(expr ${end} - ${start}) seconds." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters