Skip to content

Commit

Permalink
Ch-backup commands with stopped Clickhouse (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailBurdukov authored Jul 1, 2024
1 parent ae46512 commit 42a624b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
6 changes: 4 additions & 2 deletions ch_backup/backup_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 0 additions & 15 deletions ch_backup/ch_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions tests/integration/ch_backup.featureset
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions tests/integration/features/operations_without_ch.feature
Original file line number Diff line number Diff line change
@@ -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 |

0 comments on commit 42a624b

Please sign in to comment.