Skip to content

Commit

Permalink
chore: don't trust query settings, inline manually
Browse files Browse the repository at this point in the history
  • Loading branch information
fuziontech committed Sep 21, 2023
1 parent 5811b3f commit 120628e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions housewatch/clickhouse/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ def execute_backup_on_shards(
nodes = get_node_per_shard(cluster)
responses = []
for shard, node in nodes:
loop_query = query
params["shard"] = shard
if base_backup:
query_settings["base_backup"] = f"S3('{base_backup}/{shard}', '{aws_key}', '{aws_secret}')"
final_query = query % (params or {}) if substitute_params else query
loop_query = query + "\nS3('%(base_backup)s/%(shard)s', '%(aws_key)s', '%(aws_secret)s')"
params["base_backup"] = base_backup
final_query = loop_query % (params or {}) if substitute_params else loop_query
client = Client(
host=node["host_address"],
database=settings.CLICKHOUSE_DATABASE,
Expand Down Expand Up @@ -132,7 +134,6 @@ def create_database_backup(database, bucket, path, cluster=None, aws_key=None, a
QUERY = """BACKUP DATABASE %(database)s
TO S3('https://%(bucket)s.s3.amazonaws.com/%(path)s/%(shard)s', '%(aws_key)s', '%(aws_secret)s')
ASYNC"""

return execute_backup_on_shards(
QUERY,
{
Expand All @@ -152,7 +153,7 @@ def create_database_backup(database, bucket, path, cluster=None, aws_key=None, a
TO S3('https://%(bucket)s.s3.amazonaws.com/%(path)s', '%(aws_key)s', '%(aws_secret)s')
ASYNC"""
if base_backup:
query_settings["base_backup"] = f"S3('{base_backup}', '{aws_key}', '{aws_secret}')"
QUERY = QUERY + "\nS3('%(base_backup)s', '%(aws_key)s', '%(aws_secret)s')"
return run_query(
QUERY,
{
Expand All @@ -161,6 +162,7 @@ def create_database_backup(database, bucket, path, cluster=None, aws_key=None, a
"path": path,
"aws_key": aws_key,
"aws_secret": aws_secret,
"base_backup": base_backup,
},
query_settings=query_settings,
use_cache=False,
Expand Down

0 comments on commit 120628e

Please sign in to comment.