diff --git a/README.md b/README.md index 3647921..901625c 100644 --- a/README.md +++ b/README.md @@ -119,14 +119,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 diff --git a/docs/images/bbq_retention_process_7_months.gif b/docs/images/bbq_retention_process_7_months.gif index 5c0f085..4d92010 100644 Binary files a/docs/images/bbq_retention_process_7_months.gif and b/docs/images/bbq_retention_process_7_months.gif differ diff --git a/tests/retention/policy/test_retention_policy.py b/tests/retention/policy/test_retention_policy.py index e61f451..3a6f3ae 100644 --- a/tests/retention/policy/test_retention_policy.py +++ b/tests/retention/policy/test_retention_policy.py @@ -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