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
isaak yansane-sisk
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
...
@@ -28,85 +28,76 @@ import subprocess
from
slapos.recipe.librecipe
import
GenericBaseRecipe
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
:
def
_mydumper_base_cmd
(
mydumper
,
database
,
user
,
password
,
mydumper_cmd
.
extend
([
'-S'
,
args
[
'socket'
]])
socket
=
None
,
host
=
None
,
port
=
None
,
**
kw
):
else
:
cmd
=
[
mydumper
]
mydumper_cmd
.
extend
([
'-h'
,
args
[
'host'
]])
cmd
.
extend
([
'-B'
,
database
])
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'
)
if
args
[
'rows'
]
is
not
None
:
if
socket
:
mydumper_cmd
.
extend
([
'-r'
,
args
[
'rows'
]])
cmd
.
extend
([
'-S'
,
socket
])
else
:
mydumper_cmd
.
extend
([
'-o'
,
args
[
'directory'
]])
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
):
def
do_export
(
args
):
mydumper_cmd
=
[
args
[
'mydumper'
]]
cmd
=
_mydumper_base_cmd
(
**
args
)
mydumper_cmd
.
extend
([
'-B'
,
args
[
'database'
]])
if
args
[
'socket'
]
is
not
None
:
if
args
[
'compression'
]:
mydumper_cmd
.
extend
([
'-S'
,
args
[
'socket'
]])
cmd
.
append
(
'--compress'
)
else
:
mydumper_cmd
.
extend
([
'-h'
,
args
[
'host'
]])
mydumper_cmd
.
etxned
([
'-P'
,
args
[
'port'
]])
mydumper_cmd
.
extend
([
'-u'
,
args
[
'user'
]])
if
args
[
'rows'
]
is
not
None
:
if
args
[
'password'
]
is
not
None
:
cmd
.
extend
([
'-r'
,
args
[
'rows'
]])
mydumper_cmd
.
extend
([
'-p'
,
args
[
'password'
]])
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
):
class
Recipe
(
GenericBaseRecipe
):
def
install
(
self
):
def
install
(
self
):
# Host or socket should be defined
config
=
{
try
:
'database'
:
self
.
options
[
'database'
],
self
.
options
[
'host'
]
'directory'
:
self
.
options
[
'backup-directory'
],
except
:
'user'
:
self
.
options
[
'user'
],
self
.
options
[
'socket'
]
'password'
:
self
.
options
.
get
(
'password'
),
}
config
=
dict
(
database
=
self
.
options
[
'database'
],
socket
=
self
.
options
.
get
(
'socket'
),
if
self
.
options
.
get
(
'host'
):
host
=
self
.
options
.
get
(
'host'
),
config
[
'host'
]
=
self
.
options
[
'host'
]
port
=
self
.
options
.
get
(
'port'
,
3306
),
config
[
'port'
]
=
self
.
options
.
get
(
'port'
,
3306
)
directory
=
self
.
options
[
'backup-directory'
],
elif
self
.
options
.
get
(
'socket'
):
user
=
self
.
options
[
'user'
],
config
[
'socket'
]
=
self
.
options
[
'socket'
]
password
=
self
.
options
.
get
(
'password'
),
else
:
)
raise
ValueError
(
"host or socket must be defined"
)
name
=
__name__
if
self
.
optionIsTrue
(
'import'
,
False
):
if
self
.
optionIsTrue
(
'import'
,
False
):
config
.
update
(
mydumper
=
self
.
options
[
'myloader-binary'
])
function
=
do_import
name
+=
'.do_import'
config
[
'mydumper'
]
=
self
.
options
[
'myloader-binary'
]
else
:
else
:
config
.
update
(
mydumper
=
self
.
options
[
'mydumper-binary'
],
function
=
do_export
compression
=
self
.
optionIsTrue
(
'compression'
,
default
=
False
),
config
[
'mydumper'
]
=
self
.
options
[
'mydumper-binary'
]
rows
=
self
.
options
.
get
(
'rows'
),
config
[
'compression'
]
=
self
.
optionIsTrue
(
'compression'
,
default
=
False
)
)
config
[
'rows'
]
=
self
.
options
.
get
(
'rows'
)
name
+=
'.dump'
wrapper
=
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
wrapper
=
self
.
createPythonScript
(
name
=
self
.
options
[
'wrapper'
],
name
,
absolute_function
=
'%s.%s'
%
(
__name__
,
function
.
func_name
)
,
config
)
arguments
=
config
)
return
[
wrapper
]
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