Mysqldump Full backup shell script

Source: Internet
Author: User

#!/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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.