-
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.
The system was modified to remove cron, runny, rsyslog, and the integration with Logentries. All output is now sent to STDOUT/STDERR. Messages were updated and additional error handling and reporting was added.
- Loading branch information
Showing
7 changed files
with
99 additions
and
66 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,22 +1,14 @@ | ||
FROM alpine:3.8 | ||
FROM alpine:3.11 | ||
|
||
RUN apk update \ | ||
&& apk add --no-cache rsyslog rsyslog-tls \ | ||
ca-certificates openssl \ | ||
bash \ | ||
postgresql \ | ||
postgresql-client \ | ||
python py-pip \ | ||
&& update-ca-certificates \ | ||
&& apk add --no-cache \ | ||
bash \ | ||
postgresql \ | ||
postgresql-client \ | ||
python py-pip \ | ||
&& pip install s3cmd python-magic | ||
|
||
COPY dockerbuild/rsyslog.conf /etc/rsyslog.conf | ||
|
||
RUN wget https://raw.githubusercontent.com/silinternational/runny/0.2/runny -O /usr/local/bin/runny \ | ||
&& chmod +x /usr/local/bin/runny | ||
|
||
COPY application/ /data/ | ||
WORKDIR /data | ||
|
||
ENTRYPOINT ["./entrypoint.sh"] | ||
CMD ["crond -f"] | ||
CMD ["./entrypoint.sh"] |
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,15 +1,42 @@ | ||
#!/usr/bin/env sh | ||
|
||
logger -p user.info "backing up ${DB_NAME}..." | ||
STATUS=0 | ||
|
||
start=$(date +%s) | ||
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) | ||
echo "postgresql-backup-restore: backup: Started" | ||
|
||
logger -p user.info "${DB_NAME} backed up ($(stat -c %s /tmp/${DB_NAME}.sql) bytes) in $(expr ${end} - ${start}) seconds." | ||
echo "postgresql-backup-restore: Backing up ${DB_NAME}" | ||
|
||
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} | ||
start=$(date +%s) | ||
$(PGPASSWORD=${DB_USERPASSWORD} pg_dump --host=${DB_HOST} --username=${DB_USER} --create --clean ${DB_OPTIONS} --dbname=${DB_NAME} > /tmp/${DB_NAME}.sql) || STATUS=$? | ||
end=$(date +%s) | ||
|
||
logger -p user.info "${DB_NAME} backup stored in ${S3_BUCKET}." | ||
if [ $STATUS -ne 0 ]; then | ||
echo "postgresql-backup-restore: FATAL: Backup of ${DB_NAME} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds." | ||
exit $STATUS | ||
else | ||
echo "postgresql-backup-restore: Backup of ${DB_NAME} completed in $(expr ${end} - ${start}) seconds, ($(stat -c %s /tmp/${DB_NAME}.sql) bytes)." | ||
fi | ||
|
||
start=$(date +%s) | ||
gzip -f /tmp/${DB_NAME}.sql || STATUS=$? | ||
end=$(date +%s) | ||
|
||
if [ $STATUS -ne 0 ]; then | ||
echo "postgresql-backup-restore: FATAL: Compressing backup of ${DB_NAME} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds." | ||
exit $STATUS | ||
else | ||
echo "postgresql-backup-restore: Compressing backup of ${DB_NAME} completed in $(expr ${end} - ${start}) seconds." | ||
fi | ||
|
||
start=$(date +%s) | ||
s3cmd put /tmp/${DB_NAME}.sql.gz ${S3_BUCKET} || STATUS=$? | ||
end=$(date +%s) | ||
|
||
if [ $STATUS -ne 0 ]; then | ||
echo "postgresql-backup-restore: FATAL: Copy backup to ${S3_BUCKET} of ${DB_NAME} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds." | ||
exit $STATUS | ||
else | ||
echo "postgresql-backup-restore: Copy backup to ${S3_BUCKET} of ${DB_NAME} completed in $(expr ${end} - ${start}) seconds." | ||
fi | ||
|
||
echo "postgresql-backup-restore: backup: Completed" |
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,41 +1,72 @@ | ||
#!/usr/bin/env sh | ||
|
||
STATUS=0 | ||
|
||
echo "postgresql-backup-restore: restore: Started" | ||
|
||
# Does the database exist? | ||
logger -p user.info "checking for DB ${DB_NAME}..." | ||
echo "postgresql-backup-restore: 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}" | ||
echo "postgresql-backup-restore: FATAL: ${message}" | ||
exit 1 | ||
fi | ||
|
||
# Ensure the database user exists. | ||
logger -p user.info "checking for DB user ${DB_USER}..." | ||
echo "postgresql-backup-restore: 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}" | ||
echo "postgresql-backup-restore: FATAL: ${message}" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
logger -p user.info "changing DB ownership to ${DB_USER}..." | ||
echo "postgresql-backup-restore: 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}" | ||
echo "postgresql-backup-restore: FATAL: ${message}" | ||
exit 1 | ||
fi | ||
|
||
logger -p user.info "restoring ${DB_NAME}..." | ||
echo "postgresql-backup-restore: 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) | ||
s3cmd get -f ${S3_BUCKET}/${DB_NAME}.sql.gz /tmp/${DB_NAME}.sql.gz || STATUS=$? | ||
end=$(date +%s) | ||
|
||
if [ $STATUS -ne 0 ]; then | ||
echo "postgresql-backup-restore: FATAL: Copy backup of ${DB_NAME} from ${S3_BUCKET} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds." | ||
exit $STATUS | ||
else | ||
echo "postgresql-backup-restore: Copy backup of ${DB_NAME} from ${S3_BUCKET} completed in $(expr ${end} - ${start}) seconds." | ||
fi | ||
|
||
start=$(date +%s) | ||
runny psql --host=${DB_HOST} --username=${DB_USER} --dbname=${DB_NAME} ${DB_OPTIONS} < /tmp/${DB_NAME}.sql | ||
gunzip -f /tmp/${DB_NAME}.sql.gz || STATUS=$? | ||
end=$(date +%s) | ||
|
||
logger -p user.info "${DB_NAME} restored in $(expr ${end} - ${start}) seconds." | ||
if [ $STATUS -ne 0 ]; then | ||
echo "postgresql-backup-restore: FATAL: Decompressing backup of ${DB_NAME} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds." | ||
exit $STATUS | ||
else | ||
echo "postgresql-backup-restore: Decompressing backup of ${DB_NAME} completed in $(expr ${end} - ${start}) seconds." | ||
fi | ||
|
||
start=$(date +%s) | ||
psql --host=${DB_HOST} --username=${DB_USER} --dbname=${DB_NAME} ${DB_OPTIONS} < /tmp/${DB_NAME}.sql || STATUS=$? | ||
end=$(date +%s) | ||
|
||
if [ $STATUS -ne 0 ]; then | ||
echo "postgresql-backup-restore: FATAL: Restore of ${DB_NAME} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds." | ||
exit $STATUS | ||
else | ||
echo "postgresql-backup-restore: Restore of ${DB_NAME} completed in $(expr ${end} - ${start}) seconds." | ||
fi | ||
|
||
echo "postgresql-backup-restore: restore: Completed" | ||
exit $STATUS |
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
LOGENTRIES_KEY= | ||
AWS_ACCESS_KEY= | ||
AWS_SECRET_KEY= | ||
S3_BUCKET= |