#!/bin/bash#? date:2017-10#? version:0.1#? description:db_user= "root" myisam_db= "MySQL" db_passwd= "123456" host= "localhost" backup_dir= "/opt/backup/mysql/sql "Log_file="/opt/backup/mysql/sql/mysql_backup.log "keep_days=30mysql=" $ (which?mysql) "mysqldump=" $ (Which?) mysqldump) "db_list=$ (mysql?-h$host?-u$db_user?-p$db_passwd?-e? ') Show?databases ' |egrep?-v? ' Database|information_schema|mysql|performance_schema ') export? Path= "/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin" dbs=$ (echo?$ Db_list|tr? ' \ n '? '? ') myisam_dump_file= $backup _dir/myisam-$ (date?+ "%y-%m-%d")-full.sql.gzinnodb_dump_file= $backup _dir/innodb-$ (date? + "%y-%m-%d")-full.sql.gzold_file_myisam= $backup _dir/myisam-$ (date?--date= "$keep _days?days?ago"? + "%y-%m-%d")- full.sql.gzold_file_innodb= $backup _dir/innodb-$ (date?--date= "$keep _days?days?ago"? + "%y-%m-%d")-full.sql.gzinfo ()? {?? If? [?$?? -eq?0?]; Then???? Echo? " Full?backup?$1?successfully. "? >> $log _file?? else???? Echo? " Full?backup?$1?failed. "? >> $log _filE???? Echo? " full?backup?$1?failed. "| Mail?-s? " Full?backup?$2?failed "[email protected]?? Fi}delete_old_files ()? {if? [-f?$1?]; Then?? Rm?-rf?$1?? Echo? " Delete?old?file? ' $ '? Successfully '?>> $log _filefi}start_time=$ (date?+ "%f?%h:%m:%s") [?!? -d? $backup _dir?]? &&?mkdir?-p? $backup _dir[?!? F. $log _file?]? &&?touch? $log _fileecho? " Starting?mysql?full?backup?database?at? $start _time "?>> $log _file$mysqldump?-h$host?-u$db_user?-p$db_ Passwd?-f?-b?-x?--events?--triggers?--routines?--master-data=2 $myisam _db|gzip?> $myisam _dump_file?2>> $log _file?info? $myisam _dump_file? " MyISAM "$mysqldump?-h$host?-u$db_user?-p$db_passwd?-f?-b?--single-transaction?--events?--triggers?--routines?-- master-data=2 $dbs |gzip?> $innodb _dump_file?2>> $log _file?info? $innodb _dump_file? " INNOBD "stop_time=$ (date?+"%f?%h:%m:%s ") echo?" End?mysql?full?backup?database?at? $stop _time "?>> $log _filedelete_old_files? $old _file_myisamdelete_old_ Files $old _file_innodbecho? "?"? >> $log _file
Mysqldump Full backup shell script