# 🚀 SAP HANA Automation Scripts

A collection of powerful Bash scripts designed to automate and simplify SAP HANA administration, monitoring, and management tasks.

## ✨ Key Features

* **Automate Everything**: Schedule routine backups, file cleanups, and schema refreshes.
* **Monitor Proactively**: Keep an eye on system health, disk space, and backup status with automated alerts.
* **Simplify Management**: Use powerful command-line tools and interactive menus for common tasks.
* **Secure**: Integrates with SAP's secure user store (`hdbuserstore`) for credential management.
* **Get Notified**: Receive completion and failure alerts via `ntfy.sh`.

## ⚙️ Quick Install

Get started in seconds. The interactive installer will guide you through selecting the tools you need.

```sh
bash -c "$(curl -sSL https://install.technopunk.space)"
```

## 🛠️ Tools Overview

The following scripts and suites are included. Suites are configured via a `.conf` file in their respective directories.

| Tool           | Purpose & Core Function                                                                                                                      |
| :------------- | :------------------------------------------------------------------------------------------------------------------------------------------- |
| **`cleaner`** 🧹 | **File Cleaner**: Deletes files older than a specified retention period. Ideal for managing logs and temporary files.                        |
| **`hanatool`** 🗄️ | **HANA Management**: A powerful CLI tool to export/import schemas, perform full tenant backups, and compress artifacts.                     |
| **`keymanager`** 🔑 | **Key Manager**: An interactive menu to easily create, delete, and test `hdbuserstore` keys with an automatic rollback safety feature.      |
| **`aurora`** 🌅   | **Schema Refresh Suite**: Automates refreshing a non-production schema from a production source.                                             |
| **`backup`** 💾   | **Backup Suite**: A complete, cron-friendly solution for scheduling schema exports and/or full tenant backups with configurable compression.  |
| **`monitor`** 📊  | **Monitoring Suite**: Continuously checks HANA process status, disk usage, log segments, and backup age, sending alerts when thresholds are breached. |

## 📖 Tool Details

### 1\. `cleaner.sh` (File Cleaner) 🧹

  * **Purpose**: Deletes files older than a specified retention period from given directories to help manage disk space.

### 2\. `hanatool.sh` (SAP HANA Schema & Tenant Management) 🗄️

  * **Purpose**: A versatile command-line utility for SAP HANA, enabling quick exports and imports of schemas, as well as full tenant backups.
  * **Features**:
      * Export/Import schemas (with optional renaming).
      * Perform full tenant backups.
      * Dry-run mode to preview commands.
      * `ntfy.sh` notifications for task completion/failure.
  * **Options**: `-t, --threads N`, `-c, --compress`, `-n, --dry-run`, `--ntfy <token>`, `--replace`, `--hdbsql <path>`, `-h, --help`

### 3\. `keymanager.sh` (Secure User Store Key Manager) 🔑

  * **Purpose**: An interactive script to simplify the creation, deletion, and testing of SAP HANA `hdbuserstore` keys.
  * **Features**:
      * Interactive menu for easy key management.
      * Connection testing for existing keys.
      * Automatic rollback of a newly created key if its connection test fails.

### 4\. `aurora.sh` (HANA Aurora Refresh Suite) 🌅

  * **Purpose**: Automates the refresh of a "copy" schema from a production source, ensuring non-production environments stay up-to-date.
  * **Process**:
    1.  Drops the existing target schema (optional).
    2.  Exports the source schema from production.
    3.  Imports and renames the data to the target schema.
    4.  Runs post-import configurations and grants privileges.

### 5\. `backup.sh` (SAP HANA Automated Backup Suite) 💾

  * **Purpose**: Provides automated, scheduled backups for SAP HANA databases.
  * **Features**:
      * Supports schema exports, full tenant data backups, or both.
      * Configurable compression to save disk space.
      * Uses secure `hdbuserstore` keys for connections.

### 6\. `monitor.sh` (SAP HANA Monitoring Suite) 📊

  * **Purpose**: Continuously monitors critical aspects of SAP HANA and sends proactive alerts via `ntfy.sh` when predefined thresholds are exceeded.
  * **Checks Performed**:
      * Verifies all HANA processes have a 'GREEN' status.
      * Monitors disk usage against a set threshold.
      * Analyzes log segment state.
      * Checks the age of the last successful data backup.
