diff --git a/slapos/recipe/postgres/__init__.py b/slapos/recipe/postgres/__init__.py index 26fd94e6ac09978592a5c15c698b119a7e9bbee3..cea26e5ea6c67166a993b63463a0ba6f37d80aa7 100644 --- a/slapos/recipe/postgres/__init__.py +++ b/slapos/recipe/postgres/__init__.py @@ -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) diff --git a/stack/lapp/buildout.cfg b/stack/lapp/buildout.cfg index 9bb6f414631a191da8e4620e25c7280e8e0d0a1d..6915e690fa4117526ac4c0057e03c45f95aa4758 100644 --- a/stack/lapp/buildout.cfg +++ b/stack/lapp/buildout.cfg @@ -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] diff --git a/stack/lapp/postgres/instance-postgres-import.cfg.in b/stack/lapp/postgres/instance-postgres-import.cfg.in index f267370bf68d80a6924a04376eee12f1c542c73b..5b2ac52a9eebcb928d5f54b2d91c90e4c378beb9 100644 --- a/stack/lapp/postgres/instance-postgres-import.cfg.in +++ b/stack/lapp/postgres/instance-postgres-import.cfg.in @@ -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}