Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3134094
  • 博文数量: 144
  • 博客积分: 10056
  • 博客等级: 上将
  • 技术积分: 2603
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-13 14:20
个人简介

互通有无,共同提高。

文章分类

全部博文(144)

分类: LINUX

2012-02-10 11:08:47

OpenWorks自带的owbackup和owbackup-all脚本
 
Landmark 2003
 
用法:
 
owbackup
 
参数:
project name: 要备份的工区名
backup file name: 备份文件名
 
用法:
 
owbackup-all []
 
参数:
directory name: 保存备份文件的目录
extension: 备份文件扩展名; 可选项; 若不指定参数将使用.bkup为扩展名
 
实例:
 
$OWHOME/bin/owbackup MAHSPROJECT /data1/owprj_bak/mhs_back/MHS.dmp
$OWHOME/bin/owbackup MAHSPROJECT /data1/owprj_bak/mhs_back/MHS-'date +"%d-%b-%y"'
 
$OWHOME/bin/owbackup-all /data1/owprj_bak/mhs_back
$OWHOME/bin/owbackup-all /data1/owprj_bak/mhs_back MHS.bkup
 

Landmark R5000.8
 
owbackup
 
不备份外部文件
 
$OWHOME/bin/owbackup MHS /disk01/backups/MHS.dmp
$OWHOME/bin/owbackup MHS /disk01/backups/MHS-'date +"%d-%b-%y"'
 
备份外部文件和地震工区文件
 
$OWHOME/bin/owbackup MHS /disk01/backups/MHS.bak -SID OWPEPRIS -ExternalFile /disk01/backups/MHS_extern.bak
 
$OWHOME/bin/owbackup MHS /disk01/backups/MHS-'date +"%d-%b-%y"' -SID OWPEPRIS -ExternalFile  /disk01/backups/MHS_extern.zip -SeismicFile /disk01/backups/MHS_seismic.zip

owbackup-all
 
不备份外部文件
 
$OWHOME/bin/owbackup-all /disk01/backups
$OWHOME/bin/owbackup-all /disk01/backups MHS.bkup

备份外部文件和地震工区文件
 
$OWHOME/bin/owbackup-all /disk01/backups -OEXT .bck -ExtFileDir /disk01/backups
$OWHOME/bin/owbackup-all /disk01/backups -OEXT MHS.bkup -ExtFileDir /disk01/backups

 
 (问题已解决)
 
 
下面是井工区自动备份脚本(虽已测试通过,但仍可根据实际需要使脚本更加简洁、适用):

下面是工区自动备份脚本,可根据具体情况选用。脚本(一):只备份井工区;脚本(二):备份井工区(oracle)、OpenWorks外部数据(OW_PROJ_DATA)、地震工区目录(备份地震工区时排除.3dv、.bri、.cgm、.inp等文件。:脚本(二)由网友 龙踞中原 提供,此处只做少许修改)。

脚本(一)

1、auto_back.sh(此文件放在$OWHOME/bin下)

#!/bin/bash
#
# owr5000 user automatic backup scipts 
#
#   arg1 =
#
export OM_PROJECT_DIR="/disk01/"
export OM_BACK_DIR="$OM_PROJECT_DIR/backups"
export BACKUP_LOG="$OM_PROJECT_DIR/automatic_backup.log"
##############prepareded  data
dat1=`date -R  | cut -d" " -f4`
dat2=`date -R  | cut -d" " -f2`
dat3=`date -R  | cut -d" " -f3`
DATE=$dat1-$dat3-$dat2
######################auto backup user database
function auto_back()
{
mkdir $OM_BACK_DIR/$DATE
$OWHOME/bin/owbackup-all $OM_BACK_DIR/$DATE > $OM_BACK_DIR/$DATE/$DATE.log
export LOG=`cat $OM_BACK_DIR/$DATE/$DATE.log|grep Check|cut  -d" " -f2`
cp $LOG $OM_BACK_DIR/$DATE
}
if [ -d "$OM_BACK_DIR/$DATE" ]
 then
  echo "directory $OM_BACK_DIR/$DATE File exists"
 else
auto_back &
fi

##############check LOG file
if [ ! -f "$BACKUP_LOG" ]
   then
  echo "$BACKUP_LOG is not found! will be touch a new file" >&2
  touch $BACKUP_LOG
 fi
chmod  777 $BACKUP_LOG
###############deleted old backup database file

function check_backup_file_date()
{
ls $OM_BACK_DIR/* 1>/dev/null  2>> $BACKUP_LOG
  stat=$?
  if [ $stat -ne 0 ]
  then
    echo "datebase backup file not in $OM_BACK_DIR dirictory , stat=$stat" >> $B
ACKUP_LOG
  exit
  else
ls $OM_BACK_DIR/ |
while read file_name
  do
 old_data_day=`echo  $file_name |cut -d"-" -f3 `
 old_data_year=`echo  $file_name |cut -d"-" -f1 `
  if [ $old_data_year -eq $dat1 ]
  then
  let  number_data=$dat2-$old_data_day
   if [ $number_data -gt 2 ]
    then
    rm -rf $OM_BACK_DIR/$file_name
    echo "dirictory  $file_name was deleted on $DATE " >> $BACKUP_LOG
   fi
   fi
  done
fi
}
check_backup_file_date
 

2、auto_cron(此文件放在$OWHOME/bin下)
 
su - owr5000 -c /pb/OpenWorks/bin/auto_back.sh
 

3、/etc/cron.d下的 owr5000
 
[root@wx02 cron.d]# pwd
/etc/cron.d
 
[root@wx02 cron.d]# ll
total 36
-rw-r--r-- 1 root root 170 Jan 23  2008 mailman
-rw-r--r-- 1 root root 139 Aug 30  2006 mrtg
-rw------- 1 root root  69 Mar 27 08:46 owr5000
-rw------- 1 root root 366 Sep 15  2008 sa-update
-rw-r--r-- 1 root root 192 Sep 16  2008 sysstat

00 2 * * * root  /pb/OpenWorks/bin/auto_cron 1>/dev/null 2>/dev/null
 
 
以下是执行结果示例(每日凌晨2点开始备份oracle内部数据,保留最近的3个备份目录)。待进一步完善的是:同时备份井工区内部和外部数据以及地震或解释工区数据(排除.3dv, .3dh, .bri, .cmp, .cgm, .inp等格式文件):
 
wx02{owr5000}% pwd
/disk01/backups
 
wx02{owr5000}% ll
total 12
drwxrwxr-x 2 owr5000 lmk 4096 Mar 29 02:00 2012-Mar-29/
drwxrwxr-x 2 owr5000 lmk 4096 Mar 30 02:00 2012-Mar-30/
drwxrwxr-x 2 owr5000 lmk 4096 Mar 31 02:00 2012-Mar-31/

wx02{owr5000}% cd 2012-Mar-31/
/disk01/backups/2012-Mar-31
 
wx02{owr5000}% ll
total 96736
-rw-rw-r-- 1 owr5000 lmk      566 Mar 31 02:00 2012-Mar-31.log
-rw-rw-r-- 1 owr5000 lmk 78838605 Mar 31 02:00 MHS.bck
-rw-rw-r-- 1 owr5000 lmk    87063 Mar 31 02:00 owbackup-all_MHS.err
-rw-rw-r-- 1 owr5000 lmk    83645 Mar 31 02:00 owbackup-all_R5KLEC.err
-rw-rw-r-- 1 owr5000 lmk 19922640 Mar 31 02:00 R5KLEC.bck
 
 
脚本(二)
 
1、在一个空间足够大的盘上创建备份文件保存目录,如:/dell061disk2/ZJ_BAK,在其下面建OPENWORKS_PROJ_BACKUP和SEISWORKS_PROJ_BACKUP目录。
 
2、编辑脚本文件(此处例子为backup_yd3d_12),如:

#!/bin/csh -f
setenv OWHOME  /disk1/OW
setenv ORACLE_SID  ow2003
setenv ORACLE_HOME  /disk1/oracle8/OraHome1
setenv OWSYSSID ow2003
echo ----------------------------------------------------------------------------------------------------------- >>& /dell061disk2/ZJ_BAK/project_backup.log
echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >>& /dell061disk2/ZJ_BAK/project_backup.log
echo ----------------------------------------------------------------------------------------------------------- >>& /dell061disk2/ZJ_BAK/project_backup.log
set now = `date +%Y-%m-%d_%H_%M`
echo Begin to backup oracle database at `date +%Y-%m-%d_%H:%M` >>& /dell061disk2/ZJ_BAK/project_backup.log
/disk1/OW/bin/owbackup ZHENJING /dell061disk2/ZJ_BAK/OPENWORKS_PROJ_BACKUP/ZHENJING_Oracle_Backup_$now.dmp >>& /dell061disk2/ZJ_BAK/project_backup.log
echo End of oracle database backup at `date +%Y-%m-%d_%H:%M`, file name is: >>& /dell061disk2/ZJ_BAK/project_backup.log
ls -l -h /dell061disk2/ZJ_BAK/OPENWORKS_PROJ_BACKUP/ZHENJING_Oracle_Backup_$now.dmp >>& /dell061disk2/ZJ_BAK/project_backup.log
echo --------------------------------------------------------- >>& /dell061disk2/ZJ_BAK/project_backup.log
set now = `date +%Y-%m-%d_%H_%M`
echo Begin to backup external project files at $now >>& /dell061disk2/ZJ_BAK/project_backup.log
cd /pa/lamprj/OW_PROJ_DATA
(tar -jcv -f  /dell061disk2/ZJ_BAK/OPENWORKS_PROJ_BACKUP/ZHENJING_External_Backup_$now.tar.bz2 ZHENJING > /dev/null) >>& /dell061disk2/ZJ_BAK/project_backup.log
echo End of external project files backup at `date +%Y-%m-%d_%H:%M`, file name is: >>& /dell061disk2/ZJ_BAK/project_backup.log
ls -l -h /dell061disk2/ZJ_BAK/OPENWORKS_PROJ_BACKUP/ZHENJING_External_Backup_$now.tar.bz2 >>& /dell061disk2/ZJ_BAK/project_backup.log
echo --------------------------------------------------------- >>& /dell061disk2/ZJ_BAK/project_backup.log
set now = `date +%Y-%m-%d_%H_%M`
echo Begin to backup seismic project at `date +%Y-%m-%d_%H:%M` >>& /dell061disk2/ZJ_BAK/project_backup.log
cd /pa/lamprj
(tar -jcv -f /dell061disk2/ZJ_BAK/SEISWORKS_PROJ_BACKUP/yd3d_12_Seismic_Project_Backup_$now.tar.bz2 yd3d_12 --exclude '*.3dv' --exclude '*.3dh' --exclude '*.bri' --exclude '*.cgm' --exclude '*.inp' > /dev/null) >>& /dell061disk2/ZJ_BAK/project_backup.log
echo End of seismic project backup at `date +%Y-%m-%d_%H:%M`, file name is: >>& /dell061disk2/ZJ_BAK/project_backup.log
ls -l -h /dell061disk2/ZJ_BAK/SEISWORKS_PROJ_BACKUP/yd3d_12_Seismic_Project_Backup_$now.tar.bz2 >>& /dell061disk2/ZJ_BAK/project_backup.log
echo --------------------------------------------------------- >>& /dell061disk2/ZJ_BAK/project_backup.log
echo Deleting old backup files created more than 10 days ago ...... >>& /dell061disk2/ZJ_BAK/project_backup.log
echo Now will delete following SEISMIC PROJECT backup files ...... >>& /dell061disk2/ZJ_BAK/project_backup.log
find /dell061disk2/ZJ_BAK/SEISWORKS_PROJ_BACKUP/ -name "yd3d_12_Seismic_Project_Backup_*.tar.bz2" -atime +10 -print >>& /dell061disk2/ZJ_BAK/project_backup.log
find /dell061disk2/ZJ_BAK/SEISWORKS_PROJ_BACKUP/ -name "yd3d_12_Seismic_Project_Backup_*.tar.bz2" -atime +10 -exec rm -f {} \;
echo Now will delete following OPENWORKS PROJECT backup files ...... >>& /dell061disk2/ZJ_BAK/project_backup.log
find /dell061disk2/ZJ_BAK/OPENWORKS_PROJ_BACKUP/ -name "ZHENJING_*_Backup_*" -atime +10 -print >>& /dell061disk2/ZJ_BAK/project_backup.log
find /dell061disk2/ZJ_BAK/OPENWORKS_PROJ_BACKUP/ -name "ZHENJING_*_Backup_*" -atime +10 -exec rm -f {} \;
echo Successful deleted old backup files created more than 10 days ago at `date +%Y-%m-%d_%H:%M`

3、在兰马用户下(用户ow2003)用 crontab -e 编辑cron job,如:
 
00 2 * * * /dell061disk2/wang_bak/backup_yd3d_12 1>/dev/null 2>/dev/null

4、以上工作完成后,进入root用户,用命令 service crond restart 重启crond服务。为稳妥起见,也可把备份脚本改为点文件,或进入root用户,用 chattr +i filename修改属性,使一般用户无法修改脚本文件。
 
注:备份脚本如果通过FTP从Linux传到Windows编辑后再传回Linux系统后,要用dos2unix filename 转换一下格式,并放开执行权限,这样cronjob才能执行。
 
 
以下是执行结果示例(每天备份,删除超过10天未用的文件):
 
dell061{ow2003}% pwd
/dell061disk2/ZJ_BAK/OPENWORKS_PROJ_BACKUP
dell061{ow2003}% ll -h
-rw-r--r--  1 ow2003 dba 106M Dec 16 02:01 ZHENJING_External_Backup_2012-12-16_02_00.tar.bz2
-rw-r--r--  1 ow2003 dba 106M Dec 17 02:01 ZHENJING_External_Backup_2012-12-17_02_00.tar.bz2
-rw-r--r--  1 ow2003 dba 106M Dec 18 02:01 ZHENJING_External_Backup_2012-12-18_02_01.tar.bz2
-rw-r--r--  1 ow2003 dba 960M Dec 16 02:00 ZHENJING_Oracle_Backup_2012-12-16_02_00.dmp
-rw-r--r--  1 ow2003 dba 960M Dec 17 02:00 ZHENJING_Oracle_Backup_2012-12-17_02_00.dmp
-rw-r--r--  1 ow2003 dba 970M Dec 18 02:01 ZHENJING_Oracle_Backup_2012-12-18_02_00.dmp
dell061{ow2003}% cd ..
/dell061disk2/ZJ_BAK
dell061{ow2003}% ls
OPENWORKS_PROJ_BACKUP/  project_backup.log  SEISWORKS_PROJ_BACKUP/
dell061{ow2003}% cd SEISWORKS_PROJ_BACKUP/
/dell061disk2/ZJ_BAK/SEISWORKS_PROJ_BACKUP
dell061{ow2003}% ll -h
total 155G
-rw-r--r--  1 ow2003 dba 19G Dec 16 04:06 yd3d_12_Seismic_Project_Backup_2012-12-16_02_01.tar.bz2
-rw-r--r--  1 ow2003 dba 19G Dec 17 04:06 yd3d_12_Seismic_Project_Backup_2012-12-17_02_01.tar.bz2
-rw-r--r--  1 ow2003 dba 19G Dec 18 04:07 yd3d_12_Seismic_Project_Backup_2012-12-18_02_01.tar.bz2
dell061{ow2003}%
阅读(13659) | 评论(1) | 转发(2) |
给主人留下些什么吧!~~

ltm8172015-08-23 00:01:07

谢谢,学习不少