Commit 97e89b28 authored by Marco Mariani's avatar Marco Mariani

backup postgres with custom format and no permission

parent 19a2b07e
......@@ -206,26 +206,22 @@ class ExportRecipe(GenericBaseRecipe):
def install(self):
pgdata = self.options['pgdata-directory']
ret = []
wrapper = self.options['wrapper']
self.createBackupScript(wrapper)
ret.append(wrapper)
return ret
return [wrapper]
def createBackupScript(self, wrapper):
"""
Create a script to backup the database in plain SQL format.
Create a script to backup the database in 'custom' format.
"""
content = textwrap.dedent("""\
#!/bin/sh
umask 077
%(bin)s/pg_dump \\
-h %(pgdata-directory)s \\
-f %(backup-directory)s/backup.sql \\
--host=%(pgdata-directory)s \\
--format=custom \\
--file=%(backup-directory)s/backup.dump \\
%(dbname)s
""" % self.options)
self.createExecutable(wrapper, content=content)
......@@ -236,23 +232,24 @@ class ImportRecipe(GenericBaseRecipe):
def install(self):
pgdata = self.options['pgdata-directory']
ret = []
if not os.path.exists(pgdata):
wrapper = self.options['wrapper']
self.createRestoreScript(wrapper)
ret.append(wrapper)
return ret
wrapper = self.options['wrapper']
self.createRestoreScript(wrapper)
return [wrapper]
def createRestoreScript(self, wrapper):
"""
Create a script to backup the database in plain SQL format.
Create a script to restore the database from 'custom' format.
"""
content = textwrap.dedent("""\
#!/bin/sh
%(bin)s/pg_restore -h %(pgdata-directory)s -d %(dbname)s %(backup-directory)s/backup.sql
%(bin)s/pg_restore \\
--host=%(pgdata-directory)s \\
--dbname=%(dbname)s \\
--clean \\
--no-owner \\
--no-acl \\
%(backup-directory)s/backup.dump
""" % self.options)
self.createExecutable(wrapper, content=content)
......
......@@ -92,7 +92,7 @@ mode = 0644
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/postgres/instance-postgres-import.cfg.in
output = ${buildout:directory}/instance-postgres-import.cfg
md5sum = feb43a65eefd9c5dea8e7d3551465956
md5sum = 1989ba2164dd5f79793a04e0a02ea515
mode = 0644
[instance-postgres-export]
......
......@@ -2,11 +2,13 @@
extends = ${instance-postgres:output}
${pbsready-import:output}
parts += postgres-instance
parts +=
postgres-instance
[importer]
recipe = slapos.cookbook:postgres.import
wrapper = $${rootdirectory:bin}/resilient-importer
wrapper = $${rootdirectory:bin}/$${slap-parameter:namebase}-importer
bin = $${postgres-instance:bin}
pgdata-directory = $${postgres-instance:pgdata-directory}
backup-directory = $${postgres-instance:backup-directory}
......
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