nas的linux备份套件,linux 备份数据库到 NAS

先把nas开启NFS服务

再把NAS的共享盘挂载到Linux里,

sudo mkdir mybackup

sudo mount -o username=***,password=*** //192.168.0.***/database /mnt/mybackup

shell注意权限

#!/bin/bash

# Database info

DB_USER="root"

DB_PASS="root"

#DB_HOST="192.168.0.101"

DB_HOSTS=("192.168.0.11,3306,baiduled"

"192.168.0.101,3306,baiduled"

"192.168.0.12,3306,baiduled"

"192.168.0.15,3306,baiduled"

"192.168.0.102,3306,baiduled"

"192.168.0.203,13103,baiduled"

"192.168.0.104,3306,baiduled"

"192.168.0.107,3306,baiduled"

"192.168.0.10,3306,ledconfig"

"192.168.0.14,3306,baiduled"

"192.168.0.10,3306,googleled"

)

#DB_PORT="3306"

#DB_NAME="baiduled"

# Others vars

BIN_DIR="/usr/bin" #the mysql bin path

BCK_DIR="/mnt/mybackup" #the backup file directory

DATE=`date +%F`

DB_BACKUP_NAME=$DB_NAME_DATA

# TODO

# /usr/bin/mysqldump --opt -ubatsing -pbatsingpw -hlocalhost timepusher > /mnt/mysqlBackup/db_`date +%F`.sql

for var in ${DB_HOSTS[@]};

do

IFS=','

arr=($var)

#echo ${arr[0]}_${arr[1]}_${arr[2]}

#$BIN_DIR/mysqldump --databases $DB_NAME --tables controller -h$DB_HOST -P$DB_PORT -u$DB_USER -p$DB_PASS | gzip > $BCK_DIR/db_$DATE.dump.gz

$BIN_DIR/mysqldump --databases ${arr[2]} --ignore-table=${arr[2]}.datacollection --ignore-table=${arr[2]}.alarm -h${arr[0]} -P${arr[1]} -u$DB_USER -p$DB_PASS | gzip > $BCK_DIR/db_${arr[0]}_${arr[2]}_$DATE.dump.gz

done

#还原数据库

#用mysql-front导入前一天的 *.sql 文件即可恢复数据

你可能感兴趣的:(nas的linux备份套件)