1.创建目录:
mkdir /backup #用于存放备份文件
mkdir /oldbackup #用于存放旧的备份文件
2.写脚本:
vim /backup/backup.sh
编写:
mv /backup/backup* /oldbackup
echo "old backup file is moved to /oldbackup"
Now=$(date +%d-%m-%Y--%H:%M:%S)
File=backup-$Now.sql
mysqldump -uroot -predhat databse >$File
echo "Your database backup are successfully completed"
3.制定备份计划:
vim /etc/crontab
编写:
01 01 * * * root /backup/backup.sh #每天01:01开始备份