2024-08-03 16:03:17 +02:00
---
title: Backup to AWS S3
layout: default
parent: How Tos
nav_order: 2
---
2025-01-13 14:40:46 +01:00
# Backup to AWS S3
2024-08-03 16:03:17 +02:00
2025-01-13 14:40:46 +01:00
To store your backups on AWS S3, you can configure the backup process to use the `--storage s3` option. This section explains how to set up and configure S3-based backups.
2024-08-03 16:03:17 +02:00
2025-01-13 14:40:46 +01:00
---
## Configuration Steps
1. **Specify the Storage Type**
Add the `--storage s3` flag to your backup command.
2. **Set the S3 Path**
Optionally, specify a custom folder within your S3 bucket where backups will be stored using the `--path` flag.
Example: `--path /my-custom-path` .
3. **Required Environment Variables**
The following environment variables are mandatory for S3-based backups:
- `AWS_S3_ENDPOINT` : The S3 endpoint URL (e.g., `https://s3.amazonaws.com` ).
- `AWS_S3_BUCKET_NAME` : The name of the S3 bucket where backups will be stored.
- `AWS_REGION` : The AWS region where the bucket is located (e.g., `us-west-2` ).
- `AWS_ACCESS_KEY` : Your AWS access key.
- `AWS_SECRET_KEY` : Your AWS secret key.
- `AWS_DISABLE_SSL` : Set to `"true"` if using an S3 alternative like Minio without SSL (default is `"false"` ).
- `AWS_FORCE_PATH_STYLE` : Set to `"true"` if using an S3 alternative like Minio (default is `"false"` ).
2024-08-03 16:03:17 +02:00
2025-01-13 14:40:46 +01:00
---
## Example Configuration
Below is an example `docker-compose.yml` configuration for backing up to AWS S3:
2024-08-03 16:03:17 +02:00
2025-01-13 14:40:46 +01:00
```yaml
2024-08-03 16:03:17 +02:00
services:
mysql-bkup:
2025-01-13 14:40:46 +01:00
# In production, lock your image tag to a specific release version
# instead of using `latest` . Check https://github.com/jkaninda/pg-bkup/releases
# for available releases.
image: jkaninda/pg-bkup
container_name: pg-bkup
2024-08-10 10:50:00 +02:00
command: backup --storage s3 -d database --path /my-custom-path
2024-08-03 16:03:17 +02:00
environment:
2025-01-13 14:40:46 +01:00
- DB_PORT=5432
- DB_HOST=postgres
2024-08-03 16:03:17 +02:00
- DB_NAME=database
- DB_USERNAME=username
- DB_PASSWORD=password
2025-01-13 14:40:46 +01:00
## AWS Configuration
2024-08-03 16:03:17 +02:00
- AWS_S3_ENDPOINT=https://s3.amazonaws.com
- AWS_S3_BUCKET_NAME=backup
2025-01-13 14:40:46 +01:00
- AWS_REGION=us-west-2
2024-08-03 16:03:17 +02:00
- AWS_ACCESS_KEY=xxxx
- AWS_SECRET_KEY=xxxxx
2025-01-13 14:40:46 +01:00
## Optional: Disable SSL for S3 alternatives like Minio
2024-08-03 16:03:17 +02:00
- AWS_DISABLE_SSL="false"
2025-01-13 14:40:46 +01:00
## Optional: Enable path-style access for S3 alternatives like Minio
- AWS_FORCE_PATH_STYLE=false
# Ensure the mysql-bkup container is connected to the same network as your database
2024-08-03 16:03:17 +02:00
networks:
- web
2025-01-13 14:40:46 +01:00
2024-08-03 16:03:17 +02:00
networks:
web:
```
2025-01-13 14:40:46 +01:00
---
## Recurring Backups to S3
To schedule recurring backups to S3, use the `--cron-expression` flag or the `BACKUP_CRON_EXPRESSION` environment variable. This allows you to define a cron schedule for automated backups.
2024-08-03 16:03:17 +02:00
2025-01-13 14:40:46 +01:00
### Example: Recurring Backup Configuration
2024-08-03 16:03:17 +02:00
2025-01-13 14:40:46 +01:00
```yaml
2024-08-03 16:03:17 +02:00
services:
mysql-bkup:
2025-01-13 14:40:46 +01:00
# In production, lock your image tag to a specific release version
# instead of using `latest` . Check https://github.com/jkaninda/mysql-bkup/releases
# for available releases.
2024-08-03 16:03:17 +02:00
image: jkaninda/mysql-bkup
container_name: mysql-bkup
2025-01-13 14:40:46 +01:00
command: backup --storage s3 -d database --cron-expression "0 1 * * *"
2024-08-03 16:03:17 +02:00
environment:
- DB_PORT=3306
- DB_HOST=mysql
- DB_NAME=database
- DB_USERNAME=username
- DB_PASSWORD=password
2025-01-13 14:40:46 +01:00
## AWS Configuration
2024-08-03 16:03:17 +02:00
- AWS_S3_ENDPOINT=https://s3.amazonaws.com
- AWS_S3_BUCKET_NAME=backup
2025-01-13 14:40:46 +01:00
- AWS_REGION=us-west-2
2024-08-03 16:03:17 +02:00
- AWS_ACCESS_KEY=xxxx
- AWS_SECRET_KEY=xxxxx
2025-01-13 14:40:46 +01:00
## Optional: Define a cron schedule for recurring backups
#- BACKUP_CRON_EXPRESSION=0 1 * * *
## Optional: Delete old backups after a specified number of days
2024-10-20 06:52:36 +02:00
#- BACKUP_RETENTION_DAYS=7
2025-01-13 14:40:46 +01:00
## Optional: Disable SSL for S3 alternatives like Minio
2024-08-03 16:03:17 +02:00
- AWS_DISABLE_SSL="false"
2025-01-13 14:40:46 +01:00
## Optional: Enable path-style access for S3 alternatives like Minio
- AWS_FORCE_PATH_STYLE=false
# Ensure the pg-bkup container is connected to the same network as your database
2024-08-03 16:03:17 +02:00
networks:
- web
2025-01-13 14:40:46 +01:00
2024-08-03 16:03:17 +02:00
networks:
web:
```
2025-01-13 14:40:46 +01:00
---
## Key Notes
- **Cron Expression**: Use the `--cron-expression` flag or `BACKUP_CRON_EXPRESSION` environment variable to define the backup schedule. For example, `0 1 * * *` runs the backup daily at 1:00 AM.
- **Backup Retention**: Optionally, use the `BACKUP_RETENTION_DAYS` environment variable to automatically delete backups older than a specified number of days.
- **S3 Alternatives**: If using an S3 alternative like Minio, set `AWS_DISABLE_SSL="true"` and `AWS_FORCE_PATH_STYLE="true"` as needed.