KEMBAR78
SAP HANA Backup Automation Guide | PDF
0% found this document useful (0 votes)
133 views1 page

SAP HANA Backup Automation Guide

This stored procedure performs daily backups of the database and prunes old backups from the catalog. It finds the oldest successful backup from the past 5 days, executes a new complete backup with the current date, deletes backups and catalog entries older than the oldest ID, and reclaims log space after backup completion. The procedure takes a retention period in days as a parameter.

Uploaded by

Femi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
133 views1 page

SAP HANA Backup Automation Guide

This stored procedure performs daily backups of the database and prunes old backups from the catalog. It finds the oldest successful backup from the past 5 days, executes a new complete backup with the current date, deletes backups and catalog entries older than the oldest ID, and reclaims log space after backup completion. The procedure takes a retention period in days as a parameter.

Uploaded by

Femi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

-- Backup Database and Prune Backup Catalog

CREATE PROCEDURE "SYSTEM"."BACKUP_DAILY" ( IN retention INT )


LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER
AS
BEGIN
--Use a Cursor for future use. The following only loops one time based on one record from SQL.
DECLARE CURSOR c_backup_catalog FOR
--- Find the Minimum Backup ID from sucesful backups in the past 5 days.
SELECT TOP 1 min(to_bigint(BACKUP_ID)) as BACKUP_ID,
TO_CHAR(CURRENT_TIMESTAMP,'YYYYMMDD') as TODAY
FROM SYS.M_BACKUP_CATALOG
where SYS_START_TIME >= ADD_DAYS(CURRENT_TIMESTAMP, -:retention)
and SYS_START_TIME <= CURRENT_TIMESTAMP
and ENTRY_TYPE_NAME = 'complete data backup'
and STATE_NAME = 'successful';

FOR cur_row as c_backup_catalog DO


--- Execute Backup adding todays date as an Integer
EXEC 'BACKUP DATA USING FILE (''COMPLETE_DATA_BACKUP_' || cur_row.TODAY || ''')' ;
--- Cleanup the Backup Catalog and backup files over X days old
EXEC 'BACKUP CATALOG DELETE ALL BEFORE BACKUP_ID ' || cur_row.BACKUP_ID || ' COMPLETE';
--- Reclaim any log space post backup
EXEC 'ALTER SYSTEM RECLAIM LOG';

END FOR;

END;

/* Execute the Procedure from SAP HANA Studio Example: CALL SYSTEM.BACKUP_DAILY(5) */

You might also like