Commit ef58fdb3 authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Ajusta el proyecto a su nueva finalidad

Revisa y mejora el script principal.
Adapta la contrucción de imagen Docker y despliegue del servicio a las
nuevas necesidades.
Modifica y añade variables de configuración.
Actualiza readme y licencia.
parent 9f6ce1b9
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -10,5 +10,5 @@ stages:

.docker-build:
  variables:
    IMAGE_NAME_VARIABLE_NAME: BACKUP_POSTGRESQL_IMAGE_NAME
    IMAGE_TAG_VARIABLE_NAME: BACKUP_POSTGRESQL_IMAGE_TAG
    IMAGE_NAME_VARIABLE_NAME: BACKUP_FILES_IMAGE_NAME
    IMAGE_TAG_VARIABLE_NAME: BACKUP_FILES_IMAGE_TAG
+15 −19
Original line number Diff line number Diff line
@@ -4,35 +4,27 @@ FROM alpine:${ALPINE_IMAGE_TAG}

LABEL maintainer="info@redmic.es"

ENV POSTGRES_USER=postgres \
	POSTGRES_PORT=5432 \
	POSTGRES_DUMP_PATH=/tmp/backup \
	POSTGRES_PASS_FILE=/root/.pgpass \
ARG BACKUP_PATH=/backup \
	CURL_VERSION=7.74.0-r1 \
	BASH_VERSION=5.1.0-r0 \
	GLIBC_VERSION=2.33-r0 \
	AWS_CLI_VERSION=2.0.30

ENV BACKUP_PATH=${BACKUP_PATH} \
	WORK_PATH=/tmp/backup \
	AWS_DEFAULT_REGION=eu-west-1 \
	PUSHGATEWAY_HOST=pushgateway:9091 \
	AWS_OUTPUT=json

COPY scripts /

ARG CURL_VERSION=7.74.0-r1 \
	POSTGRESQL_CLIENT_VERSION=13.2-r0 \
	BASH_VERSION=5.1.0-r0

# hadolint ignore=DL3018
RUN apk update && \
	apk list \
		curl \
		postgresql-client \
		bash && \
	apk add --no-cache \
		curl="${CURL_VERSION}" \
		postgresql-client="${POSTGRESQL_CLIENT_VERSION}" \
		bash="${BASH_VERSION}"

ARG GLIBC_VERSION=2.33-r0 \
	AWS_CLI_VERSION=2.0.30

# hadolint ignore=DL3018
RUN curl -sL https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub -o /etc/apk/keys/sgerrand.rsa.pub && \
		bash="${BASH_VERSION}" && \
	curl -sL https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub -o /etc/apk/keys/sgerrand.rsa.pub && \
	curl -sL "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-${GLIBC_VERSION}.apk" -o glibc.apk && \
	curl -sL "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-bin-${GLIBC_VERSION}.apk" -o glibc-bin.apk && \
	apk add --no-cache \
@@ -52,4 +44,8 @@ RUN curl -sL https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub -o /etc/apk/keys/
		/usr/local/aws-cli/v2/*/dist/awscli/data/ac.index \
		/usr/local/aws-cli/v2/*/dist/awscli/examples

COPY scripts /

VOLUME ${BACKUP_PATH}

ENTRYPOINT ["/docker-entrypoint.sh"]
+1 −0
Original line number Diff line number Diff line
MIT License

Copyright (c) 2021 REDMIC Project / Postgres
Copyright (c) 2021 REDMIC Project / Maintenance

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
+31 −35
Original line number Diff line number Diff line
# Backup PostgreSQL
# Backup files

Backup PostgreSQL is a service for creating PostgreSQL database backups and uploading them to AWS S3 (or S3-compatible service).
Service for creating arbitrary files backups and uploading them to AWS S3 (or S3-compatible service).
Also sends metrics to Prometheus through Pushgateway.

![alt schema-db](images/schema-backup-db.png)
@@ -8,41 +8,37 @@ Also sends metrics to Prometheus through Pushgateway.
## Build arguments

|       Name       |           Description             |
|---------------------------|--------------------------------------|
|------------------|-----------------------------------|
| ALPINE_IMAGE_TAG | Base Docker image tag             |
| CURL_VERSION     | cURL dependency version           |
| POSTGRESQL_CLIENT_VERSION | PostgreSQL-client dependency version |
| BASH_VERSION     | Bash dependency version           |
| GLIBC_VERSION    | glibc dependency version          |
| AWS_CLI_VERSION  | AWS (cli v2) dependency version   |
| BACKUP_PATH      | Root path to find paths to backup |

## Variables

|         Name          |                   Description                   |        Default       |
|-----------------------|---------------------------------|----------------------|
| POSTGRES_USER         | Database username               | postgres             |
| POSTGRES_PASSWORD     | Database password               | changeme             |
| POSTGRES_HOSTNAME     | Database hostname               | changeme             |
| POSTGRES_PORT         | Database port                   | 5432                 |
| POSTGRES_DUMP_PATH    | Temporal path                   | /tmp/backup          |
| POSTGRES_PASS_FILE    | PG credentials file path        | /root/.pgpass        |
| DUMP_FILENAME         | File name for uploads           | db.dump              |
| BUCKET_BACKUP_DB      | Bucket name for uploads         | backup-db            |
|-----------------------|-------------------------------------------------|----------------------|
| BACKUP_PATH           | Root path to find paths to backup               | /backup              |
| PATHS_TO_BACKUP       | Paths to include in backup (separated by space) |                      |
| WORK_PATH             | Temporal path for working                       | /tmp/backup          |
| UPLOAD_BUCKET         | Bucket name for uploads                         | backup-files         |
| UPLOAD_ENDPOINT_URL   | URL for uploads (S3-compatible)                 |                      |
| AWS_ACCESS_KEY_ID     | AWS credentials                                 | changeme             |
| AWS_SECRET_ACCESS_KEY | AWS credentials                                 | changeme             |
| AWS_DEFAULT_REGION    | AWS region                                      | eu-west-1            |
| AWS_OUTPUT            | AWS output format                               | json                 |
| PUSHGATEWAY_HOST      | Pushgateway hostname                            | pushgateway:9091     |
| PUSHGATEWAY_JOB       | Pushgateway job name            | ${POSTGRES_HOSTNAME} |
| PUSHGATEWAY_JOB       | Pushgateway job name                            | backup-files         |
| PUSHGATEWAY_LABEL     | Pushgateway label value                         | ${PUSHGATEWAY_JOB}   |

## Metrics

|                                Name                                    |                        Description                       |
|----------------------------------------------------------|----------------------------------------------------------|
| backup_db{label="redmic"}                                | Outcome of the backup database job (0=failed, 1=success) |
| backup_duration_seconds{label="redmic",stage="dump"}     | Duration of create dump execution in seconds             |
| backup_duration_seconds{label="redmic",stage="compress"} | Duration of compress dump execution in seconds           |
| backup_duration_seconds{label="redmic",stage="upload"}   | Duration of upload backup to S3 execution in seconds     |
| backup_size_bytes{label="redmic"}                        | Duration of the script execution in seconds              |
| backup_created_date_seconds{label="redmic"}              | Created date in seconds                                  |
|------------------------------------------------------------------------|----------------------------------------------------------|
| backup_duration_seconds{label="${PUSHGATEWAY_LABEL}",stage="dump"}     | Duration of create dump execution in seconds             |
| backup_duration_seconds{label="${PUSHGATEWAY_LABEL}",stage="compress"} | Duration of compress dump execution in seconds           |
| backup_duration_seconds{label="${PUSHGATEWAY_LABEL}",stage="upload"}   | Duration of upload backup to S3 execution in seconds     |
| backup_size_bytes{label="${PUSHGATEWAY_LABEL}"}                        | Duration of the script execution in seconds              |
| backup_created_date_seconds{label="${PUSHGATEWAY_LABEL}"}              | Created date in seconds                                  |
+4 −8
Original line number Diff line number Diff line
ALPINE_IMAGE_TAG=3.13
CURL_VERSION=7.74.0-r1
POSTGRESQL_CLIENT_VERSION=13.2-r0
BASH_VERSION=5.1.0-r0
GLIBC_VERSION=2.33-r0
AWS_CLI_VERSION=2.0.30
BACKUP_PATH=/backup

POSTGRES_HOSTNAME=changeme
POSTGRES_PORT=5432
POSTGRES_USER=postgres
POSTGRES_PASSWORD=changeme
POSTGRES_DUMP_PATH=/tmp/backup
POSTGRES_PASS_FILE=/root/.pgpass
WORK_PATH=/tmp/backup

AWS_DEFAULT_REGION=eu-west-1
AWS_ACCESS_KEY_ID=changeme
AWS_SECRET_ACCESS_KEY=changeme
BUCKET_BACKUP_DB=backup-db
UPLOAD_BUCKET=backup-files
AWS_OUTPUT=json

PUSHGATEWAY_HOST=pushgateway:9091
PUSHGATEWAY_JOB=backup-files
Loading