Skip to content

Commit

Permalink
Make s3-sync usable with others than AWS S3
Browse files Browse the repository at this point in the history
  • Loading branch information
back-2-95 committed Jan 31, 2024
1 parent 59ca89b commit 4b9a59c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
18 changes: 13 additions & 5 deletions misc/s3-sync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@ Container to sync backups to Amazon S3 and get them from there using s3cmd.
- Mount local path `/abs/path/to/backups` to container in `/data`
- Sync all files from local path to S3 bucket `foobar-bucket`

```
```console
docker run -it -e ACCESS_KEY=foobar -e SECRET_KEY=foobar -e S3_PATH=s3://foobar-bucket \
-v /abs/path/to/backups:/data druidfi/s3-sync sync
```

## Run in cron mode
## Use custom s3cmd configuration

```console
docker run -it -e S3_PATH=s3://foobar-bucket \
-v /abs/path/to/.s3cfg:/root/.s3cfg:ro \
-v /abs/path/to/backups:/data druidfi/s3-sync
```

## Run in cron mode

```console
docker run -it -e ACCESS_KEY=foobar -e SECRET_KEY=foobar -e S3_PATH=s3://foobar-bucket -e CRON_SCHEDULE="*/5 * * * *" \
-v /abs/path/to/backups:/data druidfi/s3-sync
```
Expand All @@ -24,9 +32,9 @@ docker run -it -e ACCESS_KEY=foobar -e SECRET_KEY=foobar -e S3_PATH=s3://foobar-
- See the documentation in https://s3tools.org/usage
- Sync specific documentation in https://s3tools.org/s3cmd-sync

## How to give access to S3 bucket
## How to give access to AWS S3 bucket

```
```json
{
"Version": "2008-10-17",
"Statement": [
Expand All @@ -50,4 +58,4 @@ docker run -it -e ACCESS_KEY=foobar -e SECRET_KEY=foobar -e S3_PATH=s3://foobar-
}
]
}
```
```
17 changes: 11 additions & 6 deletions misc/s3-sync/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
# shellcheck disable=SC2086

DATA_PATH="/data/"
S3CMD_BIN="/usr/bin/s3cmd"

: "${ACCESS_KEY:?"ACCESS_KEY env variable is required"}"
: "${SECRET_KEY:?"SECRET_KEY env variable is required"}"
REGION=${REGION:-eu-central-1}
if [ -n "${REGION}" ]; then
$S3CMD_BIN="${$S3CMD_BIN} --region=${REGION}"
fi

if [ -n "${ACCESS_KEY}" ]; then
$S3CMD_BIN="${$S3CMD_BIN} --access_key=${ACCESS_KEY}"
fi

S3CMD_BIN="/usr/bin/s3cmd --region=$REGION"
S3CMD_BIN="$S3CMD_BIN --access_key=$ACCESS_KEY"
S3CMD_BIN="$S3CMD_BIN --secret_key=$SECRET_KEY"
if [ -n "${SECRET_KEY}" ]; then
$S3CMD_BIN="${$S3CMD_BIN} --secret_key=${SECRET_KEY}"
fi

if [ "$1" = 'conf' ]; then
echo -e "\n\nsc3cmd:" "$S3CMD_BIN" "\n\n"
Expand Down

0 comments on commit 4b9a59c

Please sign in to comment.