Backup any local folder/volume to a S3 compatible object storage location
Tested with:
- Scaleway Object storage
s3cmd will manage all files in your bucket. Do not upload other files manually, or they will be remove once their expiration datetime is passed. Use a dedicated bucket.
See https://www.scaleway.com/en/docs/object-storage-with-s3cmd/ to populate your .env vars:
S3_ACCESS_KEYS3_SECRET_KEYS3_SIGNATURES3_BUCKET_LOCATIONS3_HOST_BASES3_HOST_BUCKETS3_BUCKET_NAME- Bucket nameS3_FOLDER_NAME- Objects folder (prefix) without ending slashS3_CHUNK_SIZE- Chunk size in MB (be careful, chunks count is limited to 1000 on Scaleway Object storage)S3_STORAGE_CLASS- Default:STANDARD- Stores object with specified CLASS (STANDARD,STANDARD_IA, orREDUCED_REDUNDANCY) - For scaleway.com:STANDARD: The Standard class for any upload; suitable for on-demand content like streaming or CDNONEZONE_IA: TheONEZONE_IAclass available only on FR-PAR is a good choice for storing secondary backup copies or easily re-creatable data.GLACIER: Archived storage. Your data needs to be restored first to be accessed. This class is available in the FR-PAR and NL-AMS regions.
LOCAL_PATH- Absolute path for folder to back up (default:/var/www/html) - Set it tofalseif you want to skip files backupCOMPRESS- (Optional) Default:1, compress files TAR archive
DB_USER- (Optional) MySQL user nameDB_HOST- (Optional) MySQL host nameDB_PASS- (Optional) MySQL user passwordDB_NAME- (Optional) MySQL namePGDATABASE- (Optional) PostgreSQL Database namPGHOST- (Optional) PostgreSQL host namePGOPTIONS- (Optional) PostgreSQL optionsPGPORT- (Optional) PostgreSQL portPGUSER- (Optional) PostgreSQL user namePGPASSWORD- (Optional) PostgreSQL user password
Your PostgreSQL server version must match pg_dump: version 12.x max
docker-compose run --rm backupYou can run any command instead of backup, for example listing your bucket files:
docker-compose run --rm backup s3cmd ls s3://mybucket/backups/Use Lifecycle rules or Object Lifecycle Management to define rules to expire or transfer your backup files to Glacier.
For example you can define an expiry policy based on your objects prefix: ${S3_FOLDER_NAME}/ which is backups/.
backup:
image: ambroisemaupate/s3-backup
networks:
- default
depends_on:
- db
environment:
LOCAL_PATH: /var/www/html
# Use MySQL
DB_USER: ${MYSQL_USER}
DB_HOST: db
DB_PASS: ${MYSQL_PASSWORD}
DB_NAME: ${MYSQL_DATABASE}
# Or use PostgreSQL
# PGDATABASE: ${PGDATABASE}
# PGHOST: db
# PGUSER: ${PGUSER}
# PGPASSWORD: ${PGPASSWORD}
S3_ACCESS_KEY: xxxxxxxxx
S3_SECRET_KEY: xxxxxxxxx
S3_SIGNATURE: s3v4
S3_BUCKET_LOCATION: fr-par
S3_HOST_BASE: https://s3.fr-par.scw.cloud
S3_HOST_BUCKET: https://mybucket.s3.fr-par.scw.cloud
S3_BUCKET_NAME: mybucket
S3_FOLDER_NAME: site-backups
S3_STORAGE_CLASS: STANDARD
volumes:
- public_files:/var/www/html/web/files:roThen execute it manually:
docker-compose run --rm --no-deps backupOr from your crontab:
00 0 * * * cd /root/docker-server-env/compose/my_site && /usr/local/bin/docker-compose run --no-deps --rm backup
You can encrypt your backup files with GPG public keys. You must provide a gpg file with any public keys and share it as a volume into /pubkeys.gpg (GPG_PUBLIC_KEYS_PATH env var contains path to pubkeys file).
backup:
image: ambroisemaupate/s3-backup
# ...
volumes:
- ./pubkeys.gpg:/pubkeys.gpg:ro
- public_files:/var/www/html/web/files:roAll public keys will be used to encrypt your backup files. Pay attention that encrypted files size will be bigger than original files, especially if you are using multiple recipients (https://security.stackexchange.com/questions/8245/gpg-file-size-with-multiple-recipients).
You can create a pubkey.gpg file by exporting your public key:
gpg -a --export [your public key ID] [an another pub key ID] > pubkeys.gpgProvide SENTRY_DSN env var to enable Sentry logging.
backup:
image: ambroisemaupate/s3-backup
# ...
environment:
SENTRY_DSN: https://xxxxxxx.ingest.sentry.io/xxxxxxx- Copy
.env.distto.env - Use
docker-compose.ymlto test locally - Launch backup
docker-compose run --rm backup