first commit

This commit is contained in:
ace
2023-02-08 02:18:19 +03:00
commit 922582e57e
22 changed files with 397 additions and 0 deletions

View File

@ -0,0 +1,11 @@
[Unit]
Description=Permanent backup PostgreSQL
[Service]
Type=oneshot
ExecStart=/bin/bash /var/lib/pgsql/backup-permanent.sh
User={{ wal_g_pg_backup_owner }}
Group={{ wal_g_pg_backup_group }}
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,12 @@
exec 200>/tmp/backup.lock
flock -x 200
role=$(curl -k -s http://127.0.0.1:8008 || curl -k -s https://127.0.0.1:8008 | jq '.role')
if [ "${role}" == "\"master\"" ] ; then
{{ wal_g_pg_binary_name }} backup-push {{ wal_g_pg_home_dir }}/{{ wal_g_postgresql_major_version }}/data --full --permanent 2>&1 | tee -a /var/log/postgresql/backup-permanent.log
else
echo ""
fi
exec 200>&-

View File

@ -0,0 +1,9 @@
[Unit]
Description=Run PostgreSQL backup permanent
[Timer]
Unit=backup-permanent.service
OnCalendar={{ wal_g_backup_permanent_schedule }}
[Install]
WantedBy=timers.target

View File

@ -0,0 +1,12 @@
[Unit]
Description=Backups retention for PostgreSQL
Wants=backup-retention.timer
[Service]
Type=oneshot
ExecStart=/bin/bash /var/lib/pgsql/backup-retention.sh
User={{ wal_g_pg_backup_owner }}
Group={{ wal_g_pg_backup_group }}
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,12 @@
exec 200>/tmp/backup.lock
flock -x 200
role=$(curl -k -s http://127.0.0.1:8008 || curl -k -s https://127.0.0.1:8008 | jq '.role')
if [ "${role}" == "\"master\"" ] ; then
{{ wal_g_pg_binary_name }} retain {{ wal_g_backup_retention_number }} --confirm --use-sentinel-time 2>&1 | tee -a /var/log/postgresql/backup-retention.log
else
echo ""
fi
exec 200>&-

View File

@ -0,0 +1,9 @@
[Unit]
Description=Run PostgreSQL backup retention
[Timer]
Unit=backup-retention.service
OnCalendar={{ wal_g_backup_retention_schedule }}
[Install]
WantedBy=timers.target

View File

@ -0,0 +1,12 @@
[Unit]
Description=Backup PostgreSQL
Wants=backup.timer
[Service]
Type=oneshot
ExecStart=/bin/bash /var/lib/pgsql/backup.sh
User={{ wal_g_pg_backup_owner }}
Group={{ wal_g_pg_backup_group }}
[Install]
WantedBy=multi-user.target

12
templates/backup.sh.j2 Normal file
View File

@ -0,0 +1,12 @@
exec 200>/tmp/backup.lock
flock -x 200
role=$(curl -k -s http://127.0.0.1:8008 || curl -k -s https://127.0.0.1:8008 | jq '.role')
if [ "${role}" == "\"master\"" ] ; then
{{ wal_g_pg_binary_name }} backup-push {{ wal_g_pg_home_dir }}/{{ wal_g_postgresql_major_version }}/data --full 2>&1 | tee -a /var/log/postgresql/backup.log
else
echo ""
fi
exec 200>&-

View File

@ -0,0 +1,9 @@
[Unit]
Description=Run PostgreSQL backup
[Timer]
Unit=backup.service
OnCalendar={{ wal_g_backup_schedule }}
[Install]
WantedBy=timers.target

7
templates/walg.json.j2 Normal file
View File

@ -0,0 +1,7 @@
{
{% for wal_g in wal_g_json %}
"{{ wal_g.option }}": "{{ wal_g.value }}"{% if not loop.last %},
{% endif %}
{% endfor %}
}