|
| 1 | +# Terraform — Long-Term Backup Scheduling and Retention Policy |
| 2 | + |
| 3 | +Configures automatic backup retention and a long-term backup schedule on an existing Autonomous Database. Designed for compliance scenarios where data must be retained beyond the 60-day automatic backup limit. |
| 4 | + |
| 5 | +## Files |
| 6 | + |
| 7 | +| File | Description | |
| 8 | +|---|---| |
| 9 | +| `versions.tf` | Terraform and provider version requirements | |
| 10 | +| `provider.tf` | OCI provider configuration | |
| 11 | +| `main.tf` | Automatic backup retention and long-term backup schedule | |
| 12 | +| `variables.tf` | All configurable parameters | |
| 13 | +| `outputs.tf` | Values exported after apply | |
| 14 | +| `terraform.tfvars` | Fill in your values | |
| 15 | + |
| 16 | +## Quick Start |
| 17 | + |
| 18 | +```bash |
| 19 | +# 1. Initialize Terraform |
| 20 | +terraform init |
| 21 | + |
| 22 | +# 2. Import the existing ADB into the Terraform state |
| 23 | +terraform import oci_database_autonomous_database.adb <ADB_OCID> |
| 24 | + |
| 25 | +# 3. Review the plan — the ADB should show only backup-related changes |
| 26 | +terraform plan |
| 27 | + |
| 28 | +# 4. Apply |
| 29 | +terraform apply |
| 30 | +``` |
| 31 | + |
| 32 | +## Backup Architecture |
| 33 | + |
| 34 | +``` |
| 35 | +Existing Autonomous Database |
| 36 | +├── Automatic backups (daily, managed by OCI) |
| 37 | +│ └── Retained for backup_retention_days (1–60 days) |
| 38 | +│ |
| 39 | +└── Long-term backup schedule (managed by OCI natively) |
| 40 | + ├── Cadence: ONE_TIME | WEEKLY | MONTHLY | YEARLY |
| 41 | + ├── Anchor: backup_schedule_time (RFC3339) |
| 42 | + └── Retained for long_term_backup_retention_days (90–3650 days) |
| 43 | +``` |
| 44 | + |
| 45 | +## Schedule Reference |
| 46 | + |
| 47 | +| Cadence | Behavior | |
| 48 | +|---|---| |
| 49 | +| `ONE_TIME` | Single backup taken at `backup_schedule_time` | |
| 50 | +| `WEEKLY` | Repeats every 7 days at the same time and day of week | |
| 51 | +| `MONTHLY` | Repeats on the same day each month (last day if >= 29) | |
| 52 | +| `YEARLY` | Repeats on the same date each year | |
| 53 | + |
| 54 | +## Retention Reference |
| 55 | + |
| 56 | +| Period | Days | |
| 57 | +|---|---| |
| 58 | +| 3 months (minimum) | 90 | |
| 59 | +| 1 year | 365 | |
| 60 | +| 2 years | 730 | |
| 61 | +| 5 years | 1825 | |
| 62 | +| 7 years | 2555 | |
| 63 | +| 10 years (maximum) | 3650 | |
| 64 | + |
| 65 | +## Variables |
| 66 | + |
| 67 | +| Variable | Description | Default | |
| 68 | +|---|---|---| |
| 69 | +| `tenancy_ocid` | OCID of the OCI tenancy | — | |
| 70 | +| `user_ocid` | OCID of the OCI user | — | |
| 71 | +| `fingerprint` | Fingerprint of the API key | — | |
| 72 | +| `private_key_path` | Path to the private key file (.pem) | — | |
| 73 | +| `region` | OCI region where the ADB resides | `us-ashburn-1` | |
| 74 | +| `compartment_ocid` | OCID of the compartment where the ADB resides | — | |
| 75 | +| `adb_ocid` | OCID of the existing Autonomous Database | — | |
| 76 | +| `adb_db_name` | Technical database name (must match exactly) | — | |
| 77 | +| `adb_admin_password` | ADMIN password (required by provider, not modified) | — | |
| 78 | +| `backup_retention_days` | Automatic daily backup retention in days (1–60) | `30` | |
| 79 | +| `backup_schedule_cadence` | Backup frequency: `ONE_TIME`, `WEEKLY`, `MONTHLY`, `YEARLY` | `MONTHLY` | |
| 80 | +| `backup_schedule_time` | RFC3339 anchor timestamp for the schedule | — | |
| 81 | +| `long_term_backup_retention_days` | Long-term backup retention in days (90–3650) | `365` | |
| 82 | + |
| 83 | +## Outputs |
| 84 | + |
| 85 | +| Output | Description | |
| 86 | +|---|---| |
| 87 | +| `adb_id` | OCID of the Autonomous Database | |
| 88 | +| `backup_retention_days` | Automatic backup retention period in days | |
| 89 | +| `backup_schedule_cadence` | Frequency of the long-term backup schedule | |
| 90 | +| `backup_schedule_time` | Anchor timestamp for the long-term backup schedule | |
| 91 | +| `long_term_backup_retention_days` | Long-term backup retention period in days | |
| 92 | + |
| 93 | +## Notes |
| 94 | + |
| 95 | +- **Existing ADB required:** This Terraform is designed for existing databases only. Import the ADB before running `terraform apply` — see Quick Start above. |
| 96 | + |
| 97 | +- **Automatic backup prerequisite:** OCI requires at least one automatic backup to exist before the long-term backup schedule activates. After provisioning a new ADB, wait up to 4 hours for the first automatic backup to complete. |
| 98 | + |
| 99 | +- **`backup_schedule_time` format:** Must be a valid RFC3339 timestamp in UTC. Example: `2025-06-01T02:00:00Z`. This timestamp serves as both the first backup date and the anchor point for the recurring schedule. |
| 100 | + |
| 101 | +- **MONTHLY cadence edge case:** If `backup_schedule_time` falls on day 29, 30, or 31, OCI takes the backup on the last day of months with fewer days. |
| 102 | + |
| 103 | +- **`admin_password` in tfvars:** Required by the OCI provider schema but listed in `ignore_changes`. Terraform will never use it to modify the database password. |
| 104 | + |
| 105 | +- **Automatic backup limit:** OCI automatic backups support a maximum of 60 days. For retention beyond 60 days, the long-term backup schedule is required. |
| 106 | + |
| 107 | +- **Storage costs:** Long-term backups incur additional Object Storage costs beyond the standard ADB storage bill. |
| 108 | + |
| 109 | +- **Restore from long-term backup:** Long-term backups can only be used to clone a new database, not to restore in-place. Go to your ADB in the OCI console → Backups → select the long-term backup → click Clone. |
0 commit comments