Skip to content

Commit 9f438ec

Browse files
committed
Write better readme
Signed-off-by: Nikolai Rodionov <iam@allanger.xyz>
1 parent b33c033 commit 9f438ec

2 files changed

Lines changed: 42 additions & 8 deletions

File tree

README.md

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,46 @@
1-
# pgdump-gcs
1+
# Postgres backup container for DB Operator
22

3-
Small docker container for creating a backup of a psql database and upload the dump to an external storage using rclone.
3+
Small docker container for creating a backup of a psql database and uploading it to an external storage using rclone.
4+
5+
Every backup is uploaded twice, once with a **timestamp** and once as **latest**. So you can always download the latest backup.
6+
7+
There is no clean-up logic, please take care of old backups using external tools, for example bucket retention policies.
8+
9+
## How to restore
10+
11+
This script is simply taking a database backup using `pg_dump`, you can restore it by setting env variables and running the following command:
12+
13+
```shell
14+
$ export PGHOST=< Database host >
15+
$ export PGPORT=< Database port >
16+
$ export PGUSER=< Admin user>
17+
$ export PGDATABASE=postgres
18+
$ export PGPASSWORD=< Admin password >
19+
$ pg_restore --no-owne:wr --no-privileges -d < Target database > --role < Target username > -Fc < Backup file path> --clean
20+
```
421

522
## How to use
6-
TO BE DONE ...
723

8-
## monitoring
24+
This container is supposed to be used by the DB Operator for setting up backup CronJobs.
25+
26+
To backup a postgres database using this container you need to pass env variables for `pg_dump` and for `rclone`:
27+
28+
**pg_dump** variables:
29+
30+
- **DB_NAME**: A name of a database to back up
31+
- **DB_HOST**: A database server host
32+
- **DB_PASSWORD_FILE**: A path to a file with a database password (file must be mounted to the container)
33+
- **DB_USER**: User that should perform the backup
34+
35+
**rclone** variables:
36+
37+
- **STORAGE_BUCKET**: A name of a bucket/directory that should be used for uploading the backup
38+
39+
For the rest, please check here: <https://rclone.org/docs/#environment-variables>.
40+
41+
The backend name is hardcoded to 'storage', so your env vars should be prefixed by `RCLONE_CONFIG_STORAGE_`
42+
43+
## Monitoring
944

1045
Simple curl pushing some basic parameter to a prometheus push gateway.
1146

@@ -15,6 +50,6 @@ Simple curl pushing some basic parameter to a prometheus push gateway.
1550
* size
1651

1752
### labels
18-
* job = pgdump-gcs
53+
* job = pgdump-rclone
1954
* source_type = postgresql
2055
* source_name = `${DB_NAME}`

entrypoint.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ fi
1919
# create login credential file
2020
(umask 377 && echo *:5432:*:${DB_USER}:${DB_PASSWORD} >> ~/.pgpass)
2121

22-
echo "Start create backup"
22+
echo "Backing up"
2323
pg_dump -F c -Z 9 -h ${DB_HOST} -p 5432 -U ${DB_USER} ${DB_NAME} -f ${BACKUP_FILE}
2424
BACKUP_SIZE=$(du ${BACKUP_FILE} | awk '{print $1}')
25-
echo "End backup"
2625

2726
## copy to destination
28-
echo "Copy to gcs"
27+
echo "Uploading to a storage"
2928
rclone copyto "./${BACKUP_FILE}" "storage://${STORAGE_BUCKET}/${DB_NAME}/${BACKUP_FILE}"
3029
rclone copyto "./${BACKUP_FILE}" "storage://${STORAGE_BUCKET}/${DB_NAME}/${BACKUP_FILE_LATEST}"
3130

0 commit comments

Comments
 (0)