In previous tips, you already know how to backup your own schema in HANA Studio in a manual way, using several clicks on the mouse, or write your own backup script in SQL Console, then you must compress a backup folder into .tar.gz compressed file using Linux command.
Now, you can simplify those step-by-step into only a one-step solution.
Please follow the steps below:
- Open puTTy, and login into your HANA system using root
- Go to /hana/shared/NDB/hdbclient/ directory
- Type command below to create environment variable key (you can type your own key name)
./hdbuserstore SET KEYNAME HOSTNAME: PORTNUMBER DBUSER DBPASSWORD
Please see the sample below: - Open Notepad++ (Don’t use windows standard notepad), create a new document, and copy the script below:
#Begin Of Script
#Parameter SCHEMA_NAME will be passed from shellscript argument and will be used as the directory name and compressed backup file nameSCHEMA_NAME=$1 #Parameter BACKUP_BASE_DIR is the backup root directory. You can change its value. This directory will be created automatically if necessary.
BACKUP_BASE_DIR=/hana/backup/SCHEMA_BACKUP #Parameter BACKUP_FOLDER will be created using SCHEMA_NAME parameter and concatenated with the current timestamp, for example:
SCHEMA_NAME_202012181330 #You can change this parameter value at your own risk.
BACKUP_FOLDER=${SCHEMA_NAME}_$(date +%Y%m%d%H%M) BACKUP_FOLDER=${SCHEMA_NAME}_$(date +%Y%m%d%H%M)
BACKUP_FULL_PATH=${BACKUP_BASE_DIR}/${BACKUP_FOLDER}mkdir -p ${BACKUP_BASE_DIR}
mkdir -p ${BACKUP_BASE_DIR}/${BACKUP_FOLDER}
cd ${BACKUP_BASE_DIR}
chown ndbadm:sapsys ${BACKUP_BASE_DIR}
chown ndbadm:sapsys ${BACKUP_FULL_PATH}
cd /hana/shared/NDB/HDB00/exe/
./hdbsql -U STEMBACKUP “EXPORT ${SCHEMA_NAME}.”*” AS BINARY INTO ‘${BACKUP_FULL_PATH}/’ WITH REPLACE THREADS 8″
cd ${BACKUP_BASE_DIR}#After the backup is done, the system will compress it into .tar.gz file.
tar -zcvf ${BACKUP_FOLDER}.tar.gz ${BACKUP_FOLDER} #Then the system will remove the current backup directory
rm -rf ${BACKUP_FOLDER} #End Of Script
- Please change “STEMBACKUP” to your own environment variable key. You can also change the Threads number if necessary.
- Change Notepad++ EOL conversion into Unix (LF)
- Save document as Unix script file (.sh)
- Copy this file into your HANA System using WinSCP (you can put it anywhere).
- In puTTy, go to directory where this script file located as root user, and type command below:
chmod 777 YOUR_SCRIPT_FILE.sh Sample:
chmod 777 backupsample.sh - Now you can use this script using command below:
/YOUR_SCRIPT_FILE.sh SCHEMA_NAME (This script accepts only one schema name as argument)
Sample:
/backupsample.sh DB_TRAINING
Now you can easily backup schema in just one step
These tips will work on any HANA Version (1.0 or 2.0) and any revision.
Also read: