Skip to content

Commit 63fc9d9

Browse files
authored
Merge pull request #25 from sil-org/use-aws-cli
use the AWS CLI instead of s3cmd
2 parents ec6b308 + 96eda43 commit 63fc9d9

File tree

3 files changed

+19
-32
lines changed

3 files changed

+19
-32
lines changed

Dockerfile

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,17 @@
1-
# With Python 3.12.4 on Alpine 3.20, s3cmd 2.4.0 fails with an AttributeError.
2-
# See ITSE-1440 for details.
31
FROM python:3.12.4-alpine
42

5-
# Current version of s3cmd is in edge/testing repo
6-
RUN echo https://dl-cdn.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories
3+
RUN <<EOF
4+
apk update
5+
apk add --no-cache \
6+
bash \
7+
curl \
8+
postgresql14-client \
9+
py3-pip
710

8-
# Install everything via repo because repo & pip installs can break things
9-
RUN apk update \
10-
&& apk add --no-cache \
11-
bash \
12-
postgresql14-client \
13-
py3-magic \
14-
py3-dateutil \
15-
curl \
16-
jq
17-
18-
RUN wget https://github.com/s3tools/s3cmd/archive/refs/tags/v2.4.0.tar.gz \
19-
&& tar xzf v2.4.0.tar.gz \
20-
&& cd s3cmd-2.4.0 \
21-
&& python setup.py install \
22-
&& cd .. \
23-
&& rm -rf s3cmd-2.4.0 v2.4.0.tar.gz
24-
# Install sentry-cli
25-
RUN curl -sL https://sentry.io/get-cli/ | bash
11+
curl -sL https://sentry.io/get-cli/ | bash
12+
13+
pip3 install awscli
14+
EOF
2615

2716
COPY application/ /data/
2817
WORKDIR /data

application/backup.sh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ fi
121121

122122
# Upload compressed backup file to S3
123123
start=$(date +%s);
124-
s3cmd put /tmp/${DB_NAME}.sql.gz ${S3_BUCKET} || STATUS=$?;
124+
aws s3 cp "/tmp/${DB_NAME}.sql.gz" "s3://${S3_BUCKET}/${DB_NAME}.sql.gz" || STATUS=$?
125125
if [ $STATUS -ne 0 ]; then
126126
error_message="${MYNAME}: FATAL: Copy backup to ${S3_BUCKET} of ${DB_NAME} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds.";
127127
log "ERROR" "${error_message}";
@@ -130,7 +130,7 @@ if [ $STATUS -ne 0 ]; then
130130
fi
131131

132132
# Upload checksum file
133-
s3cmd put /tmp/${DB_NAME}.sql.sha256.gz ${S3_BUCKET} || STATUS=$?;
133+
aws s3 cp "/tmp/${DB_NAME}.sql.sha256.gz" "s3://${S3_BUCKET}/${DB_NAME}.sql.sha256.gz" || STATUS=$?;
134134
end=$(date +%s);
135135
if [ $STATUS -ne 0 ]; then
136136
error_message="${MYNAME}: FATAL: Copy checksum to ${S3_BUCKET} of ${DB_NAME} returned non-zero status ($STATUS).";
@@ -144,12 +144,10 @@ fi
144144
# Backblaze B2 Upload
145145
if [ "${B2_BUCKET}" != "" ]; then
146146
start=$(date +%s);
147-
s3cmd \
148-
--access_key=${B2_APPLICATION_KEY_ID} \
149-
--secret_key=${B2_APPLICATION_KEY} \
150-
--host=${B2_HOST} \
151-
--host-bucket='%(bucket)s.'"${B2_HOST}" \
152-
put /tmp/${DB_NAME}.sql.gz s3://${B2_BUCKET}/${DB_NAME}.sql.gz;
147+
AWS_ACCESS_KEY_ID="${B2_APPLICATION_KEY_ID}" \
148+
AWS_SECRET_ACCESS_KEY="${B2_APPLICATION_KEY}" \
149+
aws s3 cp "/tmp/${DB_NAME}.sql.gz" "s3://${B2_BUCKET}/${DB_NAME}.sql.gz" \
150+
--endpoint-url "https://${B2_HOST}"
153151
STATUS=$?;
154152
end=$(date +%s);
155153
if [ $STATUS -ne 0 ]; then

application/restore.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ log "INFO" "${MYNAME}: copying database ${DB_NAME} backup and checksum from ${S3
9595
start=$(date +%s)
9696

9797
# Download database backup
98-
s3cmd get -f ${S3_BUCKET}/${DB_NAME}.sql.gz /tmp/${DB_NAME}.sql.gz || STATUS=$?
98+
aws s3 cp s3://${S3_BUCKET}/${DB_NAME}.sql.gz /tmp/${DB_NAME}.sql.gz || STATUS=$?
9999
if [ $STATUS -ne 0 ]; then
100100
error_message="${MYNAME}: FATAL: Copy backup of ${DB_NAME} from ${S3_BUCKET} returned non-zero status ($STATUS) in $(expr $(date +%s) - ${start}) seconds."
101101
log "ERROR" "${error_message}"
@@ -104,7 +104,7 @@ if [ $STATUS -ne 0 ]; then
104104
fi
105105

106106
# Download checksum file
107-
s3cmd get -f ${S3_BUCKET}/${DB_NAME}.sql.sha256.gz /tmp/${DB_NAME}.sql.sha256.gz || STATUS=$?
107+
aws s3 cp s3://${S3_BUCKET}/${DB_NAME}.sql.sha256.gz /tmp/${DB_NAME}.sql.sha256.gz || STATUS=$?
108108
end=$(date +%s)
109109
if [ $STATUS -ne 0 ]; then
110110
error_message="${MYNAME}: FATAL: Copy checksum of ${DB_NAME} from ${S3_BUCKET} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds."

0 commit comments

Comments
 (0)