数据库全量备份简单脚本

mysql数据库需要做全量备份,我就写了个特别简单的全量备份脚本,也只备份两个数据库,只需要创建两个文件,内容如下:

1、上传至服务器,给予权限755

chmod 755 mybackup.sh

2、mybackup.sh文件内容

#/usr/bin/env bash
BASEDIR="/home"
username=`cat ${BASEDIR}/mybackup.conf | grep "username" | awk -F '=' '{print $2}'`
password=`cat ${BASEDIR}/mybackup.conf | grep "password" | awk -F '=' '{print $2}'`
db_name=new_retail_back
dbname=pro_wallet_back

echo "username and password"
echo ${username}
echo ${password}
echo "begin to backup"
mysqldump -hlocalhost -u${username} -p${password} --databases new_retail | gzip > /home/data/mysql/new_retail_back`date +'%Y-%m-%d %H:%M:%S'`.sql.gz
mysqldump -hlocalhost -u${username} -p${password} --databases pro_wallet | gzip > /home/data/mysql/pro_wallet_back`date +'%Y-%m-%d %H:%M:%S'`.sql.gz
#删除三天之前的备份
find /home/data/mysql -name $db_name"*.sql.gz" -type f -mtime 3 -exec rm -rf {} \; > /dev/null 2>&1
find /home/data/mysql -name $dbname"*.sql.gz" -type f -mtime 3 -exec rm -rf {} \; > /dev/null 2>&1
#删除一分钟之前的备份
#find $backup_dir -name $db_name"*.sql.gz" -type f -mmin +1 -exec rm -rf {} \; > /dev/null 2>&1


3、mybackup.conf文件内容

username=root
password=123456
backupnode=full

你可能感兴趣的:(数据库全量备份简单脚本)