Sybase備份指令碼 btmbfe_sybase_backup.sh
#!/bin/sh
BACKUPDIR=/sybase/dumpdb
log=$BACKUPDIR/dbbackup.log
ddays=3 #3天前的檔案刪除
Date=`date +%Y%m%d`
dayDir=${BACKUPDIR}/MBFEDB_BT_${Date}
tarfile=MBFEDB_BT_${Date}.tar
zfile=${tarfile}.Z
echo "--------------------------------------------------------" >> $log
nowtime=`date +"%Y%m%d %H:%M:%S"`
echo "--> 1-1 $nowtime backup begin" >> $log
if [ -d $dayDir ]
then
echo "--> 1-2 Dir $dayDir exist!" >> $log
else
mkdir $dayDir
echo "--> 1-3 Create dir $dayDir ok!" >> $log
fi
#-- dump --#
DBName='MBFEWKDB MBFEHISDB DIRWAYSDB DISWAYSDB'
chown -R sybase $dayDir
for db in $DBName
do
nowtime=`date +"%Y%m%d %H:%M:%S"`
su - sybase -c "isql -Usa -PBtsa1@ <
dump database $db to '$dayDir/${db}_${Date}.dump'
go
dump transaction $db with truncate_only
go
!"
echo "--> 2 $nowtime $db dump " >> $log
done
#-- 檢查 dump 備份檔案 --#
flag=0
for db in $DBName
do
if [ -f $dayDir/${db}_${Date}.dump ]
then
echo "--> 2-1 $nowtime $db dump ok (flag=$flag)" >> $log
else
flag=`expr $flag + 1`
echo "--> 2-2 $nowtime $db dump fail (flag=$flag)" >> $log
fi
done
if [ "$flag" != "0" ]
then
echo "--> 2-3 backup fail (flag=$flag) " >> $log
echo "--------------------------------------------------------\n\n" >> $log
exit 2
fi
#-- 打包 --#
nowtime=`date +"%Y%m%d %H:%M:%S"`
echo "--> 3-1 $nowtime tar begin" >> $log
tar -cf $BACKUPDIR/$tarfile $dayDir
res=$?
if [ "$res" = "0" ]
then
echo "--> 3-2 tar ok" >> $log
else
echo "--> 3-3 tar fail(res=$res)" >> $log
echo "--------------------------------------------------------\n\n" >> $log
exit 3
fi
#-- 壓縮 --#
nowtime=`date +"%Y%m%d %H:%M:%S"`
echo "--> 4-1 $nowtime compress begin" >> $log
compress $BACKUPDIR/$tarfile
res=$?
if [ "$res" = "0" ]
then
echo "--> 4-2 compress ok (res=$res)" >> $log
cd $BACKUPDIR
rm -rf $dayDir
else
echo "--> 3-3 compress fail (res=$res)" >> $log
echo "--------------------------------------------------------\n\n" >> $log
exit 4
fi
echo "--> 5 Delete files of $ddays days before " >> $log
find $BACKUPDIR -mtime +$ddays -name "MBFEDB_BT_*.Z" >> $log
find $BACKUPDIR -mtime +$ddays -name "MBFEDB_BT_*.Z" | xargs -i /bin/rm {}
ftp -i -n 10.8.7.100 <
user coredb coredb
bin
put $zfile
bye
!
res=$?
echo "--> 6 backup success (res=$res)" >> $log
echo "--------------------------------------------------------\n\n" >> $log
exit 0
BACKUPDIR=/sybase/dumpdb
log=$BACKUPDIR/dbbackup.log
ddays=3 #3天前的檔案刪除
Date=`date +%Y%m%d`
dayDir=${BACKUPDIR}/MBFEDB_BT_${Date}
tarfile=MBFEDB_BT_${Date}.tar
zfile=${tarfile}.Z
echo "--------------------------------------------------------" >> $log
nowtime=`date +"%Y%m%d %H:%M:%S"`
echo "--> 1-1 $nowtime backup begin" >> $log
if [ -d $dayDir ]
then
echo "--> 1-2 Dir $dayDir exist!" >> $log
else
mkdir $dayDir
echo "--> 1-3 Create dir $dayDir ok!" >> $log
fi
#-- dump --#
DBName='MBFEWKDB MBFEHISDB DIRWAYSDB DISWAYSDB'
chown -R sybase $dayDir
for db in $DBName
do
nowtime=`date +"%Y%m%d %H:%M:%S"`
su - sybase -c "isql -Usa -PBtsa1@ <
dump database $db to '$dayDir/${db}_${Date}.dump'
go
dump transaction $db with truncate_only
go
!"
echo "--> 2 $nowtime $db dump " >> $log
done
#-- 檢查 dump 備份檔案 --#
flag=0
for db in $DBName
do
if [ -f $dayDir/${db}_${Date}.dump ]
then
echo "--> 2-1 $nowtime $db dump ok (flag=$flag)" >> $log
else
flag=`expr $flag + 1`
echo "--> 2-2 $nowtime $db dump fail (flag=$flag)" >> $log
fi
done
if [ "$flag" != "0" ]
then
echo "--> 2-3 backup fail (flag=$flag) " >> $log
echo "--------------------------------------------------------\n\n" >> $log
exit 2
fi
#-- 打包 --#
nowtime=`date +"%Y%m%d %H:%M:%S"`
echo "--> 3-1 $nowtime tar begin" >> $log
tar -cf $BACKUPDIR/$tarfile $dayDir
res=$?
if [ "$res" = "0" ]
then
echo "--> 3-2 tar ok" >> $log
else
echo "--> 3-3 tar fail(res=$res)" >> $log
echo "--------------------------------------------------------\n\n" >> $log
exit 3
fi
#-- 壓縮 --#
nowtime=`date +"%Y%m%d %H:%M:%S"`
echo "--> 4-1 $nowtime compress begin" >> $log
compress $BACKUPDIR/$tarfile
res=$?
if [ "$res" = "0" ]
then
echo "--> 4-2 compress ok (res=$res)" >> $log
cd $BACKUPDIR
rm -rf $dayDir
else
echo "--> 3-3 compress fail (res=$res)" >> $log
echo "--------------------------------------------------------\n\n" >> $log
exit 4
fi
echo "--> 5 Delete files of $ddays days before " >> $log
find $BACKUPDIR -mtime +$ddays -name "MBFEDB_BT_*.Z" >> $log
find $BACKUPDIR -mtime +$ddays -name "MBFEDB_BT_*.Z" | xargs -i /bin/rm {}
ftp -i -n 10.8.7.100 <
user coredb coredb
bin
put $zfile
bye
!
res=$?
echo "--> 6 backup success (res=$res)" >> $log
echo "--------------------------------------------------------\n\n" >> $log
exit 0
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22661144/viewspace-1430690/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 備份指令碼指令碼
- rman備份和增量備份指令碼指令碼
- ORACLE備份指令碼Oracle指令碼
- mysqldump 備份指令碼MySql指令碼
- rman 備份指令碼指令碼
- mysqldump備份指令碼MySql指令碼
- innobackupex備份指令碼指令碼
- SQLServer備份指令碼SQLServer指令碼
- SQL 備份指令碼SQL指令碼
- Mongodb 備份指令碼MongoDB指令碼
- rman備份指令碼指令碼
- oracle 備份指令碼Oracle指令碼
- mysql備份指令碼MySql指令碼
- windows mysqldump備份指令碼WindowsMySql指令碼
- 自動備份指令碼指令碼
- mysql innobackupex備份指令碼MySql指令碼
- rman 全備份指令碼指令碼
- rman增量備份指令碼指令碼
- windows rman備份指令碼Windows指令碼
- Windows 快速備份指令碼Windows指令碼
- ORACLE日常備份指令碼Oracle指令碼
- RMAN常用備份指令碼指令碼
- Oracle 集中備份指令碼Oracle指令碼
- 生成熱備份指令碼指令碼
- 生成冷備份指令碼指令碼
- 備份指令碼--紀錄指令碼
- oracle RMAN備份指令碼Oracle指令碼
- EXP的備份指令碼指令碼
- oracle_備份指令碼Oracle指令碼
- MySQL備份之分庫分表備份指令碼MySql指令碼
- Oracle冷備份(一致備份)指令碼Oracle指令碼
- 兩套mysql備份指令碼MySql指令碼
- 資料庫備份指令碼資料庫指令碼
- mysql按表備份指令碼MySql指令碼
- [Oracle] rman備份指令碼(2)Oracle指令碼
- expdp 邏輯備份指令碼指令碼
- 檢視備份資訊指令碼指令碼
- oracle for linux 備份指令碼OracleLinux指令碼