Skip to content

Commit

Permalink
Add backup schedule lifecycle rules
Browse files Browse the repository at this point in the history
Update aws-sdk gem versions to fix malformedXML error
  • Loading branch information
BasilMawejje committed Oct 27, 2021
1 parent 4a04d4f commit 20ba3f6
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 19 deletions.
18 changes: 9 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ GEM
ast (2.4.1)
autoprefixer-rails (10.0.1.0)
execjs
aws-eventstream (1.1.0)
aws-partitions (1.381.0)
aws-sdk-core (3.109.1)
aws-eventstream (1.2.0)
aws-partitions (1.519.0)
aws-sdk-core (3.121.3)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.239.0)
aws-sigv4 (~> 1.1)
jmespath (~> 1.0)
aws-sdk-kms (1.39.0)
aws-sdk-core (~> 3, >= 3.109.0)
aws-sdk-kms (1.50.0)
aws-sdk-core (~> 3, >= 3.121.2)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.83.0)
aws-sdk-core (~> 3, >= 3.109.0)
aws-sdk-s3 (1.104.0)
aws-sdk-core (~> 3, >= 3.121.2)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.1)
aws-sigv4 (1.2.2)
aws-sigv4 (~> 1.4)
aws-sigv4 (1.4.0)
aws-eventstream (~> 1, >= 1.0.2)
bcrypt (3.1.16)
better_errors (2.8.3)
Expand Down
68 changes: 58 additions & 10 deletions lib/tasks/shf_aws.rake
Original file line number Diff line number Diff line change
Expand Up @@ -136,31 +136,79 @@ namespace :shf do
# This simplifies our rake task syntax in the terminal.
aws_s3 = Backup.s3_backup_resource
aws_client = aws_s3.client
aws_s3_backup_bucket_name = "shf-test-backups" # Remember to revert to production bucket
aws_s3_backup_bucket_name = Backup.s3_backup_bucket # Remember to revert to production bucket
aws_s3_backup_bucket_full_prefix = Backup.s3_backup_bucket_full_prefix

storage_rules = [{days: 90, storage_class: 'GLACIER'}, {days: 450, storage_class: 'DEEP_ARCHIVE'}]
# year = (aws_s3_backup_bucket_full_prefix.split('/')[1]
# current_month = aws_s3_backup_bucket_full_prefix.split('/')[2]
# prev_month = (aws_s3_backup_bucket_full_prefix.split('/')[2].to_i - 1).to_s
# day = (aws_s3_backup_bucket_full_prefix.split('/')[3]
# binding.pry

ActivityLogger.open(LogfileNamer.name_for(LOGFILENAME), LOG_FACILITY, 'Add bucket lifecycle configuration') do |log|
aws_client.put_bucket_lifecycle_configuration({
bucket: aws_s3_backup_bucket_name,
lifecycle_configuration: {
rules: [
{
filter: {
prefix: aws_s3_backup_bucket_full_prefix,
},
id: 'Daily backup schedule',
status: 'Enabled',
transitions: [
{
days: 60,
storage_class: 'STANDARD_IA',
},
],
},
{
expiration: {
days: 366,
},
id: 'Monthly backup schedule',
filter: {
tag: {
key: 'date-month-day',
value: '1'
}
},
status: 'Enabled',
transitions: [
{
days: 90,
storage_class: 'GLACIER',
}
]
},
{
expiration: {
days: 3650
},
id: "Transition objects to GLACIER after 90 days then move them to DEEP_ARCHIVE after 450 days",
id: 'Yearly backup schedule',
filter: {
prefix: aws_s3_backup_bucket_full_prefix
and: {
tags: [
{
key: 'date-month-day',
value: '1'
},
{
key: 'date-month-num',
value: '1'
},
],
},
},
status: 'Enabled',
transitions: storage_rules,
abort_incomplete_multipart_upload: {
days_after_initiation: 10 # Remember to change this based on PR reply.
}
transitions: [
{
days: 366,
storage_class: 'DEEP_ARCHIVE'
}
]
}
]
],
}
})

Expand Down

0 comments on commit 20ba3f6

Please sign in to comment.