1. 程式人生 > >自動備份數據庫文件腳本

自動備份數據庫文件腳本

lin mysql- 腳本 time host reat service nbsp cron

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

自動備份數據庫文件腳本