Skip to content

Commit e50464f

Browse files
Merge pull request #24 from Nsttt/add-readme
Add readme and compose file
2 parents d45032b + 79bc5a5 commit e50464f

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

README.md

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# PostgreSQL Backup to S3 with Docker
2+
3+
This application automates the process of backing up PostgreSQL databases and uploading them to an S3-compatible storage service, utilizing Docker for easy deployment and scheduling.
4+
5+
## Features
6+
7+
- Easy deployment with Docker and Docker Compose.
8+
- Support for multiple PostgreSQL databases.
9+
- Customizable backup intervals.
10+
- Direct upload of backups to an S3-compatible storage bucket.
11+
- Environment variable and command-line configuration for flexibility.
12+
- Secure handling of database and S3 credentials.
13+
14+
## Prerequisites
15+
16+
- Docker and Docker Compose installed on your system.
17+
- Access to a PostgreSQL database.
18+
- Access to an S3-compatible storage service.
19+
20+
## Configuration
21+
22+
Before running the application, you need to configure it either by setting environment variables in a `.env` file or by using command-line flags in the `docker-compose.yml`.
23+
24+
### Environment Variables
25+
26+
Create a `.env` file in the project directory with the following variables:
27+
28+
- `URLS`: Comma-separated list of PostgreSQL database URLs to backup. Format: `postgres://<user>:<password>@<host>[:<port>]/<dbname>`
29+
- `S3_ENDPOINT`: The endpoint URL of your S3-compatible storage service.
30+
- `S3_BUCKET`: The name of the bucket where backups will be stored.
31+
- `S3_ACCESS_KEY`: Your S3 access key.
32+
- `S3_SECRET_KEY`: Your S3 secret key.
33+
- `INTERVAL`: How often to run the backup (e.g., `24h` for daily backups).
34+
35+
### Docker Compose
36+
37+
Alternatively, you can specify the configuration directly in the `docker-compose.yml` file under the `environment` section of your service:
38+
39+
```yaml
40+
services:
41+
app:
42+
build: .
43+
environment:
44+
URLS: "postgres://user:password@host:port/dbname"
45+
S3_ENDPOINT: "your_s3_endpoint"
46+
S3_BUCKET: "your_s3_bucket"
47+
S3_ACCESS_KEY: "your_s3_access_key"
48+
S3_SECRET_KEY: "your_s3_secret_key"
49+
INTERVAL: "24h"
50+
```
51+
52+
## Running the Application with Docker
53+
54+
There is an image available on `ghcr.io/thedevminertv/postgres_s3_backup` that you can use.
55+
56+
Alternatively, you can build the image yourself:
57+
58+
1. Build the Docker image:
59+
60+
```sh
61+
docker compose build
62+
```
63+
64+
2. Start the application:
65+
66+
```sh
67+
docker compose up -d
68+
```
69+
70+
This will start the application in the background. It will automatically perform backups based on the configured interval and upload them to the specified S3 bucket.
71+
72+
## Monitoring and Logs
73+
74+
To monitor the application's activity and view logs:
75+
76+
```sh
77+
docker compose logs -f
78+
```
79+
80+
This command will follow the log output of the container. Press `Ctrl+C` to exit log following.
81+
82+
## Updating Configuration
83+
84+
If you need to update the configuration, modify the `.env` file or the `docker-compose.yml` as necessary and restart the service:
85+
86+
```sh
87+
docker compose down
88+
docker compose up -d
89+
```

compose.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: "3.9"
2+
3+
services:
4+
pg_s3_backup:
5+
build: .
6+
environment:
7+
URLS: "postgres://user:password@host:port/dbname"
8+
S3_ENDPOINT: "your_s3_endpoint"
9+
S3_BUCKET: "your_s3_bucket"
10+
S3_ACCESS_KEY: "your_s3_access_key"
11+
S3_SECRET_KEY: "your_s3_secret_key"
12+
INTERVAL: "24h"

0 commit comments

Comments
 (0)