【BASIS】HANA備份指令碼,Catalog自動清理

penguin.23發表於2020-12-14

1、建立備份的資料庫賬號;

create user <Backup User Name> password "<Password>";

alter user <Backup User Name> DISABLE PASSWORD LIFETIME;

grant backup admin to <Backup User Name>;

2、加密HANA賬號登陸憑據;
hdbuserstore set USER4BACKUP localhost:3<Instance Number>15 <Backup User Name> <Password>

3、自動備份指令碼;

#!/bin/sh

#/* Backup script */

source $HOME/.bashrc

date="$(date +"%Y-%m-%d")"

time="$(date +"%Y-%m-%d %H:%M:%S")"

backup="backup data using file ('$date')"

echo "daily backup  :"  $time  "Start" >> $DIR_INSTANCE/backup.log

$DIR_EXECUTABLE/hdbsql -U USER4BACKUP -x $backup 

time="$(date +"%Y-%m-%d %H:%M:%S")"

echo "daily backup  :"  $time  "End" >> $DIR_INSTANCE/backup.log

time="$(date +"%Y-%m-%d %H:%M:%S")"

4、自動清理Hana Catalog指令碼;

sql="select top 1 REPLACE(BACKUP_ID,',','') as A from M_BACKUP_CATALOG where ENTRY_TYPE_NAME='complete data backup' and UTC_START_TIME <= ADD_DAYS(CURRENT_UTCDATE,-7) order by UTC_END_TIME desc"

backupid=`$DIR_EXECUTABLE/hdbsql -U USER4BACKUP  -x $sql | grep \" | sed -e 's/\"//g'`


if [ -z $backupid ]

then

        echo "backupid not found"

else

        sql="BACKUP CATALOG DELETE ALL BEFORE BACKUP_ID $backupid COMPLETE"

        $DIR_EXECUTABLE/hdbsql -U USER4BACKUP -x $sql

fi

5、 第三、四兩段指令碼合起來,配置自動任務執行。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/20659905/viewspace-2742176/,如需轉載,請註明出處,否則將追究法律責任。

相關文章