first commit

This commit is contained in:
ace
2024-05-15 15:52:33 +03:00
commit 9a5d1bddec
24 changed files with 522 additions and 0 deletions

View File

@ -0,0 +1,11 @@
[Unit]
Description=Permanent backup PostgreSQL
[Service]
Type=oneshot
ExecStart=/bin/bash {{ wal_g_pg_home_dir }}/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,13 @@
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\"" ] || [ "${role}" == "" ]; then
{% if wal_g_http_proxy is defined %}http_proxy={{ wal_g_http_proxy }} {% else %}{% endif %}{% if wal_g_https_proxy is defined %}https_proxy={{ wal_g_https_proxy }} {% elif wal_g_http_proxy is defined %}https_proxy={{ wal_g_http_proxy }}{% else %}{% endif %} {{ wal_g_pg_binary_name }} --config {{ wal_g_pg_home_dir }}/{{ wal_g_config_name }} backup-push {{ wal_g_pg_data_dir }} --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 {{ wal_g_pg_home_dir }}/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\"" ] || [ "${role}" == "" ]; then
{% if wal_g_http_proxy is defined %}http_proxy={{ wal_g_http_proxy }} {% else %}{% endif %}{% if wal_g_https_proxy is defined %}https_proxy={{ wal_g_https_proxy }} {% elif wal_g_http_proxy is defined %}https_proxy={{ wal_g_http_proxy }}{% else %}{% endif %} {{ wal_g_pg_binary_name }} --config {{ wal_g_pg_home_dir }}/{{ wal_g_config_name }} delete 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 {{ wal_g_pg_home_dir }}/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\"" ] || [ "${role}" == "" ]; then
{% if wal_g_http_proxy is defined %}http_proxy={{ wal_g_http_proxy }} {% else %}{% endif %}{% if wal_g_https_proxy is defined %}https_proxy={{ wal_g_https_proxy }} {% elif wal_g_http_proxy is defined %}https_proxy={{ wal_g_http_proxy }}{% else %}{% endif %} {{ wal_g_pg_binary_name }} --config {{ wal_g_pg_home_dir }}/{{ wal_g_config_name }} backup-push {{ wal_g_pg_data_dir }} --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 %}
}