Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
slapos
Commits
97e89b28
Commit
97e89b28
authored
Nov 26, 2012
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
backup postgres with custom format and no permission
parent
19a2b07e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
22 deletions
+21
-22
slapos/recipe/postgres/__init__.py
slapos/recipe/postgres/__init__.py
+16
-19
stack/lapp/buildout.cfg
stack/lapp/buildout.cfg
+1
-1
stack/lapp/postgres/instance-postgres-import.cfg.in
stack/lapp/postgres/instance-postgres-import.cfg.in
+4
-2
No files found.
slapos/recipe/postgres/__init__.py
View file @
97e89b28
...
...
@@ -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
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
)
...
...
stack/lapp/buildout.cfg
View file @
97e89b28
...
...
@@ -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]
...
...
stack/lapp/postgres/instance-postgres-import.cfg.in
View file @
97e89b28
...
...
@@ -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}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment