Commit e79a64f2 authored by Marco Mariani's avatar Marco Mariani

abilian: postgres basebackup

parent f8a696aa
...@@ -28,8 +28,8 @@ superuser = postgres ...@@ -28,8 +28,8 @@ superuser = postgres
password = $${postgres-passwd:passwd} password = $${postgres-passwd:passwd}
port = 5432 port = 5432
dbname = db dbname = db
# pgdata_directory is created by initdb, and should not exist beforehand. # pgdata-directory is created by initdb, and should not exist beforehand. Mandatory parameter.
pgdata-directory = $${directories:var}/data pgdata-directory = $${directories:var}/pgdata
bin = ${postgresql91:location}/bin bin = ${postgresql91:location}/bin
services = $${directories:services} services = $${directories:services}
...@@ -48,6 +48,10 @@ template-postgresql-conf = ...@@ -48,6 +48,10 @@ template-postgresql-conf =
default_text_search_config = 'pg_catalog.english' default_text_search_config = 'pg_catalog.english'
unix_socket_directory = '{unix_socket_directory}' unix_socket_directory = '{unix_socket_directory}'
unix_socket_permissions = 0700 unix_socket_permissions = 0700
# backup
wal_level = hot_standby
max_wal_senders = 2
template-pg-hba-conf = template-pg-hba-conf =
# This configuration file is generated by a SlapOS instance profile. Manual edits will be overwritten. # This configuration file is generated by a SlapOS instance profile. Manual edits will be overwritten.
...@@ -57,6 +61,7 @@ template-pg-hba-conf = ...@@ -57,6 +61,7 @@ template-pg-hba-conf =
#do not conflict with other postgres instances on the same node #do not conflict with other postgres instances on the same node
#host all all 127.0.0.1/32 md5 #host all all 127.0.0.1/32 md5
{ipv4_auth} {ipv4_auth}
local replication postgres trust
template-hba-ipv4 = template-hba-ipv4 =
host all all {ip}/32 md5 host all all {ip}/32 md5
...@@ -97,18 +102,95 @@ key = $${slap-connection:key-file} ...@@ -97,18 +102,95 @@ key = $${slap-connection:key-file}
cert = $${slap-connection:cert-file} cert = $${slap-connection:cert-file}
#[postgres-backup-sql]
#recipe = slapos.recipe.template:jinja2
#template = inline:
# #!/bin/bash
# . {{environment}}
# {{postgres_bin}}/pg_dumpall --clean --file=$${directories:backup}/dumpall
# echo "backup done"
#rendered = $${directories:bin}/postgres-backup
#mode = 700
#context =
# raw environment $${buildout:directory}/environment.sh
# raw postgres_bin $${postgres-instance:bin}
[postgres-status]
recipe = slapos.recipe.template:jinja2
template = inline:
#!/bin/sh
extranet_part=`pwd | grep -o slappart[0-9+] | tail -1`
/opt/slapos/bin/slapos node supervisorctl --cfg ../../../../etc/slapos.cfg status $extranet_part:postgres-start-on-watch
rendered = $${directories:bin}/postgres-status
mode = 700
[postgres-stop]
recipe = slapos.recipe.template:jinja2
template = inline:
#!/bin/sh
extranet_part=`pwd | grep -o slappart[0-9+] | tail -1`
/opt/slapos/bin/slapos node supervisorctl --cfg ../../../../etc/slapos.cfg stop $extranet_part:postgres-start-on-watch
rendered = $${directories:bin}/postgres-stop
mode = 700
[postgres-start]
recipe = slapos.recipe.template:jinja2
template = inline:
#!/bin/sh
extranet_part=`pwd | grep -o slappart[0-9+] | tail -1`
/opt/slapos/bin/slapos node supervisorctl --cfg ../../../../etc/slapos.cfg start $extranet_part:postgres-start-on-watch
rendered = $${directories:bin}/postgres-start
mode = 700
[postgres-restore]
recipe = slapos.recipe.template:jinja2
template = inline:
#!/bin/bash
. {{environment}}
# shut down postgres
$${directories:bin}/postgres-stop
# check that postgres is down or refuse to run
$${directories:bin}/postgres-status | grep STOPPED || exit 10
echo "restoring from {{backup_dir}}"
rm -rf {{pgdata}}/pg_* {{pgdata}}/base {{pgdata}}/global {{pgdata}}/PG_VERSION
cp -a {{backup_dir}}/pg_* {{backup_dir}}/base {{backup_dir}}/global {{backup_dir}}/PG_VERSION {{pgdata}}/
echo "restore done"
echo "SELECT 1" | postgres --single -D {{pgdata}} {{dbname}} || (rm {{pgdata}}/postmaster.pid; pg_resetxlog -f {{pgdata}})
for table in blob partenaire contact visite; do
echo "COPY (SELECT COUNT(*) FROM $table) To '{{pgdata}}/$table.count' (format csv, delimiter ';')" | postgres --single -D {{pgdata}} {{dbname}}
done
rendered = $${directories:bin}/postgres-restore
mode = 700
context =
raw dbname extranet_spr_production
raw environment $${buildout:directory}/environment.sh
raw postgres_bin $${postgres-instance:bin}
raw pgdata $${postgres-instance:pgdata-directory}
raw backup_dir $${directories:backup}
[postgres-backup] [postgres-backup]
recipe = slapos.recipe.template:jinja2 recipe = slapos.recipe.template:jinja2
template = inline: template = inline:
#!/bin/bash #!/bin/bash
. {{environment}} . {{environment}}
{{postgres_bin}}/pg_dumpall --clean --file=$${directories:backup}/dumpall rm -rf {{backup_dir}}
{{postgres_bin}}/pg_basebackup -D {{backup_dir}} -x -U postgres
echo "backup done" echo "backup done"
rendered = $${directories:bin}/postgres-backup rendered = $${directories:bin}/postgres-backup
mode = 700 mode = 700
context = context =
raw environment $${buildout:directory}/environment.sh raw environment $${buildout:directory}/environment.sh
raw postgres_bin $${postgres-instance:bin} raw postgres_bin $${postgres-instance:bin}
raw backup_dir $${directories:backup}
[cron-postgres-backup] [cron-postgres-backup]
......
...@@ -26,6 +26,10 @@ parts = ...@@ -26,6 +26,10 @@ parts =
redis redis
cron cron
postgres-backup postgres-backup
postgres-restore
postgres-start
postgres-stop
postgres-status
cron-postgres-backup cron-postgres-backup
......
...@@ -239,14 +239,14 @@ configure-command = ...@@ -239,14 +239,14 @@ configure-command =
recipe = slapos.recipe.template recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance.cfg.in url = ${:_profile_base_location_}/instance.cfg.in
output = ${buildout:directory}/instance.cfg output = ${buildout:directory}/instance.cfg
md5sum = 6aaed03a96475027eff404c430d7888f md5sum = 02e0a25e4ffdb63a18cc29d0c9055919
mode = 0644 mode = 0644
[instance-postgres] [instance-postgres]
recipe = slapos.recipe.template recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance-postgres.cfg.in url = ${:_profile_base_location_}/instance-postgres.cfg.in
output = ${buildout:directory}/instance-postgres.cfg output = ${buildout:directory}/instance-postgres.cfg
md5sum = 5fc618f929c9d34cdaca57b17864c611 md5sum = 16a2d43b29a3c497c03a496f423c1600
mode = 0644 mode = 0644
[instance-redis] [instance-redis]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment