Skip to content
This repository has been archived by the owner on Aug 25, 2023. It is now read-only.

Commit

Permalink
YACHT-1256: Updating documentation - details about modified retention…
Browse files Browse the repository at this point in the history
… policy. Gif also updated.

Adding unit test for situation when there is an old backup, then is new change and new backup and then source table is deleted.
  • Loading branch information
radkomateusz committed Apr 17, 2019
1 parent d0eb381 commit 0e7fcd1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![Build Status](https://travis-ci.org/ocadotechnology/bbq.svg?branch=master)](https://travis-ci.org/ocadotechnology/bbq)
[![Build Status](https://travis-ci.org/ocadotechnology/bbq.svg?branch=master)](https://travis-ci.org/ocadotechnology/bbq)
[![Coverage Status](https://coveralls.io/repos/github/ocadotechnology/bbq/badge.svg?branch=master)](https://coveralls.io/github/ocadotechnology/bbq?branch=master)

# Backup Big Query (BBQ)
Expand Down Expand Up @@ -119,14 +120,13 @@ There's 10,000 [copy jobs per project per day limit](https://cloud.google.com/bi
Note that partitions are represented as individual tables in backup storage. If you try to restore dataset with 10 tables with 500 partitions each, it will require 5000 copy jobs which is half of your daily quota.
## Retention process

Every day retention process scans all backups to find and delete backups matching specific criteria within given source table/partition:
* if there are multiple backups per day, the most recent is retained. Multiple backups per day are created in rare cases (e.g. when task queue task is executed more than one time),
* if there are more than 10 backups for given table/partition, the 10 most recent are retained,
* if all backups are older than 7 months, then most recent is retained,
* if there are backups younger than 7 months, then all others are deleted,
* if source table is deleted, then the last backup is deleted after 7 months.
Every day retention process scans all backups to find and delete backups matching specific criteria for given source table/partition:
* if there are multiple backups per day, the most recent one is retained. Multiple backups per day are created in rare cases (e.g. when task queue task is executed more than one time),
* for backups younger than 7 months, the 10 most recent ones are retained,
* for backups older than 7 months, single most recent backup is retained,
* if source table is deleted, then the last backup is deleted after 7 months after deletion.

### Example of 10 versions retention
### Example of 10 versions retention for backups younger than 7 months
![Retention process](docs/images/bbq_retention_process_10_versions.gif)

### Example of 7 months old backup deletion and source deletion grace period
Expand Down
Binary file modified docs/images/bbq_retention_process_7_months.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions tests/retention/policy/test_retention_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,30 @@ def test_remove_all_backups_if_source_table_doesnt_exists_for_min_7_months(self,
eligible_for_deletion
)

@patch.object(BigQueryTableMetadata, 'table_exists', return_value=False)
@patch.object(BigQueryTableMetadata, 'get_table_by_reference', return_value=BigQueryTableMetadata(None))
@patch.object(Backup, 'get_table', return_value=Table(last_checked=datetime(2017, 8, 1)))
@freeze_time("2017-08-20")
def test_should_not_remove_any_backups_if_source_table_was_deleted_less_than_seven_months_ago(self, _, _1, _2): # nopep8 pylint: disable=C0301
# given
reference = TableReference('example-project-id', 'example-dataset-id',
'example-table-id')
young_backup = create_backup(datetime(2017, 8, 1))
old_backup = create_backup(datetime(2016, 1, 17))

backups = [young_backup, old_backup]
backups_expected_for_deletion = []

# when
eligible_for_deletion = self.under_test \
.get_backups_eligible_for_deletion(backups=list(backups),
table_reference=reference)
# then
self.sortAndAssertListEqual(
backups_expected_for_deletion,
eligible_for_deletion
)

@freeze_time("2017-08-20")
def test_should_remove_above_last_10_young_backups(self):
#given
Expand Down

0 comments on commit 0e7fcd1

Please sign in to comment.