Skip to content

Commit

Permalink
Merge pull request #1692 from smilerz/master
Browse files Browse the repository at this point in the history
Add pgAdmin and pgBackup
  • Loading branch information
nemchik authored Nov 22, 2023
2 parents c41b143 + fc918d1 commit 058ed57
Show file tree
Hide file tree
Showing 17 changed files with 184 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compose/.apps/pgadmin/pgadmin.aarch64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
services:
pgadmin:
image: dpage/pgadmin4:${PGADMIN_TAG}
3 changes: 3 additions & 0 deletions compose/.apps/pgadmin/pgadmin.hostname.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
services:
pgadmin:
hostname: ${DOCKERHOSTNAME}
14 changes: 14 additions & 0 deletions compose/.apps/pgadmin/pgadmin.labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
services:
pgadmin:
labels:
com.dockstarter.appinfo.deprecated: "false"
com.dockstarter.appinfo.description: pgAdmin 4 is a web based administration tool for the PostgreSQL database.
com.dockstarter.appinfo.nicename: pgAdmin
com.dockstarter.appvars.pgadmin_disable_postfix: "True"
com.dockstarter.appvars.pgadmin_enabled: "false"
com.dockstarter.appvars.pgadmin_network_mode: ""
com.dockstarter.appvars.pgadmin_default_email: ""
com.dockstarter.appvars.pgadmin_default_password: ""
com.dockstarter.appvars.pgadmin_port_80: "5050"
com.dockstarter.appvars.pgadmin_restart: unless-stopped
com.dockstarter.appvars.pgadmin_tag: "latest"
3 changes: 3 additions & 0 deletions compose/.apps/pgadmin/pgadmin.netmode.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
services:
pgadmin:
network_mode: ${PGADMIN_NETWORK_MODE}
4 changes: 4 additions & 0 deletions compose/.apps/pgadmin/pgadmin.ports.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
services:
pgadmin:
ports:
- ${PGADMIN_PORT_80}:80
3 changes: 3 additions & 0 deletions compose/.apps/pgadmin/pgadmin.x86_64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
services:
pgadmin:
image: dpage/pgadmin4:${PGADMIN_TAG}
18 changes: 18 additions & 0 deletions compose/.apps/pgadmin/pgadmin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
services:
pgadmin:
container_name: pgadmin
environment:
- PGADMIN_DEFAULT_EMAIL=${PGADMIN_DEFAULT_EMAIL}
- PGADMIN_DEFAULT_PASSWORD=${PGADMIN_DEFAULT_PASSWORD}
- PGADMIN_DISABLE_POSTFIX=${PGADMIN_DISABLE_POSTFIX}
- TZ=${TZ}
logging:
driver: json-file
options:
max-file: ${DOCKERLOGGING_MAXFILE}
max-size: ${DOCKERLOGGING_MAXSIZE}
restart: ${PGADMIN_RESTART}
volumes:
- /etc/localtime:/etc/localtime:ro
- ${DOCKERCONFDIR}/pgadmin:/var/lib/pgadmin
- ${DOCKERSTORAGEDIR}:/storage
3 changes: 3 additions & 0 deletions compose/.apps/pgbackup/pgbackup.aarch64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
services:
pgbackup:
image: prodrigestivill/postgres-backup-local:${PGBACKUP_TAG}
3 changes: 3 additions & 0 deletions compose/.apps/pgbackup/pgbackup.hostname.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
services:
pgbackup:
hostname: ${DOCKERHOSTNAME}
18 changes: 18 additions & 0 deletions compose/.apps/pgbackup/pgbackup.labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
services:
pgbackup:
labels:
com.dockstarter.appinfo.deprecated: "false"
com.dockstarter.appinfo.description: Backup PostgresSQL to the local filesystem with periodic rotating backups.
com.dockstarter.appinfo.nicename: pgBackup
com.dockstarter.appvars.pgbackup_enabled: "false"
com.dockstarter.appvars.pgbackup_keep_days: "8"
com.dockstarter.appvars.pgbackup_keep_months: "12"
com.dockstarter.appvars.pgbackup_keep_weeks: "4"
com.dockstarter.appvars.pgbackup_network_mode: ""
com.dockstarter.appvars.pgbackup_postgres_db: ""
com.dockstarter.appvars.pgbackup_postgres_host: "postgres"
com.dockstarter.appvars.pgbackup_postgres_password: ""
com.dockstarter.appvars.pgbackup_postgres_user: ""
com.dockstarter.appvars.pgbackup_restart: unless-stopped
com.dockstarter.appvars.pgbackup_schedule: "@daily"
com.dockstarter.appvars.pgbackup_tag: "16"
3 changes: 3 additions & 0 deletions compose/.apps/pgbackup/pgbackup.netmode.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
services:
pgbackup:
network_mode: ${PGBACKUP_NETWORK_MODE}
3 changes: 3 additions & 0 deletions compose/.apps/pgbackup/pgbackup.x86_64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
services:
pgbackup:
image: prodrigestivill/postgres-backup-local:${PGBACKUP_TAG}
24 changes: 24 additions & 0 deletions compose/.apps/pgbackup/pgbackup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
services:
pgbackup:
container_name: pgbackup
environment:
- POSTGRES_HOST=${PGBACKUP_POSTGRES_HOST}
- POSTGRES_DB=${PGBACKUP_POSTGRES_DB}
- POSTGRES_USER=${PGBACKUP_POSTGRES_USER}
- POSTGRES_PASSWORD=${PGBACKUP_POSTGRES_PASSWORD}
- POSTGRES_EXTRA_OPTS=-Z6 --schema=public --blobs
- SCHEDULE=${PGBACKUP_SCHEDULE}
- BACKUP_KEEP_DAYS=${PGBACKUP_KEEP_DAYS}
- BACKUP_KEEP_WEEKS=${PGBACKUP_KEEP_WEEKS}
- BACKUP_KEEP_MONTHS=${PGBACKUP_KEEP_MONTHS}
- TZ=${TZ}
logging:
driver: json-file
options:
max-file: ${DOCKERLOGGING_MAXFILE}
max-size: ${DOCKERLOGGING_MAXSIZE}
restart: ${PGBACKUP_RESTART}
volumes:
- /etc/localtime:/etc/localtime:ro
- ${DOCKERSTORAGEDIR}/backups/postgres:/backups
- ${DOCKERSTORAGEDIR}:/storage
17 changes: 17 additions & 0 deletions docs/apps/pgadmin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# pgAdmin

[![Docker Pulls](https://img.shields.io/docker/pulls/dpage/pgadmin4?style=flat-square&color=607D8B&label=docker%20pulls&logo=docker)](https://hub.docker.com/r/dpage/pgadmin4)
[![GitHub Stars](https://img.shields.io/github/stars/pgadmin-org/pgadmin4?style=flat-square&color=607D8B&label=github%20stars&logo=github)](https://github.com/pgadmin-org/pgadmin4)
[![Compose Templates](https://img.shields.io/static/v1?style=flat-square&color=607D8B&label=compose&message=templates)](https://github.com/GhostWriters/DockSTARTer/tree/master/compose/.apps/pgadmin)

## Description

[pgAdmin](https://www.pgadmin.org/): pgAdmin is the most popular and feature rich Open Source administration and development platform for PostgreSQL, the most advanced Open Source database in the world.

## Install/Setup

An email address (login) and password are the only required inputs for a fullly functional instance of pgAdmin.

Full variable documentation is available in the pgadmin [documentation](https://www.pgadmin.org/docs/pgadmin4/latest/container_deployment.html#environment-variables).

Any variable name from [config.py](https://www.pgadmin.org/docs/pgadmin4/latest/config_py.html#config-py) can be defined in the format of `PGADMIN_CONFIG_*` in docker-compose.override.yml
41 changes: 41 additions & 0 deletions docs/apps/pgbackup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# pgBackup

[![Docker Pulls](https://img.shields.io/docker/pulls/prodrigestivill/postgres-backup-local?style=flat-square&color=607D8B&label=docker%20pulls&logo=docker)](https://hub.docker.com/r/prodrigestivill/postgres-backup-local)
[![GitHub Stars](https://img.shields.io/github/stars/prodrigestivill/docker-postgres-backup-local?style=flat-square&color=607D8B&label=github%20stars&logo=github)](https://github.com/prodrigestivill/docker-postgres-backup-local)
[![Compose Templates](https://img.shields.io/static/v1?style=flat-square&color=607D8B&label=compose&message=templates)](https://github.com/GhostWriters/DockSTARTer/tree/master/compose/.apps/pgbackup)

## Description

[pgBackup](https://hub.docker.com/r/prodrigestivill/postgres-backup-local): Backup PostgresSQL to the local filesystem with periodic rotating backups

## Install/Setup

Set your postgres host, username and password in the .env file along with a comma seperated list of databases you want to backup.

By default, backups run daily. Change PGBACKUP_SCHEDULE to any valid [cron schedule](http://godoc.org/github.com/robfig/cron#hdr-Predefined_schedules) to modify the default.

### Recommended docker-compose overrides

For extra security, it is recommended to limit permissions on the backup folder to a priviledged user. Modify docker-compose.override.yml as below.

If you are using postgres docker container, add a dependency to the container

```yaml
pgbackup:
user: postgres:postgres
depends_on:
- postgres
```
## Manually trigger a backup
`docker exec -it pgbackup ./backup.sh`

## Restore from latest backup

If the database already exists, drop it.
Create a database <db_name>

```bash
docker exec -it <postgres_container> /bin/sh -c "zcat /storage/backups/postgres/last/<db_name>-latest.sql.gz | psql --username=<username> --dbname=<db_name> -W"
```
22 changes: 22 additions & 0 deletions docs/apps/postgres.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,25 @@ PostgreSQL is a powerful, open source object-relational database system with ove
There is a wealth of information to be found describing how to [install](https://www.postgresql.org/download/) and [use](https://www.postgresql.org/docs/) PostgreSQL through the [official documentation](https://www.postgresql.org/docs/). The [open source community](https://www.postgresql.org/community/) provides many helpful places to become familiar with PostgreSQL, discover how it works.

We **heavily** recommend that if you spin up a container that requires a database you create a user for that container. You should **NEVER** use the root account for anything other than database management.

Strongly consider also installing [pgAdmin](https://github.com/GhostWriters/DockSTARTer/tree/master/compose/.apps/pgadmin) for adminsitration and [pgBackup](https://github.com/GhostWriters/DockSTARTer/tree/master/compose/.apps/pgbackup) for periodic rotating backups.

## Common Activities

### Create user

```sql
CREATE USER newuser WITH PASSWORD 'password123';
```

### Make user a superuser

```sql
CREATE USER newadmin WITH PASSWORD 'password123';
ALTER USER newadmin WITH SUPERUSER;
```

### Create a database and owner to the new user

CREATE DATABASE newdatabase;
ALTER DATABASE newdatabase OWNER TO newuser;
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ nav:
- apps/openvpnas.md
- apps/organizr.md
- apps/ouroboros.md
- apps/pgadmin.md
- apps/pgbackup.md
- apps/photostructure.md
- apps/phpmyadmin.md
- apps/picard.md
Expand Down

0 comments on commit 058ed57

Please sign in to comment.