diff --git a/bin/pg-backup b/bin/pg-backup new file mode 100755 index 0000000..f695825 --- /dev/null +++ b/bin/pg-backup @@ -0,0 +1,12 @@ +#!/bin/bash + +cd /tmp + +test -d /var/lib/pgsql || exit 0 + +pgrep postgres &>/dev/null || exit 10 + +tar -jcvf /var/backups/postgres/postgresql-config.tbz2 /var/lib/pgsql/*/data/*.conf + +/usr/sbin/runuser postgres -l -s /bin/bash -c '/usr/bin/pg_dumpall > /var/backups/postgres/pgdump.sql' + diff --git a/config.yml b/config.yml index 633166e..82f5608 100644 --- a/config.yml +++ b/config.yml @@ -56,13 +56,16 @@ ansible.builtin.selinux: state: disabled - - name: Create bin directory + - name: Create Directories file: - path: /opt/atclab/bin + path: '{{ item }}' state: directory mode: '0755' owner: root group: root + loop: + - /var/backups + - /opt/atclab/bin - name: Copy etc configs copy: diff --git a/inventory.ini b/inventory.ini index 9021719..b5ddb19 100644 --- a/inventory.ini +++ b/inventory.ini @@ -50,6 +50,9 @@ atc-mgt01.dell-atc.lan atc-nas.dell-atc.lan atc-db01.dell-atc.lan +[postgres] +atc-db01.dell-atc.lan + [nvidia] atc-gpu-bart.dell-atc.lan atc-gpu-mo1.dell-atc.lan diff --git a/postgres.yml b/postgres.yml new file mode 100644 index 0000000..74bc117 --- /dev/null +++ b/postgres.yml @@ -0,0 +1,23 @@ +--- +- name: Postgres Servers + hosts: postgres + pre_tasks: + - name: Postgres Repo + ansible.builtin.dnf: + name: 'https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm' + state: present + + tasks: + - name: Backup script + copy: + src: 'bin/pg-backup' + dest: '/usr/local/bin/pg-backup' + mode: '0755' + + - name: Setup Postgres backup cron job + ansible.builtin.cron: + name: "borgmatic" + minute: 30 + hour: 23 + job: /usr/local/bin/pg-backup +