麒麟系统 Gbase8s , 每天早上1点定时备份demo数据库

麒麟系统 Gbase8s , 每天早上1点定时备份demo数据库

方案1:使用crontab

增加文件

/home/gbasedbt/load_fragments.cron

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
0 1 * * *  /home/gbasedbt/load_fragments.sh >> ./load_fragments.log 2>&1

/home/gbasedbt/cbmdb_backup.sh 记得增加执行权限

#!/bin/bash

date;

[ ! -d "/opt/bak" ] && mkdir -p "/opt/bak" && chmod 777 "/opt/bak" || chmod 777 "/opt/bak"

BACKUP_DIR=/opt/bak/$(date "+%Y%m%d%H%M")

[ ! -d $BACKUP_DIR ] && mkdir -p $BACKUP_DIR && chmod 777 $BACKUP_DIR || chmod 777 $BACKUP_DIR

source /home/gbasedbt/.bash_profile;
if onstat -  | grep 'On-Line'  > /dev/null
then

dbexport demo -ss -o $BACKUP_DIR -l

date;

else
echo "备机或未启动"

fi

/home/gbasedbt/.bash_profile

# Source /root/.bashrc if user has one
[ -f ~/.bashrc ] && . ~/.bashrc
source /home/gbasedbt/profile.gbaseserver

/home/gbasedbt/profile.gbaseserver

export GBASEDBTSERVER=gbaseserver
export GBASEDBTDIR=/home/gbasedbt/hdr35
export GBASEDBTSQLHOSTS=/home/gbasedbt/hdr35/etc/sqlhosts.gbaseserver
export ONCONFIG=onconfig.gbaseserver
export PATH=/home/gbasedbt/hdr35/bin:$PATH
export DB_LOCALE=zh_CN.utf8
export CLIENT_LOCALE=zh_CN.utf8
export GL_USEGLU=1

export ODBCINI=${GBASEDBTDIR}/etc/odbc.ini
export LD_LIBRARY_PATH=${GBASEDBTDIR}/lib:${GBASEDBTDIR}/lib/cli:${GBASEDBTDIR}/lib/esql:$LD_LIBRARY_PATH 


/etc/systemd/system/rc-local.service

[Unit]
Description=/etc/rc.d/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.d/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.d/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

/etc/rc.d/rc.local 须具有可执行权限

#!/bin/bash

touch /var/lock/subsys/local
su - gbasedbt -c 'crontab  load_fragments.cron'

方案2 直接使用 systemd 的定时任务

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值