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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Lukas Niegsch
slapos
Commits
6b1c6296
Commit
6b1c6296
authored
Nov 07, 2012
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored backup recipe
parent
db6bc831
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
60 deletions
+51
-60
slapos/recipe/mydumper.py
slapos/recipe/mydumper.py
+51
-60
No files found.
slapos/recipe/mydumper.py
View file @
6b1c6296
...
...
@@ -28,85 +28,76 @@ import subprocess
from
slapos.recipe.librecipe
import
GenericBaseRecipe
def
dump
(
args
):
mydumper_cmd
=
[
args
[
'mydumper'
]]
mydumper_cmd
.
extend
([
'-B'
,
args
[
'database'
]])
if
args
[
'socket'
]
is
not
None
:
mydumper_cmd
.
extend
([
'-S'
,
args
[
'socket'
]])
else
:
mydumper_cmd
.
extend
([
'-h'
,
args
[
'host'
]])
mydumper_cmd
.
etxned
([
'-P'
,
args
[
'port'
]])
mydumper_cmd
.
extend
([
'-u'
,
args
[
'user'
]])
if
args
[
'password'
]
is
not
None
:
mydumper_cmd
.
extend
([
'-p'
,
args
[
'password'
]])
if
args
[
'compression'
]:
mydumper_cmd
.
append
(
'--compress'
)
def
_mydumper_base_cmd
(
mydumper
,
database
,
user
,
password
,
socket
=
None
,
host
=
None
,
port
=
None
,
**
kw
):
cmd
=
[
mydumper
]
cmd
.
extend
([
'-B'
,
database
])
if
args
[
'rows'
]
is
not
None
:
mydumper_cmd
.
extend
([
'-r'
,
args
[
'rows'
]])
mydumper_cmd
.
extend
([
'-o'
,
args
[
'directory'
]])
if
socket
:
cmd
.
extend
([
'-S'
,
socket
])
else
:
cmd
.
extend
([
'-h'
,
host
])
cmd
.
extend
([
'-P'
,
port
])
subprocess
.
check_call
(
mydumper_cmd
)
cmd
.
extend
([
'-u'
,
user
])
if
password
:
cmd
.
extend
([
'-p'
,
password
])
return
cmd
def
do_import
(
args
):
mydumper_cmd
=
[
args
[
'mydumper'
]]
mydumper_cmd
.
extend
([
'-B'
,
args
[
'database'
]])
def
do_export
(
args
):
cmd
=
_mydumper_base_cmd
(
**
args
)
if
args
[
'socket'
]
is
not
None
:
mydumper_cmd
.
extend
([
'-S'
,
args
[
'socket'
]])
else
:
mydumper_cmd
.
extend
([
'-h'
,
args
[
'host'
]])
mydumper_cmd
.
etxned
([
'-P'
,
args
[
'port'
]])
if
args
[
'compression'
]:
cmd
.
append
(
'--compress'
)
mydumper_cmd
.
extend
([
'-u'
,
args
[
'user'
]])
if
args
[
'password'
]
is
not
None
:
mydumper_cmd
.
extend
([
'-p'
,
args
[
'password'
]])
if
args
[
'rows'
]
is
not
None
:
cmd
.
extend
([
'-r'
,
args
[
'rows'
]])
mydumper_cmd
.
append
(
'--overwrite-tables'
)
cmd
.
extend
([
'-o'
,
args
[
'directory'
]]
)
mydumper_cmd
.
extend
([
'-d'
,
args
[
'directory'
]]
)
subprocess
.
check_call
(
cmd
)
subprocess
.
check_call
(
mydumper_cmd
)
def
do_import
(
args
):
cmd
=
_mydumper_base_cmd
(
**
args
)
cmd
.
append
(
'--overwrite-tables'
)
cmd
.
extend
([
'-d'
,
args
[
'directory'
]])
subprocess
.
check_call
(
cmd
)
class
Recipe
(
GenericBaseRecipe
):
def
install
(
self
):
# Host or socket should be defined
try
:
self
.
options
[
'host'
]
except
:
self
.
options
[
'socket'
]
config
=
dict
(
database
=
self
.
options
[
'database'
],
socket
=
self
.
options
.
get
(
'socket'
),
host
=
self
.
options
.
get
(
'host'
),
port
=
self
.
options
.
get
(
'port'
,
3306
),
directory
=
self
.
options
[
'backup-directory'
],
user
=
self
.
options
[
'user'
],
password
=
self
.
options
.
get
(
'password'
),
)
name
=
__name__
config
=
{
'database'
:
self
.
options
[
'database'
],
'directory'
:
self
.
options
[
'backup-directory'
],
'user'
:
self
.
options
[
'user'
],
'password'
:
self
.
options
.
get
(
'password'
),
}
if
self
.
options
.
get
(
'host'
):
config
[
'host'
]
=
self
.
options
[
'host'
]
config
[
'port'
]
=
self
.
options
.
get
(
'port'
,
3306
)
elif
self
.
options
.
get
(
'socket'
):
config
[
'socket'
]
=
self
.
options
[
'socket'
]
else
:
raise
ValueError
(
"host or socket must be defined"
)
if
self
.
optionIsTrue
(
'import'
,
False
):
config
.
update
(
mydumper
=
self
.
options
[
'myloader-binary'
])
name
+=
'.do_import'
function
=
do_import
config
[
'mydumper'
]
=
self
.
options
[
'myloader-binary'
]
else
:
config
.
update
(
mydumper
=
self
.
options
[
'mydumper-binary'
],
compression
=
self
.
optionIsTrue
(
'compression'
,
default
=
False
),
rows
=
self
.
options
.
get
(
'rows'
),
)
name
+=
'.dump'
function
=
do_export
config
[
'mydumper'
]
=
self
.
options
[
'mydumper-binary'
]
config
[
'compression'
]
=
self
.
optionIsTrue
(
'compression'
,
default
=
False
)
config
[
'rows'
]
=
self
.
options
.
get
(
'rows'
)
wrapper
=
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
name
,
config
)
wrapper
=
self
.
createPythonScript
(
name
=
self
.
options
[
'wrapper'
],
absolute_function
=
'%s.%s'
%
(
__name__
,
function
.
func_name
)
,
arguments
=
config
)
return
[
wrapper
]
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