From Chris85, 2 Years ago, written in Bash.
This paste is a reply to Backup Script from Chris85 - view diff
  1. #!/usr/bin/env bash
  2. # Exxis Backup Service
  3. # Version: 1.0
  4. # Developer: Christopher Carrasco Cartagena
  5.  
  6. clear
  7.  
  8. source `dirname $0`/backup.conf
  9.  
  10. spinner()
  11. {
  12.     local pid=$1
  13.     local delay=0.5
  14.     local spinstr='|/-\'
  15.     while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
  16.         local temp=${spinstr#?}
  17.         printf " [%c]  " "$spinstr"
  18.         local spinstr=$temp${spinstr%"$temp"}
  19.         sleep $delay
  20.         printf "\b\b\b\b\b\b"
  21.     done
  22.     printf "    \b\b\b\b"
  23.     echo ""
  24. }
  25.  
  26. createdirs()
  27. {
  28.     mkdir -p ${BACKUP_DESTINY}data
  29.     mkdir -p ${BACKUP_DESTINY}log
  30.     mkdir -p ${BACKUP_DESTINY}exports
  31. }
  32.  
  33. tarfile()
  34. {
  35.     echo -n "Creating TAR GZIP file..."
  36.     tar -czf "${BACKUP_DESTINY}exports/$3_$2.tar.gz" -C $1 . &
  37.     spinner $!
  38. }
  39.  
  40. deletefile()
  41. {
  42.     echo -n "Deleting original export..."
  43.     rm -fR $1 &
  44.     spinner $!
  45. }
  46.  
  47. backuphana()
  48. {
  49.     echo -e "\nStarting HANA instance backup...\n"
  50.  
  51.     su - ${LOW_USER} -c ". ${HANA_PATH}hdbenv.sh"
  52.     su - ${LOW_USER} -c "hdbsql -U $BACKUP_KEY \"backup data using file ('$BACKUP_PREFIX')\"" &
  53.  
  54.     echo -n "Performing data backup as ${BACKUP_PREFIX}"
  55.     spinner $!
  56. }
  57.  
  58. createhanafile()
  59. {
  60.     echo -n "Creating TAR GZIP file from ${BACKUP_PREFIX}"
  61.  
  62.     HANA_BACKUP_PATH="${HANA_PATH}backup/data/"
  63.  
  64.     tar -czf ${BACKUP_DESTINY}data/${BACKUP_PREFIX}.tar.gz ${HANA_BACKUP_PATH}${BACKUP_PREFIX}* >/dev/null 2>&1 &
  65.     spinner $!
  66. }
  67.  
  68. backuplogs()
  69. {
  70.     echo -n "Creating TAR GZIP file from logs as ${LOG_PREFIX}"
  71.     HANA_LOG_BACKUP_PATH="${HANA_PATH}backup/log/"
  72.     tar -czf ${BACKUP_DESTINY}log/${LOG_PREFIX}.tar.gz ${HANA_LOG_BACKUP_PATH}* >/dev/null 2>&1 &
  73.     spinner $!
  74. }
  75.  
  76. deleteoldbackups()
  77. {
  78.     echo -ne "Deleting old backups"
  79.  
  80.     HANA_LOG_PATH="${HANA_PATH}backup/log/"
  81.  
  82.     #find ${HANA_LOG_PATH}* -mtime +${RETENTION} -exec rm {} \; &
  83.     SQL_EXE=$(su - ndbadm -c "hdbsql -U $BACKUP_KEY \"SELECT TOP 1 min(to_bigint(BACKUP_ID)) FROM SYS.M_BACKUP_CATALOG where SYS_START_TIME >= ADD_DAYS(CURRENT_TIMESTAMP, -${RETENTION}) and ENTRY_TYPE_NAME = 'complete data backup' and STATE_NAME = 'successful'\"")
  84.     BACKUP_ID=$(echo -e "${SQL_EXE}" | awk 'NR==2')
  85.     SQL_EXE=$(su - ndbadm -c "hdbsql -U $BACKUP_KEY \"BACKUP CATALOG DELETE ALL BEFORE BACKUP_ID $BACKUP_ID COMPLETE\"") &
  86.     spinner $!
  87.  
  88.     if [ "${RECLAIM_LOG_SPACE}" == "yes" ]; then
  89.         echo -n "Reclaiming un-needed log space"
  90.         SQL_EXE=$(su - ndbadm -c "hdbsql -U $BACKUP_KEY \"ALTER SYSTEM RECLAIM LOG\"") &
  91.         spinner $!
  92.     fi
  93. }
  94.  
  95. #BEGIN
  96.  
  97. MACHINE_EXPORT="${MACHINE_IP}_${SAP_HANA_PORT}"
  98. WORK_PATH="${BACKUP_PATH}${MACHINE_EXPORT}/${INSTANCE_NAME}/"
  99.  
  100. echo "=========================="
  101. echo "Exxis Backup Tool Ver. 1.0"
  102. echo "=========================="
  103.  
  104. echo -e "\nUsing backup export origin path: \t${BACKUP_PATH}"
  105. echo -e "Using backup export destiny path: \t${BACKUP_DESTINY}"
  106. echo -e "Backup retention: \t\t\t${RETENTION} day(s)"
  107.  
  108. createdirs
  109.  
  110. for DB in ${WORK_PATH}*; do
  111.     DB_NAME="${DB##*/}"
  112.     for BCK in ${DB}/*; do
  113.         BCK_NAME="${BCK##*/}"
  114.         if [ ${BCK_NAME} != "bck_actual" ]; then
  115.             BCK_DATETIME="${BCK_NAME:4:14}"
  116.             BCK_DATE="${BCK_DATETIME:0:8}"
  117.             BCK_TIME="${BCK_DATETIME:8:6}"
  118.             echo -e "\nProcessing export: (${DB_NAME}) ${BCK_NAME}"
  119.             tarfile "${BCK}" "${BCK_DATETIME}" "${DB_NAME}"
  120.             deletefile "${BCK}"
  121.         fi
  122.     done
  123. done
  124.  
  125. backuphana
  126.  
  127. if [ "${EXPORT_BACKUP}" == "yes" ]; then
  128.     createhanafile
  129.     backuplogs
  130.     echo
  131. fi
  132.  
  133. deleteoldbackups
  134.  
  135. echo -ne "\nProcessing Data..."
  136. find ${BACKUP_DESTINY}data/* -mtime +$RETENTION -exec rm {} \; &
  137. spinner $!
  138.  
  139. echo -ne "Processing Exports..."
  140. find ${BACKUP_DESTINY}exports/* -mtime +$RETENTION -exec rm {} \; &
  141. spinner $!
  142.  
  143. echo -ne "Processing Logs..."
  144. find ${BACKUP_DESTINY}log/* -mtime +$RETENTION -exec rm {} \; &
  145. spinner $!
  146.  
  147. echo -e "\nExxis Backup Tool ended"
  148. exit 0
  149.  
  150. #END
captcha