Skip to content

Commit 6d16f9f

Browse files
committed
Add Azure Backup functionality for SAP HANA database restoration
1 parent a9bc910 commit 6d16f9f

21 files changed

Lines changed: 3614 additions & 1 deletion

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ In the SAP Testing Automation Framework, thorough validation of high availabilit
3131
- **Functional Testing:** The framework executes series of real-world scenarios based on the SAP HANA and SAP Central Services high availability setup to identify potential issues, whether during a new system deployment or before implementing cluster changes in a production environment. The test cases are based on what is documented in how-to guides for SAP HANA and SAP Central Services configuration.
3232
- **Offline configuration validation:** Offline validation is a mode of the framework that validates SAP HANA and SAP Central Services high availability cluster configurations without establishing a live SSH connection to the production cluster. Instead, it analyzes captured cluster information base (CIB) XML files exported from each cluster node.
3333

34+
### Azure Backup Testing
35+
36+
The framework validates Azure Backup operations for SAP HANA databases, covering the full backup-restore lifecycle. It supports both HA (two-node cluster) and non-HA (single-node) deployments.
37+
38+
- **Backup Setup Verification:** Discovers protected HANA databases in the Recovery Services vault, verifies backup configuration health, and checks that recent restore points exist.
39+
- **Restore Operations:** Tests restore-to-database (in-place and cross-VM) and restore-to-filesystem workflows via the Azure Backup Python SDK, monitoring restore jobs to completion.
40+
- **Database Recovery Validation:** Validates native HANA recovery using database commands (`RECOVER DATA`), and confirms the database is consistent and operational after each restore.
41+
3442
### Configuration Checks (Preview)
3543

3644
The framework performs comprehensive configuration checks to ensure that the SAP system and its components are set up according to [SAP on Azure best practice](https://learn.microsoft.com/azure/sap/). This includes validating infrastructure settings, operating system parameter configurations, and network settings, in addition to the cluster configuration, to identify any deviations that could impact system performance or reliability.
@@ -65,6 +73,7 @@ For users focused solely on validating SAP functionality and configurations, the
6573

6674
- Configure management server following the document [Setup Guide for SAP Testing Automation Framework](https://github.com/Azure/sap-automation-qa/blob/main/docs/SETUP.MD).
6775
- For high availability testing scenarios, see [High Availability documentation](./docs/HIGH_AVAILABILITY.md).
76+
- For Azure Backup testing scenarios, see [Azure Backup Testing documentation](./docs/AZURE_BACKUP.md).
6877
- For Configuration Checks and Testing details, see the [Configuration Checks documentation](./docs/CONFIGURATION_CHECKS.md).
6978

7079
### Option 2: Integration with SAP Deployment Automation Framework (SDAF)
@@ -81,6 +90,7 @@ For support and questions, please:
8190
## 📚 Additional Resources
8291

8392
- [Azure SAP Documentation](https://docs.microsoft.com/azure/sap)
93+
- [Azure Backup Testing Guide](./docs/AZURE_BACKUP.md)
8494
- [Configuration Checks Guide](./docs/CONFIGURATION_CHECKS.md)
8595
- [High Availability Testing Guide](./docs/HIGH_AVAILABILITY.md)
8696

WORKSPACES/SYSTEM/DEV-WEEU-SAP01-X00/sap-parameters.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,25 @@ user_assigned_identity_client_id: "00000000-0000-0000-0000-000000000000"
5050
#############################################################################
5151
ANF_account_rg: "ANF-RESOURCE-GROUP"
5252
ANF_account_name: "ANF-ACCOUNT-NAME"
53+
54+
#############################################################################
55+
# Azure Backup Parameters (optional) #
56+
# Required when SAP_FUNCTIONAL_TEST_TYPE is AzureBackupDatabase #
57+
#############################################################################
58+
59+
# Recovery Services vault resource ID (required)
60+
backup_vault_resource_id: "/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.RecoveryServices/vaults/<vault-name>"
61+
62+
# Protected item identifiers (required for restore test cases 2-5)
63+
backup_container_name: "VMAppContainer;Compute;<resource-group>;<vm-name>"
64+
backup_item_name: "saphanadatabase;<sid>;<database-name>"
65+
66+
# Filesystem restore target path (required for test case 3)
67+
backup_target_filesystem_path: "/hana/backup/restore"
68+
69+
# Cross-VM restore parameters (required for test case 5)
70+
backup_target_container_name: "VMAppContainer;Compute;<resource-group>;<target-vm-name>"
71+
backup_target_database_name: "SYSTEMDB"
72+
73+
# Point-in-time restore (ISO 8601 UTC, optional)
74+
backup_restore_point_time: ""

docs/AZURE_BACKUP.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Azure Backup Functional Testing for SAP HANA
2+
3+
The SAP Testing Automation Framework includes an Azure Backup testing component that validates backup and restore operations for SAP HANA databases deployed on Azure. It exercises the [Azure Backup for SAP HANA](https://learn.microsoft.com/azure/backup/sap-hana-database-about) service through the Python SDK (`azure-mgmt-recoveryservicesbackup`) and native HANA recovery commands.
4+
5+
## Supported Scenarios
6+
7+
The framework supports both **HA (two-node cluster)** and **Non-HA (single-node)** HANA deployments. Five test cases cover the end-to-end backup-restore lifecycle:
8+
9+
| # | Test Case | Task Name | Description |
10+
|---|-----------|-----------|-------------|
11+
| 1 | Azure Backup Setup Verification | `backup-setup-verification` | Discovers all protected HANA databases in the Recovery Services vault, verifies backup configuration health, and checks that recent restore points exist. |
12+
| 2 | Restore Backup to HANA DB | `restore-to-db` | Triggers a full or point-in-time restore to the original HANA database via Azure Backup, monitors the restore job, then validates HANA is running. |
13+
| 3 | Restore Backup to FileSystem | `restore-to-filesystem` | Restores the HANA backup as files to a filesystem path, verifies the files are present, then recovers the HANA DB from those files and validates it is operational. |
14+
| 4 | Recover DB using Database Commands | `recover-db-commands` | Tests native HANA recovery using `recoverSys.py` / `RECOVER DATA`. Queries the backup catalog, stops HANA, performs recovery, restarts, and validates consistency. |
15+
| 5 | Cross-VM Restore | `restore-cross-vm` | Restores a HANA backup from VM-1 to VM-2 (AlternateWorkloadRestore). Validates the target HANA instance starts and the database is consistent. Requires ≥ 2 HANA nodes. |
16+
17+
## Prerequisites
18+
19+
### 1. Azure Backup Configuration
20+
21+
- A **Recovery Services vault** must exist with SAP HANA backup configured.
22+
- At least one HANA database must be **registered and protected** with a backup policy.
23+
- A recent backup (full or incremental) must have completed successfully so restore points are available.
24+
25+
For setup guidance, see [Back up SAP HANA databases in Azure VMs](https://learn.microsoft.com/azure/backup/sap-hana-database-instances-backup).
26+
27+
### 2. Managed Identity Permissions
28+
29+
The management server's managed identity (system- or user-assigned) requires:
30+
31+
| Role | Scope | Purpose |
32+
|------|-------|---------|
33+
| **Backup Operator** | Recovery Services vault | Discover protected items, list restore points, trigger restore operations, monitor restore jobs |
34+
| **Reader** | HANA VM resource group | Resolve target VM ARM IDs for cross-VM and filesystem restores |
35+
36+
For identity setup, see [Setup Guide — Identity and Authorization](./SETUP.MD#4-identity-and-authorization).
37+
38+
### 3. HANA Node Access
39+
40+
- The management server must have SSH connectivity to all HANA DB hosts.
41+
- The `<sid>adm` user must be able to run `HDB stop`, `HDB start`, `sapcontrol`, and `hdbsql` commands.
42+
- For test case 3 (restore-to-filesystem), the target filesystem path must be writable.
43+
- For test case 5 (cross-VM restore), at least 2 HANA nodes must be in the inventory.
44+
45+
## Configuration
46+
47+
### 1. Update `vars.yaml`
48+
49+
Set the test type to `AzureBackupDatabase`:
50+
51+
```yaml
52+
TEST_TYPE: SAPFunctionalTests
53+
SAP_FUNCTIONAL_TEST_TYPE: AzureBackupDatabase
54+
```
55+
56+
### 2. Configure Backup Parameters
57+
58+
Add the following variables to your system's `sap-parameters.yaml` file (under `WORKSPACES/SYSTEM/<SYSTEM_CONFIG_NAME>/`):
59+
60+
```yaml
61+
# Required: Recovery Services vault resource ID
62+
backup_vault_resource_id: "/subscriptions/xxxx/resourceGroups/my-backup-rg/providers/Microsoft.RecoveryServices/vaults/my-rsv-vault"
63+
64+
# Required for restore test cases (2-5)
65+
backup_container_name: "VMAppContainer;Compute;my-rg;hanavm01"
66+
backup_item_name: "saphanadatabase;h05;systemdb"
67+
68+
# Required for filesystem restore (test case 3)
69+
backup_target_filesystem_path: "/hana/backup/restore"
70+
71+
# Required for cross-VM restore (test case 5)
72+
backup_target_container_name: "VMAppContainer;Compute;my-rg;hanavm02"
73+
backup_target_database_name: "SYSTEMDB"
74+
75+
# Optional: point-in-time restore (ISO 8601 UTC timestamp)
76+
backup_restore_point_time: ""
77+
```
78+
79+
### 3. User-Assigned Managed Identity (Optional)
80+
81+
If your management server uses a user-assigned managed identity, set the client ID in `vars.yaml`:
82+
83+
```yaml
84+
user_assigned_identity_client_id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
85+
```
86+
87+
If omitted or set to `null`, the framework uses system-assigned managed identity.
88+
89+
## Test Execution
90+
91+
Run the tests using the `sap_automation_qa.sh` script:
92+
93+
```bash
94+
# Run all Azure Backup test cases
95+
./scripts/sap_automation_qa.sh --test_groups=BACKUP_DB_HANA
96+
97+
# Run specific test cases
98+
./scripts/sap_automation_qa.sh --test_groups=BACKUP_DB_HANA --test_cases=[backup-setup-verification]
99+
./scripts/sap_automation_qa.sh --test_groups=BACKUP_DB_HANA --test_cases=[restore-to-db,restore-to-filesystem]
100+
./scripts/sap_automation_qa.sh --test_groups=BACKUP_DB_HANA --test_cases=[restore-cross-vm]
101+
102+
# Run with verbose output
103+
./scripts/sap_automation_qa.sh --test_groups=BACKUP_DB_HANA -vv
104+
```
105+
106+
### Via SAP QA Service API
107+
108+
```bash
109+
# Create a job through the API
110+
./scripts/sap_automation_qa.sh job create --workspace DEV-WEEU-SAP01-X00 --test-group AzureBackupDatabase
111+
```
112+
113+
## Viewing Test Results
114+
115+
Test results are generated the same way as HA tests. Navigate to your workspace directory:
116+
117+
```bash
118+
cd WORKSPACES/SYSTEM/<SYSTEM_CONFIG_NAME>/quality_assurance/
119+
```
120+
121+
The HTML report summarises each test case with PASS/FAIL/SKIPPED status. For details on the report format, see [High Availability — Viewing Test Results](./HIGH_AVAILABILITY.md#viewing-test-results).

requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ azure-kusto-ingest
1111
azure-mgmt-compute
1212
azure-mgmt-loganalytics
1313
azure-mgmt-network
14+
azure-mgmt-recoveryservicesbackup
1415
azure-storage-blob
1516
azure-storage-queue
1617

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,13 @@ azure-mgmt-core==1.6.0
5858
# azure-mgmt-compute
5959
# azure-mgmt-loganalytics
6060
# azure-mgmt-network
61+
# azure-mgmt-recoveryservicesbackup
6162
azure-mgmt-loganalytics==13.1.1
6263
# via -r requirements.in
6364
azure-mgmt-network==30.2.0
6465
# via -r requirements.in
66+
azure-mgmt-recoveryservicesbackup==10.0.0
67+
# via -r requirements.in
6568
azure-storage-blob==12.26.0
6669
# via
6770
# -r requirements.in

scripts/sap_automation_qa.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ Examples:
5050
$0 --test_groups=HA_DB_HANA --test_cases=[ha-config,primary-node-crash] --extra-vars='{"key":"value"}'
5151
$0 --test_groups=HA_DB_HANA --test_cases=[ha-config] --offline
5252
53+
# Azure Backup Tests (set SAP_FUNCTIONAL_TEST_TYPE: AzureBackupDatabase in vars.yaml)
54+
$0 --test_groups=BACKUP_DB_HANA --test_cases=[backup-setup-verification]
55+
$0 --test_groups=BACKUP_DB_HANA --test_cases=[restore-to-db,restore-to-filesystem]
56+
$0 --test_groups=BACKUP_DB_HANA -vv
57+
5358
# Configuration Checks (requires TEST_TYPE: ConfigurationChecks in vars.yaml)
5459
$0 --extra-vars='{"configuration_test_type":"all"}'
5560
$0 --extra-vars='{"configuration_test_type":"high_availability"}'
@@ -82,6 +87,12 @@ Available Test Cases for groups:
8287
kill-sapstartsrv-process => Kill SAP Start Service Process
8388
manual-restart => Manual Restart
8489
ha-failover-to-node => HA Failover to Secondary Node
90+
$0 --test_groups=BACKUP_DB_HANA
91+
backup-setup-verification => Azure Backup Setup Verification
92+
restore-to-db => Restore Backup to HANA DB
93+
restore-to-filesystem => Restore Backup to FileSystem
94+
recover-db-commands => Recover DB using Database Commands
95+
restore-cross-vm => Cross-VM Restore
8596
8697
Configuration Checks (set TEST_TYPE: ConfigurationChecks in vars.yaml):
8798
configuration_test_type options (use with --extra-vars):
@@ -270,6 +281,9 @@ get_playbook_name() {
270281
echo "playbook_00_ha_scs_functional_tests"
271282
fi
272283
;;
284+
"AzureBackupDatabase")
285+
echo "playbook_00_backup_db_functional_tests"
286+
;;
273287
"ConfigurationChecks")
274288
echo "playbook_00_configuration_checks"
275289
;;

0 commit comments

Comments
 (0)