达梦数据库备份脚本

一、设置备份工具的系统环境变量

vi /etc/profile
DM_HOME=/data/dmdbms/dmdbms
export PATH=$PATH:$DM_HOME/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$DM_HOME/bin
source /etc/profile

二、创建数据库备份用户

创建用户
CREATE USER "BAK" IDENTIFIED BY "123456";
授权
GRANT "PUBLIC","RESOURCE","VTI","DBA","SOI","SVI" TO "BAK"

三、备份脚本

vim /data/dm_bak.sh
#!/bin/bash
# 定义host、账号、密码,需要自定义
dm_host='10.100.30.5'
dm_user='BAK'
dm_passwd='123456'
dm_port='5236'

# 定义备份目录、备份库、文件格式,需要自定义
bak_dir='/data/dm_bak'
date_day=`date +%F`

# 数组,需要备份的库都写在里面,需要自定义
bak_db_name=('PAAS_CS' 'PAAS_DVS' )
# 开始备份
for db_name in ${bak_db_name[@]};do
    [[ -z $db_name ]] && exit 1
    mkdir -p $bak_dir/$db_name/$db_name.$date_day
    dexp USERID=$dm_user/$dm_passwd@$dm_host:$dm_port FILE=$db_name.dmp LOG=$db_name.log OWNER=$db_name DIRECTORY=$bak_dir/$db_name/$db_name.$date_day >> /dev/null
    if [[ $? -eq 0 ]];then
        cd $bak_dir/$db_name && tar zcf $db_name.$date_day.tar  $db_name.$date_day
        if [[ $? -eq 0 ]];then
            rm -rf $bak_dir/$db_name/$db_name.$date_day
            find $bak_dir/$db_name/ -name "*.tar" -ctime +15 -exec rm -f {} \;
		#	scp -r $bak_dir/$db_name/$db_name.$date_day.tar 172.16.80.16:/data/dm-dexp/$bak_dir/$db_name/
        fi
    fi
done

四、定时执行

0 1 * * * source /etc/profile && sh /data/dm_bak.sh
posted @ 2024-06-07 14:13  村尚chun叔  阅读(443)  评论(0编辑  收藏  举报