mysql-linux定时备份mysql数据库
sh脚本
#!/bin/bash db_user="数据库用户名" db_passwd="数据库密码" db_name="数据库名" cd /进入备份文件目录/bakmysql echo "you are in bakmysql directory now" mv 备份文件名* /新的备份目录/bakmysqlold echo "Old databases are moved to bakmysqlold folder" backup_dir="/备份文件目录/bakmysql" time=$(date +"%Y-%m-%d") mysqldump -u$db_user -p$db_passwd $db_name > "$backup_dir/$db_name"-"$time.sql" echo "your database backup successfully completed" SevenDays=$(date -d -30day +"%Y-%m-%d") if [ -f /备份文件目录/bakmysqlold/$db_name-$SevenDays.sql ] then rm -rf /备份文件目录/bakmysqlold/$db_name-$SevenDays.sql echo "you have delete 30days ago bak sql file " else echo "30days ago bak sql file not exist " echo "bash complete" fi
知识只有共享才能传播,才能推崇出新的知识,才能学到更多,这里写的每一篇文字/博客,基本都是从网上查询了一下资料然后记录下来,也有些是原滋原味搬了过来,也有时加了一些自己的想法