diff --git a/compose/.apps/pgadmin/pgadmin.aarch64.yml b/compose/.apps/pgadmin/pgadmin.aarch64.yml new file mode 100644 index 0000000000..451bd9308e --- /dev/null +++ b/compose/.apps/pgadmin/pgadmin.aarch64.yml @@ -0,0 +1,3 @@ +services: + pgadmin: + image: dpage/pgadmin4:${PGADMIN_TAG} diff --git a/compose/.apps/pgadmin/pgadmin.hostname.yml b/compose/.apps/pgadmin/pgadmin.hostname.yml new file mode 100644 index 0000000000..fc7f3cb7d7 --- /dev/null +++ b/compose/.apps/pgadmin/pgadmin.hostname.yml @@ -0,0 +1,3 @@ +services: + pgadmin: + hostname: ${DOCKERHOSTNAME} diff --git a/compose/.apps/pgadmin/pgadmin.labels.yml b/compose/.apps/pgadmin/pgadmin.labels.yml new file mode 100644 index 0000000000..2fceef244d --- /dev/null +++ b/compose/.apps/pgadmin/pgadmin.labels.yml @@ -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" diff --git a/compose/.apps/pgadmin/pgadmin.netmode.yml b/compose/.apps/pgadmin/pgadmin.netmode.yml new file mode 100644 index 0000000000..75f1cd8fed --- /dev/null +++ b/compose/.apps/pgadmin/pgadmin.netmode.yml @@ -0,0 +1,3 @@ +services: + pgadmin: + network_mode: ${PGADMIN_NETWORK_MODE} diff --git a/compose/.apps/pgadmin/pgadmin.ports.yml b/compose/.apps/pgadmin/pgadmin.ports.yml new file mode 100644 index 0000000000..81e4781ca6 --- /dev/null +++ b/compose/.apps/pgadmin/pgadmin.ports.yml @@ -0,0 +1,4 @@ +services: + pgadmin: + ports: + - ${PGADMIN_PORT_80}:80 diff --git a/compose/.apps/pgadmin/pgadmin.x86_64.yml b/compose/.apps/pgadmin/pgadmin.x86_64.yml new file mode 100644 index 0000000000..451bd9308e --- /dev/null +++ b/compose/.apps/pgadmin/pgadmin.x86_64.yml @@ -0,0 +1,3 @@ +services: + pgadmin: + image: dpage/pgadmin4:${PGADMIN_TAG} diff --git a/compose/.apps/pgadmin/pgadmin.yml b/compose/.apps/pgadmin/pgadmin.yml new file mode 100644 index 0000000000..62ccd6c068 --- /dev/null +++ b/compose/.apps/pgadmin/pgadmin.yml @@ -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 diff --git a/compose/.apps/pgbackup/pgbackup.aarch64.yml b/compose/.apps/pgbackup/pgbackup.aarch64.yml new file mode 100644 index 0000000000..51f99b1fad --- /dev/null +++ b/compose/.apps/pgbackup/pgbackup.aarch64.yml @@ -0,0 +1,3 @@ +services: + pgbackup: + image: prodrigestivill/postgres-backup-local:${PGBACKUP_TAG} diff --git a/compose/.apps/pgbackup/pgbackup.hostname.yml b/compose/.apps/pgbackup/pgbackup.hostname.yml new file mode 100644 index 0000000000..39877444a5 --- /dev/null +++ b/compose/.apps/pgbackup/pgbackup.hostname.yml @@ -0,0 +1,3 @@ +services: + pgbackup: + hostname: ${DOCKERHOSTNAME} diff --git a/compose/.apps/pgbackup/pgbackup.labels.yml b/compose/.apps/pgbackup/pgbackup.labels.yml new file mode 100644 index 0000000000..9ddcd4e9f4 --- /dev/null +++ b/compose/.apps/pgbackup/pgbackup.labels.yml @@ -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" diff --git a/compose/.apps/pgbackup/pgbackup.netmode.yml b/compose/.apps/pgbackup/pgbackup.netmode.yml new file mode 100644 index 0000000000..9def0983fb --- /dev/null +++ b/compose/.apps/pgbackup/pgbackup.netmode.yml @@ -0,0 +1,3 @@ +services: + pgbackup: + network_mode: ${PGBACKUP_NETWORK_MODE} diff --git a/compose/.apps/pgbackup/pgbackup.x86_64.yml b/compose/.apps/pgbackup/pgbackup.x86_64.yml new file mode 100644 index 0000000000..51f99b1fad --- /dev/null +++ b/compose/.apps/pgbackup/pgbackup.x86_64.yml @@ -0,0 +1,3 @@ +services: + pgbackup: + image: prodrigestivill/postgres-backup-local:${PGBACKUP_TAG} diff --git a/compose/.apps/pgbackup/pgbackup.yml b/compose/.apps/pgbackup/pgbackup.yml new file mode 100644 index 0000000000..d7fa0c4825 --- /dev/null +++ b/compose/.apps/pgbackup/pgbackup.yml @@ -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 diff --git a/docs/apps/pgadmin.md b/docs/apps/pgadmin.md new file mode 100644 index 0000000000..7ac372bfbc --- /dev/null +++ b/docs/apps/pgadmin.md @@ -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 diff --git a/docs/apps/pgbackup.md b/docs/apps/pgbackup.md new file mode 100644 index 0000000000..e5a978e11d --- /dev/null +++ b/docs/apps/pgbackup.md @@ -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 + +```bash +docker exec -it /bin/sh -c "zcat /storage/backups/postgres/last/-latest.sql.gz | psql --username= --dbname= -W" +``` diff --git a/docs/apps/postgres.md b/docs/apps/postgres.md index 7ef8c6ea1c..bdb2e69b14 100644 --- a/docs/apps/postgres.md +++ b/docs/apps/postgres.md @@ -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; diff --git a/mkdocs.yml b/mkdocs.yml index f5bbbedce0..244384e7d7 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -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