1
0
mirror of https://github.com/garraflavatra/docker-volume-s3-backup.git synced 2025-05-17 13:14:38 +00:00

88 lines
2.9 KiB
Markdown
Raw Normal View History

# docker-volume-s3-backup
## Introduction
2025-05-04 13:38:00 +02:00
This project provides a Docker image that periodically backs up a Docker volume to AWS S3 as a gzipped tape archive, and can restore a backup as needed.
## Usage
### Backup
Example `docker-compose.yml`:
2019-11-27 20:57:21 -07:00
```yaml
2022-07-03 13:47:02 -04:00
services:
my_service:
image: ...
volumes:
data:/app/some-data-dir
2019-11-27 20:57:21 -07:00
volume_backup:
2025-05-04 14:00:29 +02:00
image: garraflavatra/docker-volume-s3-backup
2025-05-04 13:54:42 +02:00
volumes:
data:/data/folder1
2022-07-03 13:47:02 -04:00
environment:
2025-05-04 13:54:42 +02:00
BACKUP_NAME: myvolume # required
SCHEDULE: '@weekly' # optional
BACKUP_KEEP_DAYS: 7 # optional
PASSPHRASE: passphrase # optional
S3_REGION: region # or set S3_ENDPOINT if you do not use AWS
S3_ACCESS_KEY_ID: key # alias S3_ACCESS_KEY
S3_SECRET_ACCESS_KEY: secret # alias S3_SECRET_KEY
S3_BUCKET: my-bucket # required
S3_PREFIX: backup # required
2019-11-27 20:57:21 -07:00
```
2022-04-12 21:39:51 +03:00
2025-05-04 13:54:42 +02:00
- You can mount as many folders into `/data` as you like. Everything in `/data` is copied to your S3 storage in a single `.tar.gz`.
- The `SCHEDULE` variable determines backup frequency. See go-cron schedules documentation [here](http://godoc.org/github.com/robfig/cron#hdr-Predefined_schedules). Omit to run the backup immediately and then exit.
2019-12-01 18:47:18 -07:00
- If `PASSPHRASE` is provided, the backup will be encrypted using GPG.
- Run `docker exec <container_name> sh backup.sh` to trigger a backup ad-hoc.
2023-01-29 12:23:42 -05:00
- If `BACKUP_KEEP_DAYS` is set, backups older than this many days will be deleted from S3.
- Set `S3_ENDPOINT` if you're using a non-AWS S3-compatible storage provider.
2019-11-27 20:57:21 -07:00
### Restore
2025-05-04 13:38:00 +02:00
> [!NOTE]
> The restore command is yet to be ported from the original restore script from [`eeshugerman/postgres-backup-s3`](https://github.com/eeshugerman/postgres-backup-s3). Contributions are welcome :)
> [!CAUTION]
2025-05-04 13:38:00 +02:00
> DATA LOSS! All folder content will be dropped and re-created.
#### ... from latest backup
2019-11-27 20:57:21 -07:00
```sh
docker exec <container_name> sh restore.sh
2019-11-27 20:57:21 -07:00
```
> [!NOTE]
> If your bucket has more than a 1000 files, the latest may not be restored -- only one S3 `ls` command is used
#### ... from specific backup
2019-12-01 21:49:48 -07:00
2022-07-03 12:23:22 -04:00
```sh
docker exec <container_name> sh restore.sh <timestamp>
2022-07-03 12:23:22 -04:00
```
## Development
### Run a simple test environment with Docker Compose
```sh
2025-05-04 14:00:29 +02:00
cp .env.example .env
# fill out your secrets/params in .env
docker compose up -d
```
2022-07-03 12:23:22 -04:00
## Acknowledgements
This project is a modification of the excellent [`eeshugerman/postgres-backup-s3`](https://github.com/eeshugerman/postgres-backup-s3), which in turn is a fork and re-structuring of [`schickling/postgres-backup-s3`](https://github.com/schickling/dockerfiles/tree/master/postgres-backup-s3) and [`schickling/postgres-restore-s3`](https://github.com/schickling/dockerfiles/tree/master/postgres-restore-s3).
## Copyright
Copyright (c) 2017 Johannes Schickling
Copyright (c) 2022 Elliott Shugerman
Copyright (c) 2025 [Romein van Buren](mailto:romein@smartyellow.nl)
Licensed under the MIT license.