备份
我们使用MySQL原生备份命令,编写shell
脚本命令,当然我们也可以使用python
#!/bin/sh
cd /bak/bakmysql
echo "You are in bakmysql directory"
mv bakmysql* /bak/bakmysqlold
echo "Old databases are moved to bakmysqlold folder"
Now=$(date +"%d-%m-%Y")
File=bakmysql-win-$Now.sql
mysqldump -uroot -p'root' win > $File
echo "Your database backup successfully completed"
SevenDays=$(date -d -7day +"%d-%m-%Y")
if [ -f /bak/bakmysqlold/bakmysql-win-$SevenDays.sql ]
then
rm -rf /bak/bakmysqlold/bakmysql-win-$SevenDays.sql
echo "You have delete 7days ago bak file "
else
echo "7days ago bak file not exist "
fi