From 44b84c2bcc108cf0868ff1b402202afa8845c3db Mon Sep 17 00:00:00 2001 From: Kirill <71129570+kirillgarbar@users.noreply.github.com> Date: Mon, 22 Jul 2024 15:40:24 +0300 Subject: [PATCH] Check if backup name exists and add retry on ClickhouseError for queries (#173) * Check if backup with given name already exists * Add retry for query on ClickhouseError --- ch_backup/ch_backup.py | 12 ++++++++---- ch_backup/clickhouse/client.py | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ch_backup/ch_backup.py b/ch_backup/ch_backup.py index 83647efc..78367191 100644 --- a/ch_backup/ch_backup.py +++ b/ch_backup/ch_backup.py @@ -106,6 +106,14 @@ def backup( """ # pylint: disable=too-many-branches # pylint: disable=too-many-locals + backups_with_light_meta = self._context.backup_layout.get_backups( + use_light_meta=True + ) + + for backup in backups_with_light_meta: + if name == backup.name: + raise ClickhouseBackupError(f"Backup with name {name} already exists") + logging.info(f"Backup sources: {sources}") assert not (db_names and tables) @@ -127,10 +135,6 @@ def backup( if db_names is not None: databases = [db for db in databases if db.name in db_names] - backups_with_light_meta = self._context.backup_layout.get_backups( - use_light_meta=True - ) - last_backup = next(iter(backups_with_light_meta), None) if last_backup and not self._check_min_interval(last_backup, force): msg = "Backup is skipped per backup.min_interval config option." diff --git a/ch_backup/clickhouse/client.py b/ch_backup/clickhouse/client.py index 1ff865e9..7de1c042 100644 --- a/ch_backup/clickhouse/client.py +++ b/ch_backup/clickhouse/client.py @@ -37,7 +37,7 @@ def settings(self): """ return self._session.params - @retry(requests.exceptions.ConnectionError) + @retry((requests.exceptions.ConnectionError, ClickhouseError)) def query( self, query: str,