This page describes how to configure the system so that you will receive alerts
when Backup for GKE backups fail.

You can create backups in two different ways:

- By [manually creating](https://docs.cloud.google.com/kubernetes-engine/docs/add-on/backup-for-gke/how-to/backup.md.txt#manual) a `Backup` resource.
- By configuring a schedule when [creating your `BackupPlan` resource](https://docs.cloud.google.com/kubernetes-engine/docs/add-on/backup-for-gke/how-to/backup-plan.md.txt#create_a_backup_plan).

As a best practice, create backups using automatic scheduling. However, it can
be challenging to keep track of the status for these automatically created
backups. You have two choices:

- Periodically [view](https://docs.cloud.google.com/kubernetes-engine/docs/add-on/backup-for-gke/how-to/backup.md.txt#view_a_backup) the list of `Backup` resources, looking for newly failed backups.
- Set up an alert to notify you when backup execution fails.

This page describes how to configure an alert policy based on [log events emitted by Backup for GKE](https://docs.cloud.google.com/kubernetes-engine/docs/add-on/backup-for-gke/how-to/platform-logging-backup-for-gke.md.txt) and viewable from the
[Logs Explorer](https://docs.cloud.google.com/logging/docs/view/logs-explorer-interface.md.txt).

## Before you begin

Before setting up an alert policy, ensure you have an
appropriate [notification channel](https://docs.cloud.google.com/monitoring/support/notification-options.md.txt).

## Create an alert

To create general log-based alert policies, see [Configure log-based alerts](https://docs.cloud.google.com/logging/docs/alerting/log-based-alerts.md.txt).
Or, to create an alert policy specifically for Backup for GKE failed backups:

1. Go to the Logs Explorer page

   [Go to Logs Explorer](https://console.cloud.google.com/logs/query)
2. Enter the following filter criteria in the **Query** pane:

       logName="projects/PROJECT_ID/logs/gkebackup.googleapis.com%2Fbackup_change"
       resource.type="gkebackup.googleapis.com/BackupPlan"
       resource.labels.backup_plan_id="BACKUP_PLAN"
       resource.labels.location="LOCATION"
       jsonPayload.changeType="UPDATE"
       jsonPayload.inputBackup.state="FAILED"

   Replace the following:
   - `PROJECT_ID`: the ID of your Google Cloud project.
   - `LOCATION`: the [compute region](https://docs.cloud.google.com/compute/docs/regions-zones.md.txt#available) of the backup plan for which you want to generate alerts.
   - `BACKUP_PLAN`: the name of the backup plan for which you want to generate alerts.

   > [!NOTE]
   > **Note:** This creates an alert policy for any failed backups of a specific backup plan. If you want to create a single policy for all failed backups, omit the `resource.labels.backup_plan_id` and `resource.labels.location` fields.

3. In the **Query results** pane, click **Actions** , and then select
   **Create log alert**.

   ![](https://docs.cloud.google.com/static/kubernetes-engine/docs/add-on/backup-for-gke/images/create-log-alert.png)
4. Enter a meaningful name for your alert policy and any documentation you
   want to make available to recipients of alerts.

5. Click **Next** twice.

6. Set the appropriate notification frequency and autoclose duration. We
   suggest `5 min` and `7 days`.

7. Click **Next**.

8. Select the appropriate notification channels and save your alert
   policy.

After you save the policy, you receive alerts to your notification channels when
a backup matching your filter fails.