Skip to content

Commit

Permalink
Check if backup name exists and add retry on ClickhouseError for quer…
Browse files Browse the repository at this point in the history
…ies (#173)

* Check if backup with given name already exists

* Add retry for query on ClickhouseError
  • Loading branch information
kirillgarbar authored Jul 22, 2024
1 parent 23e9954 commit 44b84c2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions ch_backup/ch_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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."
Expand Down
2 changes: 1 addition & 1 deletion ch_backup/clickhouse/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 44b84c2

Please sign in to comment.