Skip to content

Instantly share code, notes, and snippets.

@MatthewJDavis
Last active April 8, 2019 14:30
Show Gist options
  • Select an option

  • Save MatthewJDavis/3a56103be8bfd3bbd62c799625fd79c2 to your computer and use it in GitHub Desktop.

Select an option

Save MatthewJDavis/3a56103be8bfd3bbd62c799625fd79c2 to your computer and use it in GitHub Desktop.
Create lifecycle and rules then create an AWS backup plan
# Create backup lifecycle, tags and plan
$BackupLifeCycle = New-Object -TypeName Amazon.Backup.Model.Lifecycle
$BackupLifeCycle.DeleteAfterDays = 7
# $BackupLifeCycle.MoveToColdStorageAfterDays = Commented out so no cold storage. Uncomment and assign a value if cold storage is required
# Create the tags to be applied to items created by this backup plan
$RecoveryTags = New-Object -TypeName 'system.collections.generic.dictionary[string,string]'
$RecoveryTags.Add('created:by:aws:backup:plan', '4-AM-7-Day-Retention')
# Create the backup plan
$BackupRule = New-Object -TypeName Amazon.Backup.Model.BackupRuleInput
$BackupRule.Lifecycle = $BackupLifeCycle
$BackupRule.StartWindowMinutes = 60
$BackupRule.TargetBackupVaultName = $VaultName
$BackupRule.RecoveryPointTags = $RecoveryTags
$BackupRule.RuleName = '4-AM-7-Day-Retention'
$BackupRule.ScheduleExpression = 'cron(0 4 * * ? *)' # https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html
New-BAKBackupPlan -BackupPlan_BackupPlanName '4-AM-7-Day-Retention' -BackupPlan_Rule $BackupRule -BackupPlanTag $ProjectTag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment