diff --git a/backups.yml b/backups.yml new file mode 100644 index 0000000..21ba6b8 --- /dev/null +++ b/backups.yml @@ -0,0 +1,4 @@ +- hosts: webservers + roles: + - name: backups + postgres_password: "{{ postgresql_users.postgres }}" diff --git a/roles/backups/meta/argument_specs.yml b/roles/backups/meta/argument_specs.yml new file mode 100644 index 0000000..68aa14c --- /dev/null +++ b/roles/backups/meta/argument_specs.yml @@ -0,0 +1,6 @@ +argument_specs: + main: + options: + postgres_password: + type: str + required: true diff --git a/roles/backups/tasks/main.yml b/roles/backups/tasks/main.yml new file mode 100644 index 0000000..3611c47 --- /dev/null +++ b/roles/backups/tasks/main.yml @@ -0,0 +1,26 @@ +- name: Copy pgpass file + become: true + ansible.builtin.template: + src: pgpass.j2 + dest: /root/.pgpass + mode: "0600" + owner: root +- name: Create postgresql backups volume + become: true + community.docker.docker_volume: + name: postgresql-backups +- name: Run postgresql backuper + become: true + community.docker.docker_container: + name: postgresql-backuper-1 + image: git.comfycamp.space/lumin/postgresql-backuper:v0.0.3 + volumes: + - postgresql-backups:/backups + - /root/.pgpass:/root/.pgpass:ro + env: + CUSTOM_ARGS: "-U postgres -h postgresql --no-password" + BACKUPS_DIR: /backups + BACKUP_INTERVAL: 24h + networks: + - name: postgresql + restart_policy: unless-stopped diff --git a/roles/backups/templates/pgpass.j2 b/roles/backups/templates/pgpass.j2 new file mode 100644 index 0000000..6354b5d --- /dev/null +++ b/roles/backups/templates/pgpass.j2 @@ -0,0 +1 @@ +postgresql:5432:*:postgres:{{ postgres_password }}