mysql shell 定时备份

#!/bin/sh
if [ ! -d "/data/backup" ]; then
        mkdir -p /data/backup
fi
db_user="root"
db_passwd="abc"
time="$(date +"%Y%m%d%H%M")"
mysqldump -u$db_user -p$db_passwd --database abc_app > /data/backup/db_abc_app_$time.sql        #备份并压缩文件
mysqldump -u$db_user -p$db_passwd --database abc_cms > /data/backup/db_abc_cms_$time.sql
mysqldump -u$db_user -p$db_passwd --database abc_admin > /data/backup/db_abc_admin_$time.sql
mysqldump -u$db_user -p$db_passwd --database abc_resource > /data/backup/db_abc_resource_$time.sql
find /data/backup/ -name "db_*.sql" -type f -mtime +2 -exec rm {} \; > /dev/null 2>&1  #删除7天前的备份文件
 
 
 
sudo /usr/local/mysql/bin/mysqldump 数据库名 | gzip > /usr/local/mysql/backup/adshare_$time.sql.gz  
 
 
if [ ! -d "/data/backup" ]; then
        echo '111'
else
        echo '222'
fi 
 
crontab
0 4 * * * /opt/backup.sh >> /opt/backup.log 2>&1

source
mysql>use dbtest;
mysql>set names utf8;
mysql>source
/data/backup/back.sql;


    chmod 755 backup.sh ./backup.sh
posted @ 2019-04-15 17:29  zhaojq  阅读(324)  评论(0编辑  收藏  举报