From 36ea4ba8578f10401d2549808e17aadf0dff9594 Mon Sep 17 00:00:00 2001 From: Steven Soulen Date: Wed, 7 Nov 2018 09:55:36 -0600 Subject: [PATCH] add arg_per_database. Fixes #180 --- .../holland/backup/mysqldump/base.py | 8 +++++++- .../holland/backup/mysqldump/plugin.py | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/plugins/holland.backup.mysqldump/holland/backup/mysqldump/base.py b/plugins/holland.backup.mysqldump/holland/backup/mysqldump/base.py index 7fbe3b46..7d0ffa17 100644 --- a/plugins/holland.backup.mysqldump/holland/backup/mysqldump/base.py +++ b/plugins/holland.backup.mysqldump/holland/backup/mysqldump/base.py @@ -4,6 +4,7 @@ import csv import errno import logging +import json from holland.core.backup import BackupError from holland.lib.safefilename import encode from holland.backup.mysqldump.command import ALL_DATABASES, MySQLDumpError @@ -27,7 +28,8 @@ def start(mysqldump, lock_method='auto-detect', file_per_database=True, open_stream=open, - compression_ext=''): + compression_ext='', + arg_per_database=None): """Run a mysqldump backup""" if not schema and file_per_database: raise BackupError("file_per_database specified without a valid schema") @@ -47,6 +49,8 @@ def start(mysqldump, write_manifest(schema, open_stream, compression_ext) if file_per_database: + if arg_per_database: + arg_per_database = json.loads(arg_per_database) flush_logs = '--flush-logs' in mysqldump.options if flush_logs: mysqldump.options.remove('--flush-logs') @@ -65,6 +69,8 @@ def start(mysqldump, raise BackupError("Failed to open output stream %s: %s" % ( db_name + '.sql' + compression_ext, str(exc))) try: + if db_name in arg_per_database: + more_options.append(arg_per_database[db_name]) mysqldump.run([db.name], stream, more_options) finally: try: diff --git a/plugins/holland.backup.mysqldump/holland/backup/mysqldump/plugin.py b/plugins/holland.backup.mysqldump/holland/backup/mysqldump/plugin.py index 81fe179f..3f602a98 100644 --- a/plugins/holland.backup.mysqldump/holland/backup/mysqldump/plugin.py +++ b/plugins/holland.backup.mysqldump/holland/backup/mysqldump/plugin.py @@ -52,6 +52,9 @@ bin-log-position = boolean(default=no) file-per-database = boolean(default=yes) +#arg-per-database is only used if file-per-database is true +## takes a json object {"table1": "--arg", "table2": "--arg"} +arg-per-database = string(default={}) additional-options = force_list(default=list()) @@ -240,7 +243,8 @@ def _backup(self): lock_method=config['lock-method'], file_per_database=config['file-per-database'], open_stream=self._open_stream, - compression_ext=ext) + compression_ext=ext, + arg_per_database=config['arg-per-database']) except MySQLDumpError as exc: raise BackupError(str(exc))