自动备份数据库文件脚本

vim usr/bin/zdbf.sh

#!/bin/sh

# Database info
DB_USER="root"
DB_PASS="password"
DB_HOST="ip"

DB_USER1="root"
DB_PASS1="password"
DB_HOST1="ip2"


# Database array
DB_NAME=("ag_file" "ag_sd" "ag_storage" "customer_service" "scdata")
# Others vars
BIN_DIR="/usr/local/mysql/bin" #the mysql bin path
BCK_DIR="/home/mysql-backups" #the backup file directory
DATE=`date +%F`
# create file


if [ ! -d "$BCK_DIR/$DATE" ]; then
echo "chuangjianwenjianji"
mkdir $BCK_DIR/$DATE
else
echo "yicunzai"
fi


#mkdir $BCK_DIR/$DATE
# TODO
# /usr/bin/mysqldump --opt -ubatsing -pbatsingpw -hlocalhost timepusher > /mnt/mysqlBackup/db_`date +%F`.sql
$BIN_DIR/mysqldump -u$DB_USER -p$DB_PASS -h$DB_HOST scdata> $BCK_DIR/$DATE/scdata.sql
$BIN_DIR/mysqldump -u$DB_USER1 -p$DB_PASS1 -h$DB_HOST1 ag_file> $BCK_DIR/$DATE/ag_file.sql
$BIN_DIR/mysqldump -u$DB_USER1 -p$DB_PASS1 -h$DB_HOST1 ag_sd> $BCK_DIR/$DATE/ag_sd.sql
$BIN_DIR/mysqldump -u$DB_USER1 -p$DB_PASS1 -h$DB_HOST1 ag_storage> $BCK_DIR/$DATE/ag_storage.sql
$BIN_DIR/mysqldump -u$DB_USER1 -p$DB_PASS1 -h$DB_HOST1 customer_service> $BCK_DIR/$DATE/customer_service.sql

 

加入Linux定时执行

crontab -e

54 14 * * * /usr/bin/zdbf.sh

 

转载于:https://www.cnblogs.com/cw828/p/10626871.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值