2022-01-06

TableAU Backup and Restore

#!/bin/bash
#############################################
# @CreatedDate: #13:39 2022.01.04
# @LastUpdate : #12:46 2022.01.06
# @Last Modified by: iadmin
#############################################
#cat /opt/script/tableau-backup.sh | grep LastUpdate
#############################################
#__________TIME_START:BEGIN
time_start=`date +%s.%3N`
#__________TIME_START:END
#############################################
#############################################
#__________TIME_CALCULATE:BEGIN
#now1: 2022.01.06-11.55.40.168
now1="$(date +'%Y.%m.%d-%H.%M.%S.%3N')"

CURRENT_YEAR=$(date +'%Y'); CURRENT_MONTH=$(date +'%m'); CURRENT_DATE=$(date +'%d')
CURRENT_HOUR=$(date +'%H'); CURRENT_MINUTE=$(date +'%M'); CURRENT_SECOND=$(date +'%S'); CURRENT_MILISECOND=$(date +'%3N');
#YYYY_MM: 2022-01
YYYY_MM="$CURRENT_YEAR-$CURRENT_MONTH"

#YYYY_MM_DD: 2022-01-06
#YYYY_MM_DD="$CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE"

#YYYY_MM_DD: 20220106
YYYY_MM_DD="$CURRENT_YEAR""$CURRENT_MONTH""$CURRENT_DATE"

#HH_MM_SS: 11:55:40.206
#HH_MM_SS="$CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND.$CURRENT_MILISECOND"

#HH_MM_SS: 11.55.40.206
HH_MM_SS="$CURRENT_HOUR.""$CURRENT_MINUTE.""$CURRENT_SECOND.""$CURRENT_MILISECOND"

# echo "YYYY_MM: $YYYY_MM"
# echo "YYYY_MM_DD: $YYYY_MM_DD"
# echo "HH_MM_SS: $HH_MM_SS"
# echo "now1: $now1"
#__________TIME_CALCULATE:END

(
#__________BACKUP_PROCESSING:BEGIN
TableAU_Backup_LOC="/opt/bk/TableAU";
mkdir -p $TableAU_Backup_LOC; cd $TableAU_Backup_LOC

echo ""
echo "Go to backup date folder: [$TableAU_Backup_LOC/$YYYY_MM_DD]"
mkdir -p $YYYY_MM_DD; cd $YYYY_MM_DD

Config_File="config-$YYYY_MM_DD-$HH_MM_SS.json"
Data_File="data-$YYYY_MM_DD-$HH_MM_SS.tsbak"

echo ""
echo "Backup Config: [tsm settings export -f config $Config_File]"
#tsm settings export --output-config-file <path/to/output_file.json> [global options]
#tsm settings export -f config "$Config_File"
tsm settings export --output-config-file "$Config_File"

echo ""
echo "Backup Data: [tsm maintenance backup -f $Data_File]"
#tsm maintenance backup --file <backup_file> [options] [global options]
tsm maintenance backup --file "$Data_File"

echo ""
echo "Moving backup data to Backup Folder [$TableAU_Backup_LOC/$YYYY_MM_DD]"
mv /var/opt/tableau/tableau_server/data/tabsvc/files/backups/* $TableAU_Backup_LOC/$YYYY_MM_DD

md5sum "$Data_File" > "$Data_File".md5
#__________BACKUP_PROCESSING:END


#______________________DELETE_OLD_DATA:BEGIN
cd $PATH_DST
NumberOfFileWantToKeep=14
#Giu lai [14] file moi nhat trong thu muc [$FOLDER_DST]:
#XOA FILE:
#/bin/rm -rf `ls -t "20"* | awk 'NR>7'`

#XOA FOLDER:
cd $TableAU_Backup_LOC
/bin/rm -rf `ls -td */ | awk 'NR>14'`
#______________________DELETE_OLD_DATA:END

#______________________FREE_RAM:BEGIN
free && sync && echo 3 > /proc/sys/vm/drop_caches && free
free
# printf "RAM FREE: \n $(free -h)\n" >> $DB_RESULT.log
#______________________FREE_RAM:END

#############################################
#############################################
#__________TIME_END:BEGIN
time_end=`date +%s.%3N`
execution_time=$( echo "$time_end - $time_start" | bc -l -l );
echo "time_start: [$time_start = $(date -d@$time_start +'%Y.%m.%d-%H.%M.%S.%3N')]"
echo "time_end : [$time_end = $(date -d@$time_end +'%Y.%m.%d-%H.%M.%S.%3N')]"
echo "runtime : [$execution_time] (second.milliseconds)"
#__________TIME_END:END
) 2>&1 | tee backup-job-$YYYY_MM_DD-$HH_MM_SS.log


#THE_END:
# #Restore Config:
# #https://help.tableau.com/current/server/en-us/cli_settings_tsm.htm#TSMSet
# tsm settings import --import-config-file config-2022.01.04-17h40.json

# #Restore Data:
# #https://help.tableau.com/current/server/en-us/upgrade_migrate.htm
# chown -R tableau.tableau /opt/temp/bi-2021.01.04-17h40-2022-01-04.tsbak
# tsm maintenance restore -f /opt/temp/bi-2021.01.04-17h40-2022-01-04.tsbak


#####################
# root@srv032:/opt/bk/TableAU/20220106# /opt/script/tableau-backup.sh

# Go to backup date folder: [/opt/bk/TableAU/20220106]

# Backup Config: [tsm settings export -f config config-20220106-12.33.43.768.json]
# Configuration file written to /opt/bk/TableAU/20220106/config-20220106-12.33.43.768.json.

# Backup Data: [tsm maintenance backup -f data-20220106-12.33.43.768.tsbak]
# Job id is '25', timeout is 1440 minutes.
# 6% - Starting the Active Repository instance, File Store, and Cluster Controller.
# 13% - Waiting for the Active Repository, File Store, and Cluster Controller to start.
# 20% - Installing backup services.
# 26% - Estimating required disk space.
# 33% - Gathering disk space information from all nodes.
# 40% - Analyzing disk space information.
# 46% - Checking if sufficient disk space is available on all nodes.
# 53% - Backing up configuration.
# 60% - Backing up object storage data.
# 66% - Backing up database.
# 73% - Backing up asset keys.
# 80% - Assembling the tsbak archive.
# 86% - Stopping the Active Repository if necessary.
# 93% - Waiting for the Active Repository to stop if necessary.
# 100% - Uninstalling backup services.
# Backup written to '/var/opt/tableau/tableau_server/data/tabsvc/files/backups/data-20220106-12.33.43.768.tsbak' on the controller node.

# Moving backup data to Backup Folder [/opt/bk/TableAU/20220106]
# time_start: [1641447223.762 = 2022.01.06-12.33.43.762]
# time_end : [1641447421.623 = 2022.01.06-12.37.01.623]
# runtime : [197.861] (second.milliseconds)
# root@srv032:/opt/bk/TableAU/20220106#
#####################

No comments:

Post a Comment