# Set up AWS Backup

This guide shows you how to configure AWS Backup to schedule daily backups of AWS resources including databases and S3 buckets.

<!-- prettier-ignore-start -->
!!! Warning
    As part of this series of guides you create a AWS Backup vault and enable [**Compliance mode**](https://docs.aws.amazon.com/aws-backup/latest/devguide/vault-lock.html#backup-vault-lock-modes). When **Compliance mode** is enabled, any backups created cannot be deleted by any user including the root user.
<!-- prettier-ignore-end -->

## Step 1: Add and configure the `backup` package

<!-- prettier-ignore-start -->
!!! info "Assumption"
    This step assumes you are already using Boilerplate and have a `common-config.yml`.
    If you do not, have a look here for an [example](https://github.com/oslokommune/pirates-iac/blob/main/stacks/dev/common-config.yml)
<!-- prettier-ignore-end -->

```sh title="repo-iac/environments/dev/"
ok pkg add backup
```

Edit `package-config.yml` to disable the slack notifications (you set this up later):

```yaml title="repo-iac/environments/dev/backup/package-config.yml"
StackName: "backup"

NotifySlack:
  Enable: false
```

<!-- prettier-ignore-start -->
!!! Warning
    In `config_override.tf`, it's possible to set the variable `changeable_for_days`.

    If or when you set `changeable_for_days`, you will **NOT be able to delete the backup** after `changeable_for_days` days. This ensures that intruders cannot delete your backups.
<!-- prettier-ignore-end -->

## Step 2: Install the package

```bash title="repo-iac/environments/dev/backup/"
ok pkg install
```

## Step 3: Initialize and apply the `backup` stack

Initialize Terraform and apply the configuration:

```bash title="repo-iac/environments/dev/backup/"
terraform init
terraform apply
```

## Step 4: Verify

- Go to **AWS console** > **AWS Backup** > **Backup plans**
- Verify that you have a backup plan with the name of your environment
- Go to the backup plan
- Verify that it contains two scheduled backup rules: Daily and monthly

## Next step

Set up [Datadog](set-up-datadog.md) to enable observability for your applications and infrastructure.
