Skip to content

Commit

Permalink
mysql_db: added zstd support (#696)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio-IME authored Jan 16, 2025
1 parent 022ed60 commit a45a0d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/696-mysql-db-add-zstd-support.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
minor_changes:
- mysql_db - added ``zstd`` (de)compression support for ``import``/``dump`` states
(https://github.com/ansible-collections/community.mysql/issues/696).
8 changes: 6 additions & 2 deletions plugins/modules/mysql_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
target:
description:
- Location, on the remote host, of the dump file to read from or write to.
- Uncompressed SQL files (C(.sql)) as well as bzip2 (C(.bz2)), gzip (C(.gz)) and
xz (Added in 2.0) compressed files are supported.
- Uncompressed SQL files (C(.sql)) as well as bzip2 (C(.bz2)), gzip (C(.gz)),
xz (Added in 2.0) and zstd (C(.zst)) (Added in 3.12.0) compressed files are supported.
type: path
single_transaction:
description:
Expand Down Expand Up @@ -455,6 +455,8 @@ def db_dump(module, host, user, password, db_name, target, all_databases, port,
path = module.get_bin_path('bzip2', True)
elif os.path.splitext(target)[-1] == '.xz':
path = module.get_bin_path('xz', True)
elif os.path.splitext(target)[-1] == '.zst':
path = module.get_bin_path('zstd', True)

if path:
cmd = '%s | %s > %s' % (cmd, path, shlex_quote(target))
Expand Down Expand Up @@ -526,6 +528,8 @@ def db_import(module, host, user, password, db_name, target, all_databases, port
comp_prog_path = module.get_bin_path('bzip2', required=True)
elif os.path.splitext(target)[-1] == '.xz':
comp_prog_path = module.get_bin_path('xz', required=True)
elif os.path.splitext(target)[-1] == '.zst':
comp_prog_path = module.get_bin_path('zstd', required=True)
if comp_prog_path:
# The line below is for returned data only:
executed_commands.append('%s -dc %s | %s' % (comp_prog_path, target, cmd))
Expand Down

0 comments on commit a45a0d0

Please sign in to comment.