Commit f4479fc5 authored by Marco Mariani's avatar Marco Mariani

abilian: optional backup_dir parameter in postgres_restore

parent e8bd1134
...@@ -23,12 +23,15 @@ def load_config(): ...@@ -23,12 +23,15 @@ def load_config():
if key in ['SECRET_KEY']: if key in ['SECRET_KEY']:
globals()[key] = str(value) globals()[key] = str(value)
# interpolate password if needed # interpolate password and host provided by separate files
try: try:
globals()['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI % {'password': SQLALCHEMY_DATABASE_PASSWORD} globals()['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI % {
'password': SQLALCHEMY_DATABASE_PASSWORD,
'ipv4': POSTGRES_IPV4
}
except NameError: except NameError:
pass raise NameError("The configuration is not complete yet")
load_config() load_config()
......
...@@ -151,12 +151,16 @@ template = inline: ...@@ -151,12 +151,16 @@ template = inline:
#!/bin/bash #!/bin/bash
. {{environment}} . {{environment}}
# shut down postgres # shut down postgres
backup_dir={{backup_dir}}
[ -n "$1" ] && backup_dir="$1"
$${directories:bin}/postgres-stop $${directories:bin}/postgres-stop
# check that postgres is down or refuse to run # check that postgres is down or refuse to run
$${directories:bin}/postgres-status | grep STOPPED || exit 10 $${directories:bin}/postgres-status | grep STOPPED || exit 10
echo "restoring from {{backup_dir}}" echo "restoring from $backup_dir"
mv {{pgdata}}/pg_hba.conf {{pgdata}}/hba.conf
rm -rf {{pgdata}}/pg_* {{pgdata}}/base {{pgdata}}/global {{pgdata}}/PG_VERSION 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}}/ mv {{pgdata}}/hba.conf {{pgdata}}/pg_hba.conf
cp -a $backup_dir/pg_* $backup_dir/base $backup_dir/global $backup_dir/PG_VERSION {{pgdata}}/
echo "restore done" echo "restore done"
echo "SELECT 1" | postgres --single -D {{pgdata}} {{dbname}} || (rm {{pgdata}}/postmaster.pid; pg_resetxlog -f {{pgdata}}) echo "SELECT 1" | postgres --single -D {{pgdata}} {{dbname}} || (rm {{pgdata}}/postmaster.pid; pg_resetxlog -f {{pgdata}})
for table in blob partenaire contact visite; do for table in blob partenaire contact visite; do
......
...@@ -54,6 +54,8 @@ BROKER_URL = redis://:$${redis-requirepass:passwd}@[$${redis:ipv4}]:$${redis:por ...@@ -54,6 +54,8 @@ BROKER_URL = redis://:$${redis-requirepass:passwd}@[$${redis:ipv4}]:$${redis:por
CELERY_RESULT_BACKEND = redis://:$${redis-requirepass:passwd}@[$${redis:ipv4}]:$${redis:port}/2 CELERY_RESULT_BACKEND = redis://:$${redis-requirepass:passwd}@[$${redis:ipv4}]:$${redis:port}/2
SECRET_KEY = $${csrf-secret-key:passwd} SECRET_KEY = $${csrf-secret-key:passwd}
INSTANCE_HOST = $${instance-parameters:ipv6-random} INSTANCE_HOST = $${instance-parameters:ipv6-random}
POSTGRES_IPV4 = $${postgres-promise:hostname}
SQLALCHEMY_DATABASE_URI = postgres://extranet_spr_production:%(password)s@%(ipv4)s:5432/extranet_spr_production
......
...@@ -259,14 +259,14 @@ configure-command = ...@@ -259,14 +259,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 = 02e0a25e4ffdb63a18cc29d0c9055919 md5sum = 738b85f80484ff4d57d1218cf87b3c8a
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 = 16a2d43b29a3c497c03a496f423c1600 md5sum = e2bcc3dafdfc5bf331b743952ed98be2
mode = 0644 mode = 0644
[instance-redis] [instance-redis]
...@@ -295,7 +295,7 @@ mode = 0644 ...@@ -295,7 +295,7 @@ mode = 0644
[abilian-config] [abilian-config]
recipe = hexagonit.recipe.download recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/abilian-config.py url = ${:_profile_base_location_}/abilian-config.py
md5sum = e89ecb0293a49ab382337bdb1f676fb0 md5sum = 66bf5e8f6f763de85b474838e88753da
location = ${buildout:parts-directory}/${:_buildout_section_name_} location = ${buildout:parts-directory}/${:_buildout_section_name_}
filename = abilian-config.py filename = abilian-config.py
download-only = true download-only = true
......
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