mysql本地备份脚本
#!/bin/bash
DB_HOST="127.0.0.1"
DB_NAME=("jira" "postfix")
DB_USER="root"
DB_PASSWORD="password"
DAYS=7
DIR="/opt/db"
CURRENT=$(date -d now +"%Y%m%d")
for db in ${DB_NAME[@]};
do
cd $DIR
/usr/bin/mysqldump -h $DB_HOST -u $DB_USER --password=$DB_PASSWORD $db > $db.$CURRENT.sql
/usr/bin/tar cvfz $db.$CURRENT.tar.gz $db.$CURRENT.sql && /usr/bin/rm -rf $db.$CURRENT.sql
cd ~
/usr/bin/find $DIR -name *.gz -type f -mtime +$DAYS |xargs rm -rf
done
mysql远程备份脚本
#!/bin/bash
DAYS=7
DIR="/opt/db"
HOST=$("192.168.10.214" "192.168.10.215")
CURRENT=$(date -d now +"%Y%m%d")
cd $DIR
for host in ${HOST[@]};
do
[ ! -d $host ] && mkdir $host
/usr/bin/scp -p $host:$DIR/*.$CURRENT.tar.gz $host/
/usr/bin/find $host -name *.gz -type f -mtime +$DAYS |xargs rm -rf
done
达梦数据库远程备份脚本
#!/bin/bash
DAYS=7
DIR="/opt/db"
HOST=$("192.168.10.242 KINGDEE" "192.168.10.244 SEEYON")
CURRENT=$(date -d now +"%Y_%m_%d")
cd $DIR
for data in ${HOST[@]};
do
host=$(echo $data |awk -F " " "{print $1}")
preffix=$(echo $data |awk -F " " "{print $2}")
[ ! -d $host ] && mkdir $host
/usr/bin/scp -p -r dmdba@$host:/data/dmdbms/data/$preffix/bak/*$CURRENT* $host/
/usr/bin/find $host -type d -mtime +$DAYS |xargs rm -rf
done