Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dalenewby committed Apr 13, 2022
2 parents b41486a + 3bf9a14 commit 842d654
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion application/restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,23 @@ if [ -z "${result}" ]; then
fi
fi

echo "postgresql-backup-restore: restoring ${DB_NAME}"
# Delete database if it exists.
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."
echo "postgresql-backup-restore: INFO: ${message}"
else
echo "postgresql-backup-restore: deleting database ${DB_NAME}"
result=$(psql --host=${DB_HOST} --dbname=postgres --username=${DB_USER} --command="DROP DATABASE ${DB_NAME};")
if [ "${result}" != "DROP DATABASE" ]; then
message="Create database command failed: ${result}"
echo "postgresql-backup-restore: FATAL: ${message}"
exit 1
fi
fi

echo "postgresql-backup-restore: copying database ${DB_NAME} backup from ${S3_BUCKET}"
start=$(date +%s)
s3cmd get -f ${S3_BUCKET}/${DB_NAME}.sql.gz /tmp/${DB_NAME}.sql.gz || STATUS=$?
end=$(date +%s)
Expand All @@ -29,6 +44,7 @@ else
echo "postgresql-backup-restore: Copy backup of ${DB_NAME} from ${S3_BUCKET} completed in $(expr ${end} - ${start}) seconds."
fi

echo "postgresql-backup-restore: decompressing backup of ${DB_NAME}"
start=$(date +%s)
gunzip -f /tmp/${DB_NAME}.sql.gz || STATUS=$?
end=$(date +%s)
Expand All @@ -40,6 +56,7 @@ else
echo "postgresql-backup-restore: Decompressing backup of ${DB_NAME} completed in $(expr ${end} - ${start}) seconds."
fi

echo "postgresql-backup-restore: restoring ${DB_NAME}"
start=$(date +%s)
psql --host=${DB_HOST} --username=${DB_ROOTUSER} --dbname=postgres ${DB_OPTIONS} < /tmp/${DB_NAME}.sql || STATUS=$?
end=$(date +%s)
Expand Down

0 comments on commit 842d654

Please sign in to comment.