Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
84a692bc
Commit
84a692bc
authored
Oct 16, 2013
by
James Tanner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #4301 Use module_common functions for mysqldump and return better errors
parent
efe2a9fb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
16 deletions
+32
-16
library/database/mysql_db
+32
-16
No files found.
library/database/mysql_db
View file @
84a692bc
...
@@ -116,17 +116,25 @@ def db_delete(cursor, db):
...
@@ -116,17 +116,25 @@ def db_delete(cursor, db):
cursor
.
execute
(
query
)
cursor
.
execute
(
query
)
return
True
return
True
def
db_dump
(
host
,
user
,
password
,
db_name
,
target
):
def
db_dump
(
module
,
host
,
user
,
password
,
db_name
,
target
,
socket
=
None
):
res
=
os
.
system
(
"/usr/bin/mysqldump -q -h "
+
host
+
" -u "
+
user
+
" --password="
+
password
+
" "
cmd
=
module
.
get_bin_path
(
'mysqldump'
,
True
)
+
db_name
+
" > "
cmd
+=
" --quick --host=
%
s --user=
%
s --password=
%
s"
%
(
host
,
user
,
password
)
+
target
)
if
socket
is
not
None
:
return
(
res
==
0
)
cmd
+=
" --socket=
%
s"
%
socket
cmd
+=
"
%
s"
%
db_name
cmd
+=
" >
%
s"
%
target
rc
,
stdout
,
stderr
=
module
.
run_command
(
cmd
)
return
rc
,
stdout
,
stderr
def
db_import
(
host
,
user
,
password
,
db_name
,
target
):
def
db_import
(
module
,
host
,
user
,
password
,
db_name
,
target
,
socket
=
None
):
res
=
os
.
system
(
"/usr/bin/mysql -h "
+
host
+
" -u "
+
user
+
" --password="
+
password
+
" "
cmd
=
module
.
get_bin_path
(
'mysqldump'
,
True
)
+
db_name
+
" < "
cmd
+=
" --host=
%
s --user=
%
s --password=
%
s"
%
(
host
,
user
,
password
)
+
target
)
if
socket
is
not
None
:
return
(
res
==
0
)
cmd
+=
" --socket=
%
s"
%
socket
cmd
+=
"
%
s"
%
db_name
cmd
+=
" <
%
s"
%
target
rc
,
stdout
,
stderr
=
module
.
run_command
(
cmd
)
return
rc
,
stdout
,
stderr
def
db_create
(
cursor
,
db
,
encoding
,
collation
):
def
db_create
(
cursor
,
db
,
encoding
,
collation
):
if
encoding
:
if
encoding
:
...
@@ -258,13 +266,21 @@ def main():
...
@@ -258,13 +266,21 @@ def main():
if
state
==
"absent"
:
if
state
==
"absent"
:
changed
=
db_delete
(
cursor
,
db
)
changed
=
db_delete
(
cursor
,
db
)
elif
state
==
"dump"
:
elif
state
==
"dump"
:
changed
=
db_dump
(
login_host
,
login_user
,
login_password
,
db
,
target
)
rc
,
stdout
,
stderr
=
db_dump
(
module
,
login_host
,
login_user
,
if
not
changed
:
login_password
,
db
,
target
,
module
.
fail_json
(
msg
=
"dump failed!"
)
socket
=
module
.
params
[
'login_unix_socket'
])
if
rc
!=
0
:
module
.
fail_json
(
msg
=
"
%
s"
%
stderr
)
else
:
module
.
exit_json
(
changed
=
True
,
db
=
db
,
msg
=
stdout
)
elif
state
==
"import"
:
elif
state
==
"import"
:
changed
=
db_import
(
login_host
,
login_user
,
login_password
,
db
,
target
)
rc
,
stdout
,
stderr
=
db_import
(
module
,
login_host
,
login_user
,
if
not
changed
:
login_password
,
db
,
target
,
module
.
fail_json
(
msg
=
"import failed!"
)
socket
=
module
.
params
[
'login_unix_socket'
])
if
rc
!=
0
:
module
.
fail_json
(
msg
=
"
%
s"
%
stderr
)
else
:
module
.
exit_json
(
changed
=
True
,
db
=
db
,
msg
=
stdout
)
else
:
else
:
if
state
==
"present"
:
if
state
==
"present"
:
changed
=
db_create
(
cursor
,
db
,
encoding
,
collation
)
changed
=
db_create
(
cursor
,
db
,
encoding
,
collation
)
...
...
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