From e53aab5fbea51c2ce5ad061da93df67b4d3432e1 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Fri, 17 Mar 2023 16:40:08 +0200 Subject: [PATCH] Add Postgres Backup --- docs/services/postgres-backup.md | 39 +++++++++++++++++++++++++++ docs/services/postgres.md | 9 +++++-- docs/supported-services.md | 3 ++- group_vars/mash_servers | 45 ++++++++++++++++++++++++++++++++ requirements.yml | 3 +++ setup.yml | 2 ++ 6 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 docs/services/postgres-backup.md diff --git a/docs/services/postgres-backup.md b/docs/services/postgres-backup.md new file mode 100644 index 0000000..ba8f478 --- /dev/null +++ b/docs/services/postgres-backup.md @@ -0,0 +1,39 @@ +# Postgres Backup + +This playbook can configure [docker-postgres-backup-local](https://github.com/prodrigestivill/docker-postgres-backup-local) for you via the [com.devture.ansible.role.postgres_backup](https://github.com/devture/com.devture.ansible.role.postgres_backup) Ansible role. + +For a more complete backup solution (one that includes not only Postgres, but also other configuration/data files), you may wish to look into **borg backup** (not yet supported by this playbook). + + +## Configuration + +To enable this service, add the following configuration to your `vars.yml` file and re-run the [installation](../installing.md) process: + +```yaml +######################################################################## +# # +# devture-postgres-backup # +# # +######################################################################## + +devture_postgres_backup_enabled: true + +######################################################################## +# # +# /devture-postgres-backup # +# # +######################################################################## +``` + +Refer to the table below for additional configuration variables and their default values. + + +| Name | Default value | Description | +| :-------------------------------- | :--------------------------- | :--------------------------------------------------------------- | +|`devture_postgres_backup_enabled`|`false`|Set to true to use [docker-postgres-backup-local](https://github.com/prodrigestivill/docker-postgres-backup-local) to create automatic database backups| +|`devture_postgres_backup_schedule`| `'@daily'` |Cron-schedule specifying the interval between postgres backups.| +|`devture_postgres_backup_keep_days`|`7`|Number of daily backups to keep| +|`devture_postgres_backup_keep_weeks`|`4`|Number of weekly backups to keep| +|`devture_postgres_backup_keep_months`|`12`|Number of monthly backups to keep| +|`devture_postgres_backup_base_path` | `"{{ mash_playbook_base_path }}/postgres-backup"` | Base path for postgres-backup. Also see `devture_postgres_backup_data_path` | +|`devture_postgres_backup_data_path` | `"{{ devture_postgres_backup_base_path }}/data"` | Storage path for postgres-backup database backups | diff --git a/docs/services/postgres.md b/docs/services/postgres.md index e11932e..d94e74f 100644 --- a/docs/services/postgres.md +++ b/docs/services/postgres.md @@ -110,9 +110,9 @@ just run-tags run-postgres-vacuum,start ### Backing up PostgreSQL -To automatically make Postgres database backups on a fixed schedule, see [Setting up postgres backup](configuring-playbook-postgres-backup.md). +To automatically make Postgres database backups on a fixed schedule, consider enabling the [Postgres Backup](postgres-backup.md) service. -To make a one off back up of the current PostgreSQL database, make sure it's running and then execute a command like this on the server: +To make a one-off back up of the current PostgreSQL database, make sure it's running and then execute a command like this on the server: ```bash /usr/bin/docker exec \ @@ -216,3 +216,8 @@ devture_postgres_process_extra_arguments: [ "-c max_parallel_maintenance_workers=3", ] ``` + + +## Recommended other services + +You may also wish to look into [Postgres Backup](postgres-backup.md) for backing up your Postgres database. diff --git a/docs/supported-services.md b/docs/supported-services.md index e04fc35..f07bae8 100644 --- a/docs/supported-services.md +++ b/docs/supported-services.md @@ -8,7 +8,8 @@ | [Miniflux](https://miniflux.app/) | Minimalist and opinionated feed reader. | [Link](services/miniflux.md) | | [Nextcloud](https://nextcloud.com/) | The most popular self-hosted collaboration solution for tens of millions of users at thousands of organizations across the globe. | [Link](services/nextcloud.md) | | [PeerTube](https://joinpeertube.org/) | A tool for sharing online videos | [Link](services/peertube.md) | -| [PostgreSQL](https://www.postgresql.org) | A powerful, open source object-relational database system | [Link](services/postgres.md) | +| [Postgres](https://www.postgresql.org) | A powerful, open source object-relational database system | [Link](services/postgres.md) | +| [Postgres Backup](https://github.com/prodrigestivill/docker-postgres-backup-local) | A solution for backing up PostgresSQL to local filesystem with periodic backups. | [Link](services/postgres-backup.md) | | [Radicale](https://miniflux.app/) | A Free and Open-Source CalDAV and CardDAV Server (solution for hosting contacts and calendars) | [Link](services/radicale.md) | | [Redis](https://redis.io/) | An in-memory data store used by millions of developers as a database, cache, streaming engine, and message broker. | [Link](services/redis.md) | | [Traefik](https://doc.traefik.io/traefik/) | A container-aware reverse-proxy server | [Link](services/traefik.md) | diff --git a/group_vars/mash_servers b/group_vars/mash_servers index ae983f4..e533118 100644 --- a/group_vars/mash_servers +++ b/group_vars/mash_servers @@ -12,6 +12,8 @@ devture_systemd_service_manager_services_list_auto: | + ([{'name': (devture_postgres_identifier + '.service'), 'priority': 500, 'groups': ['mash', 'postgres']}] if devture_postgres_enabled else []) + + ([{'name': (devture_postgres_backup_identifier + '.service'), 'priority': 5000, 'groups': ['mash', 'backup', 'postgres-backup']}] if devture_postgres_backup_enabled else []) + + ([{'name': (devture_container_socket_proxy_identifier + '.service'), 'priority': 2900, 'groups': ['mash', 'reverse-proxies', 'container-socket-proxy']}] if devture_container_socket_proxy_enabled else []) + ([{'name': (devture_traefik_identifier + '.service'), 'priority': 3000, 'groups': ['mash', 'traefik', 'reverse-proxies']}] if devture_traefik_enabled else []) @@ -116,6 +118,49 @@ devture_postgres_managed_databases_auto: | +######################################################################## +# # +# com.devture.ansible.role.postgres_backup # +# # +######################################################################## + +devture_postgres_backup_enabled: false + +devture_postgres_backup_identifier: "{{ mash_playbook_service_identifier_prefix }}postgres-backup" + +devture_postgres_backup_architecture: "{{ mash_playbook_architecture }}" + +devture_postgres_backup_base_path: "{{ mash_playbook_base_path }}/postgres-backup" + +devture_postgres_backup_systemd_required_services_list: | + {{ + (['docker.service']) + + + ([(devture_postgres_identifier + '.service')] if devture_postgres_enabled else []) + }} + +devture_postgres_backup_container_network: "{{ devture_postgres_container_network }}" + +devture_postgres_backup_uid: "{{ mash_playbook_uid }}" +devture_postgres_backup_gid: "{{ mash_playbook_gid }}" + +devture_postgres_backup_connection_hostname: "{{ devture_postgres_connection_hostname if devture_postgres_enabled else '' }}" +devture_postgres_backup_connection_port: "{{ devture_postgres_connection_port if devture_postgres_enabled else 5432 }}" +devture_postgres_backup_connection_username: "{{ devture_postgres_connection_username if devture_postgres_enabled else '' }}" +devture_postgres_backup_connection_password: "{{ devture_postgres_connection_password if devture_postgres_enabled else '' }}" + +devture_postgres_backup_postgres_data_path: "{{ devture_postgres_data_path if devture_postgres_enabled else '' }}" + +devture_postgres_backup_databases: "{{ devture_postgres_managed_databases | map(attribute='name') if devture_postgres_enabled else [] }}" + +######################################################################## +# # +# /com.devture.ansible.role.postgres_backup # +# # +######################################################################## + + + ######################################################################## # # # com.devture.ansible.role.playbook_state_preserver # diff --git a/requirements.yml b/requirements.yml index 1904657..4e25d13 100644 --- a/requirements.yml +++ b/requirements.yml @@ -21,6 +21,9 @@ - src: git+https://github.com/devture/com.devture.ansible.role.postgres.git version: 38764398bf82b06a1736c3bfedc71dfd229e4b52 +- src: git+https://github.com/devture/com.devture.ansible.role.postgres_backup.git + version: 8e9ec48a09284c84704d7a2dce17da35f181574d + - src: git+https://github.com/devture/com.devture.ansible.role.container_socket_proxy.git version: v0.1.1-1 diff --git a/setup.yml b/setup.yml index d8fca83..8e00029 100644 --- a/setup.yml +++ b/setup.yml @@ -40,6 +40,8 @@ # This role exposes various tags (setup-postgres, setup-all, upgrade-postgres, import-postgres, etc.), so we don't tag it here. - role: galaxy/com.devture.ansible.role.postgres + - role: galaxy/com.devture.ansible.role.postgres_backup + - role: galaxy/com.devture.ansible.role.container_socket_proxy - role: galaxy/com.devture.ansible.role.traefik