Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/skip zero retention #141

Merged
merged 19 commits into from
Oct 4, 2022
Merged

Conversation

tarunmenon95
Copy link
Contributor

@tarunmenon95 tarunmenon95 commented Aug 31, 2022

Added feature to skip creating backups for those with retention types (daily,weekly,monthly,yearly) that are set to 0 in the configuration variables.

Workflow

  1. We call the function 'verify_retention' to that verifies the retention type for the current backup resource (Based on date of creation) against the specifed value in the config
if not self._verify_retention(backup_resource=backup_resource):
  1. We check whether the retention value is set to '0' in the config
CREATE_DAILY = RuntimeConfig.get_keep_daily(backup_resource.entity_resource_tags(),self) != 0
  1. A dict of all retention types and their corresponding boolean on whether we should create them or not is created.
retention = {
            backup_resource.RETENTION_DAILY : CREATE_DAILY,
            backup_resource.RETENTION_WEEKLY : CREATE_WEEKLY,
            backup_resource.RETENTION_MONTHLY : CREATE_MONTHLY,
            backup_resource.RETENTION_YEARLY : CREATE_YEARLY,
        }
  1. We then return True/False depending on if the supplied retention value is True/False in the dictionary
return True if retention[retention_value] else False 
  1. Lastly in the engine, we call this function and skip any iterations where the retention type is set to '0'
if not self._verify_retention(backup_resource=backup_resource):
                self.logger.info(f"Skipping backup as retention type {backup_resource.retention_type} is disabled")
                continue

EC2AMI 'Daily'Example

  1. The current date is 31-Aug-2022, as such we expect that the retention type for the created backup will be 'daily'

  2. For a given ec2 instance, we can observe the following specified config defines that the 'daily' retention is set to 0.

Screen Shot 2022-08-31 at 11 00 34 am

  1. We call 'shelvery ec2ami create_backups' and can observe the creation of the backup is skipped.

Screen Shot 2022-08-31 at 11 01 59 am

  1. Lastly, if we change the value from '0' to '1' in the config then call 'shelvery ec2ami create_backups' again we observe that the backup is created as expected.

Screen Shot 2022-08-31 at 11 03 29 am

@tarunmenon95
Copy link
Contributor Author

tarunmenon95 commented Sep 14, 2022

Added the logic to automatically go to the next retention type in the precedence order when the current one is disabled. If the final retention type in the order is disabled (daily) then the backup is skipped.

Examples

  • For the purposes of the following examples, the retention type has been hardcoded to force yearly backups.

Screen Shot 2022-09-14 at 4 09 38 pm

Yearly Backup (Yearly, Monthly, Weekly disabled)

  • Observed in the below screenshot, we can see that yearly, monthly and weekly backups have all been disabled.

Screen Shot 2022-09-14 at 4 08 13 pm

- We call 'shelvery ec2ami create_backups' to create the backups for the above instance - Shelvery now checks whether the current retention type is enabled, if not it will move on to the next retention type from Yearly -> Monthly -> Weekly -> Daily. Below we observe that Shelvery detected that yearly, monthly, weekly were all disabled and as such after checking all retention types in order, chose daily as it was allowed.

Screen Shot 2022-09-14 at 4 11 18 pm

Skip Backup (All Disabled)

  • Here we observe that all retention types are disabled

Screen Shot 2022-09-14 at 4 15 58 pm

- When we attempt to create backups, we observe that no backups are created at all as they we're all disabled. When daily is detected as disabled, shelvery will now skip the iteration for that backup_resource.

Screen Shot 2022-09-14 at 4 16 22 pm

@tarunmenon95
Copy link
Contributor Author

Changes

  • Added refactor changes to retention type check function
  • Added debugging logs

Examples

  • For the purposes of the following examples, the retention type has been hardcoded to force yearly backups.
    Screen Shot 2022-09-14 at 4 09 38 pm

Daily Backup (Yearly, Monthly, Weekly disabled, Daily Enabled)

  • We observe in the tags the yearly, monthly and weekly retention periods are disabled (Set to 0), only daily is enabled.
    Screen Shot 2022-10-04 at 12 28 32 pm
  • We call 'shelvery ec2ami create_backups' which initially detects the retention type as yearly as defined above. It then correctly detects yearly, monthly and weekly as being disabled and finally creates a daily backup as it was the only option enabled.
    Screen Shot 2022-10-04 at 12 37 31 pm

All Disabled

  • We observe that all retention types have been set to 0 thus are all disabled.
    Screen Shot 2022-10-04 at 12 39 17 pm
  • When we create backups this time we see that shelvery detects that no retention types are enabled as such skips creating a backup for this resource.
    Screen Shot 2022-10-04 at 12 41 00 pm

Custom Retention Type (quarterHourly)

  • Here we create a custom retention type by setting "quarterHourly" as an environment variable.
    Screen Shot 2022-10-04 at 12 43 13 pm
  • When we call create_backups, we obseve that shelvery detects a custom retention type is being used and skips the validation on the retention type and proceeds directly to creating the backup.
    Screen Shot 2022-10-04 at 12 45 14 pm
  • Observe that the backup is created as expected with custom retention type.
    Screen Shot 2022-10-04 at 12 45 58 pm

Copy link
Contributor

@Guslington Guslington left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Guslington Guslington merged commit 808c6de into develop Oct 4, 2022
@tarunmenon95 tarunmenon95 deleted the feature/skip-zero-retention branch July 11, 2024 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

don't take backup when retention is set to 0 and fall back to next backup type
2 participants