From 42a624bc0ae5d9061d785160056de0a61cd20679 Mon Sep 17 00:00:00 2001 From: MikhailBurdukov <102754618+MikhailBurdukov@users.noreply.github.com> Date: Mon, 1 Jul 2024 20:50:56 +0300 Subject: [PATCH] Ch-backup commands with stopped Clickhouse (#166) --- ch_backup/backup_context.py | 6 ++++-- ch_backup/ch_backup.py | 15 -------------- tests/integration/ch_backup.featureset | 1 + .../features/operations_without_ch.feature | 20 +++++++++++++++++++ 4 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 tests/integration/features/operations_without_ch.feature diff --git a/ch_backup/backup_context.py b/ch_backup/backup_context.py index 6c6203c8..c8a5eed8 100644 --- a/ch_backup/backup_context.py +++ b/ch_backup/backup_context.py @@ -101,7 +101,7 @@ def backup_layout(self) -> BackupLayout: Getter backup_layout """ if not hasattr(self, "_backup_layout"): - self._backup_layout = BackupLayout(self._config) + self._backup_layout = BackupLayout(self._config_root) return self._backup_layout @backup_layout.setter @@ -151,7 +151,7 @@ def restore_context(self) -> RestoreContext: Getter restore_context """ if not hasattr(self, "_restore_context"): - self._restore_context = RestoreContext(self._config) + self._restore_context = RestoreContext(self.config) return self._restore_context @restore_context.setter @@ -208,6 +208,8 @@ def ch_config(self) -> ClickhouseConfig: """ Getter ch_config """ + if not hasattr(self, "_ch_config"): + self._ch_config = ClickhouseConfig(self._config_root) return self._ch_config @ch_config.setter diff --git a/ch_backup/ch_backup.py b/ch_backup/ch_backup.py index bec5b378..25341766 100644 --- a/ch_backup/ch_backup.py +++ b/ch_backup/ch_backup.py @@ -13,13 +13,9 @@ collect_dedup_info, collect_dedup_references_for_batch_backup_deletion, ) -from ch_backup.backup.layout import BackupLayout from ch_backup.backup.metadata import BackupMetadata, BackupState, TableMetadata -from ch_backup.backup.restore_context import RestoreContext from ch_backup.backup.sources import BackupSources from ch_backup.backup_context import BackupContext -from ch_backup.clickhouse.config import ClickhouseConfig -from ch_backup.clickhouse.control import ClickhouseCTL from ch_backup.clickhouse.models import Database from ch_backup.config import Config from ch_backup.exceptions import ( @@ -64,18 +60,7 @@ def _context(self) -> BackupContext: """ Create and configure BackupContext """ - ctx = BackupContext(self._config) - ctx.ch_ctl_conf = self._config["clickhouse"] - ctx.main_conf = self._config["main"] - - ctx.ch_ctl = ClickhouseCTL(ctx.ch_ctl_conf, ctx.main_conf, ctx.config) - ctx.backup_layout = BackupLayout(self._config) - - ctx.config = self._config["backup"] - ctx.zk_config = self._config.get("zookeeper") - ctx.restore_context = RestoreContext(ctx.config) - ctx.ch_config = ClickhouseConfig(self._config) return ctx def reload_config(self, config: Config) -> None: diff --git a/tests/integration/ch_backup.featureset b/tests/integration/ch_backup.featureset index 163306d8..67fc8989 100644 --- a/tests/integration/ch_backup.featureset +++ b/tests/integration/ch_backup.featureset @@ -23,3 +23,4 @@ features/backup_misc_commands.feature features/lock.feature features/traffic_limiting.feature features/named_collections.feature +features/operations_without_ch.feature diff --git a/tests/integration/features/operations_without_ch.feature b/tests/integration/features/operations_without_ch.feature new file mode 100644 index 00000000..84637437 --- /dev/null +++ b/tests/integration/features/operations_without_ch.feature @@ -0,0 +1,20 @@ +Feature: Ch-backup operations without connection to clickhouse-server. + + Background: + Given default configuration + And a working s3 + And a working zookeeper on zookeeper01 + And a working clickhouse on clickhouse01 + And a working clickhouse on clickhouse02 + + Scenario: Version command without ch-server. + When we stop clickhouse at clickhouse01 + Then we got a valid ch-backup version on clickhouse01 + + Scenario: List command without ch-server. + When we create clickhouse01 clickhouse backup + And we stop clickhouse at clickhouse01 + + Then we got the following backups on clickhouse01 + | num | state | + | 0 | created |