summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToshio Kuratomi <a.badger@gmail.com>2015-03-04 06:45:16 -0800
committerToshio Kuratomi <a.badger@gmail.com>2015-03-04 06:45:16 -0800
commitec6304d5a0b7fea5c0e97e3596a6128d54cfbf75 (patch)
tree346edec4d4f3a4953aa5e2b0e700ee63d3c6c40b
parent640e0fc53c0dff26dc5ef7bc39f7fe649e3068b5 (diff)
parentee8039ef09bb35142ab2e7b5698248ba2422456d (diff)
downloadansible-modules-core-ec6304d5a0b7fea5c0e97e3596a6128d54cfbf75.tar.gz
Merge pull request #824 from Jmainguy/mysql_db_616
Now correctly gzip/bzips file back up in case of import failure
-rw-r--r--database/mysql/mysql_db.py52
1 files changed, 26 insertions, 26 deletions
diff --git a/database/mysql/mysql_db.py b/database/mysql/mysql_db.py
index 75416834..135dd7cb 100644
--- a/database/mysql/mysql_db.py
+++ b/database/mysql/mysql_db.py
@@ -152,39 +152,39 @@ def db_import(module, host, user, password, db_name, target, port, socket=None):
cmd += " --host=%s --port=%s" % (pipes.quote(host), pipes.quote(port))
cmd += " -D %s" % pipes.quote(db_name)
if os.path.splitext(target)[-1] == '.gz':
- gunzip_path = module.get_bin_path('gunzip')
- if gunzip_path:
- rc, stdout, stderr = module.run_command('%s %s' % (gunzip_path, target))
- if rc != 0:
- return rc, stdout, stderr
- cmd += " < %s" % pipes.quote(os.path.splitext(target)[0])
+ gzip_path = module.get_bin_path('gzip')
+ if not gzip_path:
+ module.fail_json(msg="gzip command not found")
+ #gzip -d file (uncompress)
+ rc, stdout, stderr = module.run_command('%s -d %s' % (gzip_path, target))
+ if rc != 0:
+ return rc, stdout, stderr
+ #Import sql
+ cmd += " < %s" % pipes.quote(os.path.splitext(target)[0])
+ try:
rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True)
if rc != 0:
return rc, stdout, stderr
- gzip_path = module.get_bin_path('gzip')
- if gzip_path:
- rc, stdout, stderr = module.run_command('%s %s' % (gzip_path, os.path.splitext(target)[0]))
- else:
- module.fail_json(msg="gzip command not found")
- else:
- module.fail_json(msg="gunzip command not found")
+ finally:
+ #gzip file back up
+ module.run_command('%s %s' % (gzip_path, os.path.splitext(target)[0]))
elif os.path.splitext(target)[-1] == '.bz2':
- bunzip2_path = module.get_bin_path('bunzip2')
- if bunzip2_path:
- rc, stdout, stderr = module.run_command('%s %s' % (bunzip2_path, target))
- if rc != 0:
- return rc, stdout, stderr
- cmd += " < %s" % pipes.quote(os.path.splitext(target)[0])
+ bzip2_path = module.get_bin_path('bzip2')
+ if not bzip2_path:
+ module.fail_json(msg="bzip2 command not found")
+ #bzip2 -d file (uncompress)
+ rc, stdout, stderr = module.run_command('%s -d %s' % (bzip2_path, target))
+ if rc != 0:
+ return rc, stdout, stderr
+ #Import sql
+ cmd += " < %s" % pipes.quote(os.path.splitext(target)[0])
+ try:
rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True)
if rc != 0:
return rc, stdout, stderr
- bzip2_path = module.get_bin_path('bzip2')
- if bzip2_path:
- rc, stdout, stderr = module.run_command('%s %s' % (bzip2_path, os.path.splitext(target)[0]))
- else:
- module.fail_json(msg="bzip2 command not found")
- else:
- module.fail_json(msg="bunzip2 command not found")
+ finally:
+ #bzip2 file back up
+ rc, stdout, stderr = module.run_command('%s %s' % (bzip2_path, os.path.splitext(target)[0]))
else:
cmd += " < %s" % pipes.quote(target)
rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True)