标签:.gz exec root nbsp sha usr .sh else lse
#!/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 /usr/local/mysql/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
0 4 * * * /opt/backup.sh >> /opt/backup.log 2>&1
chmod 755 backup.sh
./backup.sh
标签:.gz exec root nbsp sha usr .sh else lse
原文地址:https://www.cnblogs.com/zhaojq1/p/10711844.html