aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--roles/postgres_backup/defaults/main.yml5
-rw-r--r--roles/postgres_backup/tasks/main.yml37
-rw-r--r--roles/postgres_backup/vars/main.yml2
3 files changed, 15 insertions, 29 deletions
diff --git a/roles/postgres_backup/defaults/main.yml b/roles/postgres_backup/defaults/main.yml
new file mode 100644
index 0000000..ab976d9
--- /dev/null
+++ b/roles/postgres_backup/defaults/main.yml
@@ -0,0 +1,5 @@
+---
+pgsql_backup:
+ rpeo_dir: /var/backup/borg_postgres/
+ repo_key: 'CHANGEME'
+
diff --git a/roles/postgres_backup/tasks/main.yml b/roles/postgres_backup/tasks/main.yml
index 62dfae3..57f32b4 100644
--- a/roles/postgres_backup/tasks/main.yml
+++ b/roles/postgres_backup/tasks/main.yml
@@ -1,25 +1,15 @@
---
-- name: Check for BORG
- command: which borg
- register: borg_check
- ignore_errors: yes
-
-# Kinda hacky but saves time
- name: Install BORG
apt:
name:
- borgbackup
become: yes
- when: not borg_check.rc == 0
- name: Create BORG repo
file:
path: '{{ borg_repo_dir }}'
state: directory
- owner: server
- group: server
mode: 'u=rwx,g=,o='
- # recurse: yes
become: yes
- name: Initialize BORG repo
@@ -27,8 +17,9 @@
cmd: borg init --encryption=repokey
creates: '{{ borg_repo_dir }}/config'
environment:
- BORG_REPO: '{{ borg_repo_dir }}'
- BORG_PASSPHRASE: '{{ vault_db_backup_key[ env ] }}'
+ BORG_REPO: '{{ pgsql_backup.repo_dir }}'
+ BORG_PASSPHRASE: '{{ pgsql_backup.repo_key }}'
+ become: yes
- name: Create tempdir
file:
@@ -45,26 +36,17 @@
state: dump
target: '/tmp/postgres/{{ item }}.sql'
login_unix_socket: '/var/run/postgresql/'
- loop: '{{ pg_dbs }}'
+ loop: '{{ pgsql_dbs }}'
become_user: postgres
become: yes
-- name: Create tempdir
- file:
- path: /tmp/postgres
- state: directory
- owner: server
- group: server
- recurse: yes
- mode: 'u=rwx,g=,o='
- become: yes
-
- name: Create BORG backup
command: 'borg create --compression lz4 --verbose ::{hostname}-{now} /tmp/postgres'
environment:
- BORG_REPO: '{{ borg_repo_dir }}'
- BORG_PASSPHRASE: '{{ vault_db_backup_key[ env ] }}'
+ BORG_REPO: '{{ pgsql_backup.repo_dir }}'
+ BORG_PASSPHRASE: '{{ pgsql_backup.repo_key }}'
register: borg_output
+ become: yes
- name: Borg Output
debug:
@@ -79,9 +61,10 @@
- name: Prune BORG backup
command: 'borg prune --list --keep-last 3 --keep-daily 7 --keep-weekly 4 --keep-monthly 6'
environment:
- BORG_REPO: '{{ borg_repo_dir }}'
- BORG_PASSPHRASE: '{{ vault_pg_db_backup_key[ env ] }}'
+ BORG_REPO: '{{ pgsql_backup.repo_dir }}'
+ BORG_PASSPHRASE: '{{ pgsql_backup.repo_key }}'
register: borg_prune
+ become: yes
- name: Prune Output
debug:
diff --git a/roles/postgres_backup/vars/main.yml b/roles/postgres_backup/vars/main.yml
deleted file mode 100644
index 0a33854..0000000
--- a/roles/postgres_backup/vars/main.yml
+++ /dev/null
@@ -1,2 +0,0 @@
----
-borg_repo_dir: /var/backup/borg_postgres/