Skip to content

Commit

Permalink
Latest backup in any state should not be deleted while partial delete…
Browse files Browse the repository at this point in the history
… command
  • Loading branch information
MedvedewEM committed Aug 22, 2023
1 parent 0075a7d commit aa0fe2d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ch_backup/ch_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,15 @@ def delete(
found = False
deleting_backups = []
retained_backups = []
for backup in self._context.backup_layout.get_backups(use_light_meta=True):
for i, backup in enumerate(
self._context.backup_layout.get_backups(use_light_meta=True)
):
if backup.name == backup_name:
deleting_backups.append(backup)
found = True
continue

if purge_partial and backup.state != BackupState.CREATED:
if purge_partial and backup.state != BackupState.CREATED and i != 0:
deleting_backups.append(backup)
else:
retained_backups.append(backup)
Expand Down
42 changes: 42 additions & 0 deletions tests/integration/features/backup_delete.feature
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,48 @@ Feature: Backup & Clean & Restore
| num | state | data_count | link_count | title |
And s3 contains 0 objects

Scenario: Attempt to delete backup with purge partially does not delete latest creating backup
When we create clickhouse01 clickhouse backup
"""
schema_only: True
"""
When we create clickhouse01 clickhouse backup
"""
schema_only: True
"""
When we create clickhouse01 clickhouse backup
"""
schema_only: True
"""
And metadata of clickhouse01 backup #0 was adjusted with
"""
meta:
state: creating
"""
And metadata of clickhouse01 backup #1 was adjusted with
"""
meta:
state: failed
"""
Then we got the following backups on clickhouse01
| num | state | data_count | link_count | title |
| 0 | creating | 0 | 0 | schema-only |
| 1 | failed | 0 | 0 | schema-only |
| 2 | created | 0 | 0 | schema-only |
When we delete clickhouse01 clickhouse backup #2
"""
purge_partial: true
"""
Then we got the following backups on clickhouse01
| num | state | data_count | link_count | title |
| 0 | creating | 0 | 0 | schema-only |
When we delete clickhouse01 clickhouse backup #0
"""
purge_partial: true
"""
Then we got the following backups on clickhouse01
| num | state | data_count | link_count | title |

Scenario: Attempt to delete non-existent backup with force flag succeeds
When we delete clickhouse01 clickhouse backup "non_existent_backup"
"""
Expand Down

0 comments on commit aa0fe2d

Please sign in to comment.