The whole idea of scripting
1. Define the required variables
2. Use the For loop to back up the library that needs to be backed up and name the library-the date of the day. SQL naming and logging of related logs
3. Set up a directory for the date of the day of the backup, move to the backup SQL file to that directory
4. Compress package the directory to save space and remove the directory after package success
5. Backup directory only back up seven days of the database, the eighth day delete the first day of the backup, the directory will only exist for seven consecutive days of backup files
6. Find the. log log file in the backup directory for more than seven days of deletion
#!/bin/bashmysql_bin=/usr/local/tdoa/mysql/bin/mysqldumpuser=rootpasswd=myoa888mysql_back=/mysql-backdate=$ ( DATE +%F) for i in td_oa td_oa_archive bus crscelldo $mysql _bin -u$user -p$passwd $i >> $mysql _back/$ I-$date .sql if [ $? -eq 0 ];then echo -e "$date $i back success\n" >> $ mysql_back/back.log else echo -e "$date $i back failure\n" >> $MYSQl_back/error.log fidonecd $mysql _back if [ ! -d $date ];then mkdir $mysql _back/$date mv $mysql _back/*.sql $mysql _back/$date else mv $mysql _back/*.sql $mysql _back/$ date fitar -czf mysql-$date .tar.gz $daterm -r $mysql _back/$datefind $mysql _back -name \*.gz -type f -mtime +6 -exec rm {} \;find $mysql _back -name \*.log -type f -atime +6 -exec rm&nbsP {} \;
This article is from the "Hanging Sword" blog, please be sure to keep this source http://sublime.blog.51cto.com/8856101/1535990