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