Sign inSign up

pmoscode/backup-to-s3

By pmoscode

•Updated about 3 years ago

Docker container that backups files to Amazon S3

Image
0

2.7K

pmoscode/backup-to-s3 repository overview

⁠pmoscode/backup-to-s3

Docker container that backups files to Amazon S3 using aws cli⁠. If configured it can backup periodically with cron.

Fork of https://github.com/istepanov/docker-backup-to-s3⁠ with some slight changes and support for multiple architectures.

⁠Usage
docker run -d [OPTIONS] pmoscode/backup-to-s3
⁠Parameters:
  • -e S3_PATH=s3://<BUCKET_NAME>/<PATH>/: S3 Bucket name and path. Should end with trailing slash.
  • -v /path/to/backup:/data:ro: mount target local folder to container's data folder. Content of this folder will be pushed to or pulled from S3 bucket (in that case use rw instead of ro to mount the folder writable).
  • -e 'CRON_SCHEDULE=0 1 * * *': specifies when cron job starts (ticks are important) (details⁠). Or use a cron editor like: https://crontab.guru/⁠
⁠Optional parameters:
  • -e ACCESS_KEY=<AWS_KEY>: Your AWS key.
  • -e SECRET_KEY=<AWS_SECRET>: Your AWS secret.
  • -e REGION=eu-central-1: Your desired region. Default is eu-central-1

If ACCESS_KEY and SECRET_KEY are not provided, the script will assume, that it is launched in an EC2 instance (or similar AWS environment) with a proper (instance) role attached.

⁠Examples:

Run upload to S3 every day at 12:00pm:

docker run -d \
    -e ACCESS_KEY=myawskey \
    -e SECRET_KEY=myawssecret \
    -e S3_PATH=s3://my-bucket/backup/ \
    -e 'CRON_SCHEDULE=0 12 * * *' \
    -v /home/user/data:/data:ro \
    pmoscode/backup-to-s3

Run once then delete the container:

docker run --rm \
    -e ACCESS_KEY=myawskey \
    -e SECRET_KEY=myawssecret \
    -e S3_PATH=s3://my-bucket/backup/ \
    -v /home/user/data:/data:ro \
    pmoscode/backup-to-s3

Run once to get from S3 then delete the container:

docker run --rm \
    -e ACCESS_KEY=myawskey \
    -e SECRET_KEY=myawssecret \
    -e S3_PATH=s3://my-bucket/backup/ \
    -v /home/user/data:/data:rw \
    pmoscode/backup-to-s3 pull

Security considerations: on a restore, this opens up permissions on the restored files widely.

⁠Build image

docker buildx build --platform linux/arm/v6,linux/arm/v7,linux/amd64 --tag pmoscode/backup-to-s3:latest --push .

⁠Known bugs

If you are running that on a Raspberry Pi 2+ you might get this error:

Fatal Python error: pyinit_main: can't initialize time

If so, libseccomp2 could be the issue and should be updated. Take a look here: https://samcater.com/fix-workaround-rpi4-docker-libseccomp2-docker-20/⁠ or

# Get signing keys to verify the new packages, otherwise they will not install
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC 648ACFD622F3D138

# Add the Buster backport repository to apt sources.list
echo 'deb http://httpredir.debian.org/debian buster-backports main contrib non-free' | sudo tee -a /etc/apt/sources.list.d/debian-backports.list

sudo apt update
sudo apt install libseccomp2 -t buster-backports

Tag summary

Content type

Image

Digest

sha256:90c23c599…

Size

45.4 MB

Last updated

about 3 years ago

docker pull pmoscode/backup-to-s3