From 84197fb33bba5d128391f344545209c4c3c3ae71 Mon Sep 17 00:00:00 2001 From: Mike Reeves Date: Tue, 21 Apr 2026 09:42:41 -0400 Subject: [PATCH] Move postgres backup script and cron to the postgres states MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The so-postgres-backup script and its cron were living under salt/backup/config_backup.sls, which meant the backup script and cron were deployed independently of whether postgres was enabled/disabled. - Relocate salt/backup/tools/sbin/so-postgres-backup to salt/postgres/tools/sbin/so-postgres-backup so the existing postgres_sbin file.recurse in postgres/config.sls picks it up with everything else — no separate file.managed needed. - Remove postgres_backup_script and so_postgres_backup from salt/backup/config_backup.sls. - Add cron.present for so_postgres_backup to salt/postgres/enabled.sls and the matching cron.absent to salt/postgres/disabled.sls so the cron follows the container's lifecycle. --- salt/backup/config_backup.sls | 19 ------------------- salt/postgres/disabled.sls | 6 ++++++ salt/postgres/enabled.sls | 11 +++++++++++ .../tools/sbin/so-postgres-backup | 0 4 files changed, 17 insertions(+), 19 deletions(-) rename salt/{backup => postgres}/tools/sbin/so-postgres-backup (100%) diff --git a/salt/backup/config_backup.sls b/salt/backup/config_backup.sls index c8e342463..a4297444b 100644 --- a/salt/backup/config_backup.sls +++ b/salt/backup/config_backup.sls @@ -33,22 +33,3 @@ so_config_backup: - month: '*' - dayweek: '*' -postgres_backup_script: - file.managed: - - name: /usr/sbin/so-postgres-backup - - user: root - - group: root - - mode: 755 - - source: salt://backup/tools/sbin/so-postgres-backup - -# Add postgres database backup -so_postgres_backup: - cron.present: - - name: /usr/sbin/so-postgres-backup > /dev/null 2>&1 - - identifier: so_postgres_backup - - user: root - - minute: '5' - - hour: '0' - - daymonth: '*' - - month: '*' - - dayweek: '*' diff --git a/salt/postgres/disabled.sls b/salt/postgres/disabled.sls index 56dc451b7..4b5b62328 100644 --- a/salt/postgres/disabled.sls +++ b/salt/postgres/disabled.sls @@ -18,6 +18,12 @@ so-postgres_so-status.disabled: - name: /opt/so/conf/so-status/so-status.conf - regex: ^so-postgres$ +so_postgres_backup: + cron.absent: + - name: /usr/sbin/so-postgres-backup > /dev/null 2>&1 + - identifier: so_postgres_backup + - user: root + {% else %} {{sls}}_state_not_allowed: diff --git a/salt/postgres/enabled.sls b/salt/postgres/enabled.sls index 4c5838466..b3abb621e 100644 --- a/salt/postgres/enabled.sls +++ b/salt/postgres/enabled.sls @@ -89,6 +89,17 @@ delete_so-postgres_so-status.disabled: - name: /opt/so/conf/so-status/so-status.conf - regex: ^so-postgres$ +so_postgres_backup: + cron.present: + - name: /usr/sbin/so-postgres-backup > /dev/null 2>&1 + - identifier: so_postgres_backup + - user: root + - minute: '5' + - hour: '0' + - daymonth: '*' + - month: '*' + - dayweek: '*' + {% else %} {{sls}}_state_not_allowed: diff --git a/salt/backup/tools/sbin/so-postgres-backup b/salt/postgres/tools/sbin/so-postgres-backup similarity index 100% rename from salt/backup/tools/sbin/so-postgres-backup rename to salt/postgres/tools/sbin/so-postgres-backup