AndrewFarley/AWS-Automated-Daily-Instance-AMI-Snapshots

Feature request for multiple backup cycles

opswm opened this issue · 3 comments

opswm commented

Hello, is there any good way to implement the functions of multiple backup cycles?
For example, the first cycle is daily backup, and the expired AMI is deleted every week.
The second cycle is weekly backup, deleting expired AMIs every month.
The third cycle is monthly backup, deleting expired AMIs every year.
Looking forward to your reply.

@ChampionWolf This can already do what you ask for with the features that are already built in. You will need to do the following...

First, you'll need to deploy this same stack 3 different times, one for each "cycle". To do this, change the second line in serverless.yml to be the name of each cycle... eg:

# Change this...
service: daily-instance-snapshot
# To maybe one of these three (different for each stack)
service: daily-backup-week-expired
service: weekly-backup-month-expired
service: monthly-backup-year-expired

Second, you'll need to adjust how often this script runs. There's a (README hint here)[https://github.com/AndrewFarley/AWS-Automated-Daily-Instance-AMI-Snapshots#scheduling-backups-at-specific-start-times] that tells you how you can make this run however/whenever you'd like. This uses a cron type format (see the link for info). For the daily one you don't need to change this, but for the weekly/monthly one you will need to change this to the right cron format for a weekly or monthly cron job. If you can't figure this out, ask I can help further.

Third, on the weekly/monthly stacks, you will need to change the DEFAULT_RETENTION_TIME of the deployed lambda to be 31 on the weekly-backup-month-expired stack, and 365 on the monthly-backup-year-expired task.

That should do it! :) No changes (from my side) needed to support your usage pattern, just deploy it three different times with different settings for each. Cheers, and enjoy!

I will add a tutorial to the main README on how to do this, so others can enjoy it. I'll close this issue when I do so. :)

Enjoy, there's a working example, with copy/paste instructions. :) Enjoy @ChampionWolf you should be able to understand and modify the example to create a third stack to do the monthly/expire after a year feature you desire.