forked from SierraSoftworks/minback-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7c1066d
Showing
4 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
pipeline: | ||
publish:docker: | ||
image: plugins/docker | ||
repo: minback/postgres | ||
tag: | ||
- latest | ||
secrets: [ docker_username, docker_password ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Fetch the mc command line client | ||
FROM alpine:latest | ||
RUN apk update && apk add ca-certificates wget && update-ca-certificates | ||
RUN wget -O /tmp/mc https://dl.minio.io/client/mc/release/linux-amd64/mc | ||
RUN chmod +x /tmp/mc | ||
|
||
# Then build our backup image | ||
FROM postgres:9.6 | ||
LABEL maintainer="Benjamin Pannell <[email protected]>" | ||
|
||
COPY --from=0 /tmp/mc /usr/bin/mc | ||
|
||
ENV MINIO_SERVER="" | ||
ENV MINIO_BUCKET="backups" | ||
ENV MINIO_ACCESS_KEY="" | ||
ENV MINIO_SECRET_KEY="" | ||
ENV MINIO_API_VERSION="S3v4" | ||
|
||
ENV DATE_FORMAT="+%Y-%m-%d" | ||
|
||
ADD entrypoint.sh /app/entrypoint.sh | ||
|
||
ENTRYPOINT [ "/app/entrypoint.sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# minback-mongo | ||
**Minio Backup container for PostgreSQL** | ||
|
||
This container provides a trivially simple means to run `pg_dump` and fire the results off | ||
to a [Minio][] instance. It is intended to be run in conjunction with a [Kubernetes CronJob][] | ||
to maintain a frequent backup of your critical data with minimal fuss. | ||
|
||
## Features | ||
* Dumps a single MongoDB database to an S3 bucket | ||
* Lightweight and short lived | ||
* Simple and readable implementation | ||
|
||
## Example | ||
```sh | ||
docker run --rm --env-file backup.env minback/postgres my_db -h pgserver1 | ||
``` | ||
|
||
#### `backup.env` | ||
``` | ||
MINIO_SERVER=https://play.minio.io/ | ||
MINIO_ACCESS_KEY=minio | ||
MINIO_SECRET_KEY=miniosecret | ||
MINIO_BUCKET=backups | ||
``` | ||
|
||
## Usage | ||
``` | ||
DB_NAME [OPTIONS...] | ||
Arguments | ||
DB_NAME - The name of the database you wish to backup | ||
OPTIONS - Any additional options you wish to pass to mongodump | ||
``` | ||
|
||
## Configuration | ||
This container is configured using environment variables, enabling it to easily be started | ||
manually or automatically and integrate well with Kubernetes' configuration framework. | ||
|
||
#### `MINIO_SERVER=https://play.minio.io/` | ||
The Minio server you wish to send backups to. | ||
|
||
#### `MINIO_ACCESS_KEY=minio` | ||
The Access Key used to connect to your Minio server. | ||
|
||
#### `MINIO_SECRET_KEY=miniosecret` | ||
The Secret Key used to connect to your Minio server. | ||
|
||
#### `MINIO_BUCKET=backups` | ||
The Minio bucket you wish to store your backup in. | ||
|
||
### `DATE_FORMAT=+%Y-%m-%d` | ||
The date format you would like to use when naming your backup files. Files are named `$DB-$DATE.archive`. | ||
|
||
[Kubernetes CronJob]: https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/ | ||
[Minio]: https://minio.io/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#! /bin/bash | ||
set -e | ||
|
||
DB="$1" | ||
|
||
mc config host add pg "$MINIO_SERVER" "$MINIO_ACCESS_KEY" "$MINIO_SECRET_KEY" "$MINIO_API_VERSION" > /dev/null | ||
|
||
ARCHIVE="${MINIO_BUCKET}/${DB}-$(date $DATE_FORMAT).archive" | ||
|
||
echo "Dumping $DB to $ARCHIVE" | ||
echo "> pg_dump ${@:2} -F custom $DB" | ||
|
||
pg_dump "${@:2}" -F custom "$DB" | mc pipe "pg/$ARCHIVE" || mc rm "pg/$ARCHIVE" | ||
|
||
echo "Backup complete" |