Document Type | Technical Information
Category | Backup/Recovery
Applicable Product Version | Tibero 7.2.2
Document Number | TBATI034
Overview
This is a Hotbackup script that can be used in a RawDevice environment.
Test Environment
- OS Version : CentOS Linux release 7.9.2009 (Core)
- Tibero Version : Tibero 7 (DB 7.2.2) Build 293662
Method
Hotbackup Script Main Body
#!/bin/sh
# !! Check !!
# Mandatory 1,2,3 must be checked by the DBA or Administrator
# Mandatory 1 : Backup shell Environment parameters
# Mandatory 2 : Datafile copy CASE
# Mandatory 3 : Archive Backup CASE
################################################################################
# Shell Environment
################################################################################
################################################################################
#
# (Mandatory 1)
#
# TB_USER : Tibero user installed on OS
# TB_HOME : TB_HOME of the user with Tibero installed
# ARCH_DIR : Path to the archive log
# WORK_DIR : Fullbackup path
#
################################################################################
################################################################################
#
# (Optional)
#
# BACKUP_DIR : Backup destination directory (created under WORK_DIR with timestamp)
# BACKUP_CTL : Backup file path for control file (controlfile trace backup)
# LIST_DIR : Directory for storing list files (e.g., tablespace, datafile lists)
# TMP_DIR : Temporary working directory for intermediate SQL spool results
# LOG_DIR : Directory for storing backup log files
# LOG : Log file name (includes hostname and date information)
# TABLESPACES: File that stores the list of tablespaces to be backed up
# FILE_LIST : File that stores the list of datafiles for each tablespace
################################################################################
# (Mandatory 1)
TB_USER=tibero
TB_HOME=/tibero/tibero7
ARCH_DIR=/tibarch/
WORK_DIR=/data/backup/full_backup
# (Optional)
BACKUP_DIR=$WORK_DIR/`date +%y%m%d_%H%M`
BACKUP_CTL=$BACKUP_DIR/control.ctl.bak
LIST_DIR=$WORK_DIR/list
TMP_DIR=$WORK_DIR/tmp
LOG_DIR=$WORK_DIR/log
LOG=$LOG_DIR/`uname -n`_`date +%m%d`.log
TABLESPACES=$LIST_DIR/TABLESPACES.LIST
FILE_LIST=$LIST_DIR/datafile.list
mkdir -p "$BACKUP_DIR"
mkdir -p "$LIST_DIR"
mkdir -p "$TMP_DIR"
mkdir -p "$LOG_DIR"
touch "$LOG"Note
This backup script requires the subdirectories to exist on the first run, so the -p option is added.
# Using the mkdir -p option prevents errors if the directory already exists.
if [[ -d $BACKUP_DIR && (-w $BACKUP_DIR) ]];
then
echo '$BACKUP_DIR' is $BACKUP_DIR setting.
else
echo ' ERROR !! ' '$BACKUP_DIR' is $BACKUP_DIR not setting. Check is $BACKUP_DIR
exit 1
fi
if [[ -d $LIST_DIR && (-w $LIST_DIR) ]];
then
echo '$LIST_DIR' is $LIST_DIR setting.
else
echo ' ERROR !! ' '$LIST_DIR' is $LIST_DIR not setting. Check is '$LIST_DIR'
exit 1
fi
if [[ -d $TMP_DIR && (-w $TMP_DIR) ]];
then
echo '$TMP_DIR' is $TMP_DIR setting.
else
echo ' ERROR !! ' '$TMP_DIR' is $TMP_DIR not setting. Check is '$TMP_DIR'
exit 1
fi
if [[ -d $LOG_DIR && (-w $LOG_DIR) ]];
then
echo '$LOG_DIR' is $LOG_DIR setting.
else
echo ' ERROR !! ' '$LOG_DIR' is $LOG_DIR not setting. Check is '$LOG_DIR'
exit 1
fi
if [ -w $LOG ];
then
echo '$LOG' is $LOG setting.
else
echo ' ERROR !! ' '$LOG' is $LOG not setting. Check is '$LOG'
exit 1
fi
rm -f $LIST_DIR/* $TMP_DIR/*Note
If the files to be removed do not exist, the message 'rm: cannot remove /data/backup/full_backup/list/*: No such file or directory' may appear, but this is normal.
echo
"################################################################################" >> $LOG
echo "##### Backup Begin" >> $LOG
echo "##### Begin Time : `date`" >> $LOG
echo "#####" >> $LOG
echo "##### Datafile backup Begin " >> $LOG
echo "#####" >> $LOG
################################################################################
# Tablespace List Getting
################################################################################
tbsql sys/tibero <<EOF>> /dev/null
spool $TMP_DIR/tbs.tmp
select tablespace_name from dba_tablespaces;
spool off
exit
EOF
cat $TMP_DIR/tbs.tmp| grep -v TABLESPACE | grep -v "\-\-\-"|grep -v selected |grep -v SQL | sed '/^ *$/d' > $TMP_DIR/tbs_l.tmp
cat $TMP_DIR/tbs_l.tmp | grep -v TEMP > $TABLESPACES
################################################################################
# Tablespace Backup
################################################################################
cat $TABLESPACES | while read TBSPACE
do
echo "##### $TBSPACE" >> $LOG
tbsql sys/tibero << EOF >> /dev/null
alter tablespace $TBSPACE begin backup wait;
exit
EOF
Note
Using the wait option causes the script to wait to acquire a lock, and the backup command executes normally once the lock is acquired.
################################################################################
# Datafile List Getting
################################################################################
tbsql sys/tibero <<EOF >> /dev/null
spool $TMP_DIR/datafile.tmp
select file_name from dba_data_files where tablespace_name = '$TBSPACE';
spool off
exit
EOF
cat $TMP_DIR/datafile.tmp | grep -v FILE | grep -v "\-\-\-"|grep -v selected |grep -v SQL|sed '/^ *$/d' > $TMP_DIR/df_l.tmp
cat $TMP_DIR/df_l.tmp | awk '{print $1}' > $LIST_DIR/datafile.list
cat $LIST_DIR/datafile.list | while read DATAFILE
do
echo "dd if=$DATAFILE of=$BACKUP_DIR/`echo $DATAFILE | rev | cut -d / -f 1 | rev` bs=8k" >> $LOG
dd if=$DATAFILE of=$BACKUP_DIR/`echo $DATAFILE | rev | cut -d / -f 1 | rev` bs=8k >> $LOG 2>&1
done
tbsql sys/tibero<<EOF >> /dev/null
alter tablespace $TBSPACE end backup wait;
exit
EOF
echo ""
done
echo "##### Datafile backup End" >> $LOG
echo "#####" >> $LOG
################################################################################
# Archive and Controlfile backup
################################################################################
echo "##### Archive and Controlfile backup Begin" >> $LOG
echo "#####" >> $LOG
# Controlfile backup
# CHECK!! SQL (alter system switch logfile;) runs as many redo log groups (ex script. redo log 3 groups)
# select count(*)/2 as log_group_cnt from v$log;
tbsql sys/tibero<<EOF >> /dev/null
alter system switch logfile;
alter system switch logfile;
alter system switch logfile;
alter database backup controlfile to trace as '$BACKUP_CTL' reuse resetlogs;
exit
EOF
################################################################################
# #
# (Mandatory 3) #
# Archive Backup #
# #
# CASE 1. Archive is CP backup #
# #
# CASE 2. Archive is Veritas NetBackup Solution backup #
# #
# Select CASE. But enter # in front of other case command. #
# #
################################################################################
##############################################################
# CASE 1. Archive is CP backup #
##############################################################
cp -R $ARCH_DIR $BACKUP_DIR >>$LOG
echo "##### Archive and Controlfile backup End" >> $LOG
echo "#####" >> $LOG
echo "##### ALL Backup Complete!!!!" >> $LOG
echo "##### End Time : `date`" >> $LOG
echo "################################################################################" >> $LOG
echo " " >> $LOG