mysql自动备份命令.txt
1.第一步、
2.每天自动备份MySQL数据库的脚本,并且自动发送到你指定的邮箱面,这样vpser再也不会为丢失数据烦恼啦。sh内容
mkdir /bak,mkdir /bak/bakmysql,mkdir /bak/bakmysqlold 。在/bak/bakmysql文件夹下建一个shell脚本:touch /bak/bakmysql/backup.sh 。
#!/bin/sh
cd /bak/bakmysql
echo "You are in bakmysql directory"
mv wdy* /bak/bakmysqlold
echo "Old databases are moved to bakmysqlold folder"
db_user="root"
db_passwd="##"
db_name="##"
# the directory for story your backup file.you shall change this dir
backup_dir="/bak/bakmysql"
# date format for backup file (dd-mm-yyyy)
time="$(date +"%Y%m%d%H%M%S")"
cd /usr/local/mysql/
sudo ./mysqldump -u$db_user -p$db_passwd $db_name > "$backup_dir/$db_name"_"$time.sql"
tar zcf /bak/bakmysql/wdy.sql.tar.gz /bak/bakmysql/
echo “主题:数据库备份” | mutt -a /bak/bakmysql/wdy.sql.tar.gz -s “内容:数据库备份” feng1990liu@163.com
3.定时:crontab -e
4.重启crond /etc/rc.d/init.d/crond restart
1.第一步、
2.每天自动备份MySQL数据库的脚本,并且自动发送到你指定的邮箱面,这样vpser再也不会为丢失数据烦恼啦。sh内容
mkdir /bak,mkdir /bak/bakmysql,mkdir /bak/bakmysqlold 。在/bak/bakmysql文件夹下建一个shell脚本:touch /bak/bakmysql/backup.sh 。
#!/bin/sh
cd /bak/bakmysql
echo "You are in bakmysql directory"
mv wdy* /bak/bakmysqlold
echo "Old databases are moved to bakmysqlold folder"
db_user="root"
db_passwd="##"
db_name="##"
# the directory for story your backup file.you shall change this dir
backup_dir="/bak/bakmysql"
# date format for backup file (dd-mm-yyyy)
time="$(date +"%Y%m%d%H%M%S")"
cd /usr/local/mysql/
sudo ./mysqldump -u$db_user -p$db_passwd $db_name > "$backup_dir/$db_name"_"$time.sql"
tar zcf /bak/bakmysql/wdy.sql.tar.gz /bak/bakmysql/
echo “主题:数据库备份” | mutt -a /bak/bakmysql/wdy.sql.tar.gz -s “内容:数据库备份” feng1990liu@163.com
3.定时:crontab -e
4.重启crond /etc/rc.d/init.d/crond restart