麒麟系统 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 的定时任务
1199

被折叠的 条评论
为什么被折叠?



