# CDK Backup Plan


Provides an easy to use reusable CDK construct to create [Backup Plans](https://docs.aws.amazon.com/aws-backup/latest/devguide/about-backup-plans.html) using [AWS Backups](https://docs.aws.amazon.com/aws-backup/latest/devguide/whatisbackup.html). It allows to indicate how frequently and what resources to backup.
> **NOTE:** More details on all the available arguments can be found [here](API.md)
## Install
NPM install:
```sh
npm install cdk-backup-plan
```
PyPi install:
```sh
pip install cdk-backup-plan
```
## Usage
```typescript
// ...
import { Backup } from "cdk-backup-plan";
// ...
const vpc = new ec2.Vpc(stack, "TestVPC");
const engine = rds.DatabaseInstanceEngine.postgres({
version: rds.PostgresEngineVersion.VER_12_3,
});
// create rds DB
const db = new rds.DatabaseInstance(stack, "TestInstance", {
engine,
vpc,
credentials: rds.Credentials.fromGeneratedSecret("postgres"),
});
// create a backup plan for `db`
new Backup(stack, "TestBk", {
backupPlanName: "TestPkPlan",
backupRateHour: 3, // backup every 3 hours
backupCompletionWindow: cdk.Duration.hours(2), // backup should take up to 2 hours
resources: [bk.BackupResource.fromRdsDatabaseInstance(db)],
});
// ...
```
Python usage:
```python
# ...
from cdk_backup_plan import Backup
# ...
vpc = ec2.Vpc(self, "TestVPC")
engine = rds.DatabaseInstanceEngine.postgres(
version=rds.PostgresEngineVersion.VER_12_3,
)
db = rds.DatabaseInstance(self, "TestInstance",
engine=engine,
vpc=vpc,
credentials=rds.Credentials.from_generated_secret("postgres"),
)
Backup(self, "TestBk",
backup_plan_name="TestPkPlan",
backup_rate_hour=3,
backup_completion_window=Duration.hours(2),
resources=[bk.BackupResource.from_rds_database_instance(db)],
)
# ...
```
> **NOTE:** [Tagging](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_backup.BackupResource.html#static-fromwbrtagkey-value-operation) and/or [ARN](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_backup.BackupResource.html#static-fromwbrarnarn) can be used to reference resources not directly available in the [static methods section](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_backup.BackupResource.html#methods).
# API Reference
## Constructs
### Backup
Construct to create a Backup Plan with specific backing cadence.
#### Initializers
```typescript
import { Backup } from 'cdk-backup-plan'
new Backup(scope: Construct, id: string, props: BackupProps)
```
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| scope
| constructs.Construct
| Construct's scope. |
| id
| string
| Construct's id. |
| props
| BackupProps
| Construct's props. |
---
##### `scope`Required
- *Type:* constructs.Construct
Construct's scope.
---
##### `id`Required
- *Type:* string
Construct's id.
---
##### `props`Required
- *Type:* BackupProps
Construct's props.
---
#### Methods
| **Name** | **Description** |
| --- | --- |
| toString
| Returns a string representation of this construct. |
---
##### `toString`
```typescript
public toString(): string
```
Returns a string representation of this construct.
#### Static Functions
| **Name** | **Description** |
| --- | --- |
| isConstruct
| Checks if `x` is a construct. |
---
##### ~~`isConstruct`~~
```typescript
import { Backup } from 'cdk-backup-plan'
Backup.isConstruct(x: any)
```
Checks if `x` is a construct.
###### `x`Required
- *Type:* any
Any object.
---
#### Properties
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| node
| constructs.Node
| The tree node. |
| backupPlan
| aws-cdk-lib.aws_backup.BackupPlan
| Backup plan. |
---
##### `node`Required
```typescript
public readonly node: Node;
```
- *Type:* constructs.Node
The tree node.
---
##### `backupPlan`Required
```typescript
public readonly backupPlan: BackupPlan;
```
- *Type:* aws-cdk-lib.aws_backup.BackupPlan
Backup plan.
---
## Structs
### BackupProps
#### Initializer
```typescript
import { BackupProps } from 'cdk-backup-plan'
const backupProps: BackupProps = { ... }
```
#### Properties
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| backupPlanName
| string
| The display name of the backup plan. |
| resources
| aws-cdk-lib.aws_backup.BackupResource[]
| Resources to apply backup plan. |
| backupCompletionWindow
| aws-cdk-lib.Duration
| The duration after a backup job is successfully started before it must be completed or it is canceled by AWS Backup. |
| backupRateHour
| number
| How frequently backup jobs would be started. |
| backupStartWindow
| aws-cdk-lib.Duration
| The duration after a backup is scheduled before a job is canceled if it doesn't start successfully. |
| deleteBackupAfter
| aws-cdk-lib.Duration
| Specifies the duration after creation that a recovery point is deleted. |
| moveBackupToColdStorageAfter
| aws-cdk-lib.Duration
| Specifies the duration after creation that a recovery point is moved to cold storage. |
---
##### `backupPlanName`Required
```typescript
public readonly backupPlanName: string;
```
- *Type:* string
The display name of the backup plan.
---
##### `resources`Required
```typescript
public readonly resources: BackupResource[];
```
- *Type:* aws-cdk-lib.aws_backup.BackupResource[]
Resources to apply backup plan.
---
##### `backupCompletionWindow`Optional
```typescript
public readonly backupCompletionWindow: Duration;
```
- *Type:* aws-cdk-lib.Duration
- *Default:* 3 hours
The duration after a backup job is successfully started before it must be completed or it is canceled by AWS Backup.
Note: `backupCompletionWindow` must be at least 60 minutes greater
than @backupStartWindows
---
##### `backupRateHour`Optional
```typescript
public readonly backupRateHour: number;
```
- *Type:* number
- *Default:* 24 hours
How frequently backup jobs would be started.
---
##### `backupStartWindow`Optional
```typescript
public readonly backupStartWindow: Duration;
```
- *Type:* aws-cdk-lib.Duration
- *Default:* 1 hour less than
The duration after a backup is scheduled before a job is canceled if it doesn't start successfully.
---
##### `deleteBackupAfter`Optional
```typescript
public readonly deleteBackupAfter: Duration;
```
- *Type:* aws-cdk-lib.Duration
- *Default:* 30 days
Specifies the duration after creation that a recovery point is deleted.
Must be greater than moveToColdStorageAfter.
---
##### `moveBackupToColdStorageAfter`Optional
```typescript
public readonly moveBackupToColdStorageAfter: Duration;
```
- *Type:* aws-cdk-lib.Duration
- *Default:* recovery point is never moved to cold storage
Specifies the duration after creation that a recovery point is moved to cold storage.
---