美文网首页
Oracle+MySQL+InfluxDB简易备份脚本

Oracle+MySQL+InfluxDB简易备份脚本

作者: bluexiii | 来源:发表于2018-11-05 14:19 被阅读35次

Oracle

#!/bin/bash
# ##################################################################
# Oracle定时Expdp脚本
# SQL> CREATE DIRECTORY backup as '/home/oracle/dump';
# SQL> grant read,write on directory backup to SYSTEM; 
# crontab -e
# 30 00 * * *    . $HOME/.bash_profile; cd /home/oracle/sh; ./bak_exp.sh
# ##################################################################

# 环境变量
USERNAME=system
PASSWORD=yourpass
SID=orcl
SCHEMA=yoursid
DUMP_DIR=/home/oracle/dump
DIRECTORY=BAKDIR
PARALLEL=1
DMP_FILE=BAK_`date +%Y%m%d%H%M%S`.dmp
LOG_FILE=BAK_`date +%Y%m%d%H%M%S`.log

# expdp导出
expdp $USERNAME@$SID/$PASSWORD schemas=$SCHEMA DIRECTORY=$DIRECTORY DUMPFILE=$DMP_FILE logfile=$LOG_FILE parallel=$PARALLEL;

# 压缩dmp
cd $DUMP_DIR
gzip $DMP_FILE

# 删除旧的dmp
find $backup_dir -name "*.dmp" -mtime +1 -exec rm {} \;

MySQL

#!/bin/bash
# ##################################################################
# MySQL定时备份
# crontab -e
# 30 01 * * *    . $HOME/.bash_profile; cd /home/youruser/mysqlbak/sh; ./bak_mysql.sh
# ##################################################################

# 环境变量
USERNAME=root
PASSWORD=yourpass
DATABASE=yourdb
BASE_DIR=/home/youruser/mysqlbak
DUMP_FILE=$BASE_DIR/BAK_`date +%Y%m%d%H%M%S`.sql

# 备份
cd $BASE_DIR
mysqldump -u$USERNAME -p$PASSWORD $DATABASE > $DUMP_FILE

# 压缩dmp
gzip $DUMP_FILE

# 删除旧的dmp
find $BASE_DIR -name "*.sql.gz" -mtime +7 -exec rm {} \;

InfluxDB

#!/bin/bash
# ##################################################################
# InfluxDB定时备份
# crontab -e
# 30 00 * * *    . $HOME/.bash_profile; cd /home/youruser/influxbak/sh; ./bak_influx.sh
# ##################################################################

# 环境变量
DATABASE=yourdb
BASE_DIR=/home/youruser/influxbak
DUMP_DIR=$BASE_DIR/BAK_`date +%Y%m%d%H%M%S`

# 备份
mkdir $DUMP_DIR
influxd backup -portable -database $DATABASE $DUMP_DIR

# 删除旧的dmp
cd $BASE_DIR
find $BASE_DIR -type d -name "BAK_*" -mtime +7 -exec rm -rf {} \;

相关文章

网友评论

      本文标题:Oracle+MySQL+InfluxDB简易备份脚本

      本文链接:https://www.haomeiwen.com/subject/tnrsxqtx.html