{"id":1693,"date":"2022-10-02T23:45:46","date_gmt":"2022-10-02T15:45:46","guid":{"rendered":"http:\/\/www.tra56.com\/?p=1693"},"modified":"2022-10-02T23:45:46","modified_gmt":"2022-10-02T15:45:46","slug":"1693","status":"publish","type":"post","link":"https:\/\/www.tra56.com\/1693.html","title":{"rendered":"Linux\u670d\u52a1\u5668\u4e0a\u5907\u4efdmysql\u6570\u636e\u5e93\uff08\u8be6\u7ec6\u6559\u7a0b\uff09"},"content":{"rendered":"

\u9996\u5148\u4f7f\u7528  mysql -V  \u67e5\u770b\u670d\u52a1\u5668\u662f\u5426\u5b89\u88c5\u4e86mysql,\u6ca1\u6709\u4e00\u5b9a\u8981\u5b89\u88c5\uff0c\u56e0\u4e3a<\/span>\u811a\u672c\u7f16\u5199\u4e2d\u9700\u8981mysql\u547d\u4ee4\u8fdb\u884c\u5907\u4efd\u3002<\/span><\/p>\n

\u5907\u4efd\u811a\u672c\uff1a<\/span><\/span><\/p>\n

#!\/bin\/bash\r\n#\u8bbe\u7f6emysql\u7684\u767b\u5f55\u7528\u6237\u540d\u548c\u5bc6\u7801\r\n mysql_user="\u7528\u6237\u540d"\r\n mysql_password="\u5bc6\u7801"\r\n mysql_host="hostname"\r\n mysql_port="3306"\r\n mysql_charset="utf8"\r\n mysql_database="\u6570\u636e\u5e93\u540d"\r\n# \u5907\u4efd\u6587\u4ef6\u5b58\u653e\u5730\u5740(\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u586b\u5199)\r\nbackup_location=\/data1\/mysql\/data\/\r\n# \u662f\u5426\u5220\u9664\u8fc7\u671f\u6570\u636e\r\nexpire_backup_delete="ON"\r\nexpire_days=7\r\nbackup_time=`date +%Y%m%d%H%M`\r\nbackup_dir=$backup_location\r\nwelcome_msg="Welcome to use MySQL backup tools!   -- by ennenergy"\r\n# \u5224\u65admysql\u5b9e\u4f8b\u662f\u5426\u6b63\u5e38\u8fd0\u884c\r\nmysql_ps=`ps -ef |grep mysql |wc -l`\r\nmysql_listen=`netstat -an |grep LISTEN |grep $mysql_port|wc -l`\r\nif [ [$mysql_ps == 0] -o [$mysql_listen == 0] ]; then\r\necho "ERROR:MySQL is not running! backup stop!"\r\nexit\r\nelse\r\necho $welcome_msg\r\nfi\r\n\r\n#\u5907\u4efd\u538b\u7f29\u6587\u4ef6.gz\r\n#mysqldump -h$mysql_host -u$mysql_user -p$mysql_password -B $mysql_database | gzip > $backup_dir\/$mysql_database-$backup_time.sql.gz\r\n\r\n\u5907\u4efdsql\u6587\u4ef6\r\n\r\nmysqldump -h$mysql_host -P$mysql_port -u$mysql_user -p$mysql_password -B $mysql_database> $backup_dir\/$mysql_database-$backup_time.sql\r\nif [ $flag == "0" ];then\r\necho "database $mysql_database success backup to $backup_dir\/$mysql_database-$backup_time.sql.gz"\r\nelse\r\necho "database $mysql_database backup fail!"\r\nfi\r\n# \u5220\u9664\u8fc7\u671f\u6570\u636e\r\nif [ "$expire_backup_delete" == "ON" -a  "$backup_location" != "" ];then\r\n`find $backup_location\/ -type f -mtime +$expire_days | xargs rm -rf`\r\necho "Expired backup data delete complete!"\r\nfi<\/pre>\n

\u7b2c\u4e8c\u6b65\uff1a\u6dfb\u52a0\u5b9a\u65f6\u4efb\u52a1<\/p>\n

<\/p>\n

\u6267\u884c\u547d\u4ee4\uff1acrontab -e<\/p>\n

<\/p>\n

i  \u8fdb\u884c\u7f16\u5199\uff0c<\/p>\n

<\/p>\n

#\u6bcf\u5206\u949f\u6267\u884c\u5907\u4efd<\/p>\n

*\/1 * * * * cd \/home\/mysql\/;sh mysql_backup.sh >> log.txt 2>&1<\/p>\n

#\u6bcf\u592912:50\u4ee5\u53ca23:50\u6267\u884c\u5907\u4efd<\/p>\n

50 12,23 * * * cd \/home\/mysql\/;sh mysql_backup.sh >> log.txt 2>&1<\/p>\n

\u6dfb\u52a0\u540eesc\uff0c\u8f93\u5165:wq\u4fdd\u5b58\u9000\u51fa\uff0c\u6b64\u65f6\u5b9a\u65f6\u4efb\u52a1\u5c31\u4f1a\u6267\u884c\u4e86\u3002<\/p>\n

<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"

\u9996\u5148\u4f7f\u7528  mysql -V  \u67e5\u770b\u670d\u52a1\u5668\u662f\u5426\u5b89\u88c5\u4e86mysql,\u6ca1\u6709\u4e00\u5b9a\u8981\u5b89\u88c5\uff0c\u56e0\u4e3a\u811a\u672c\u7f16 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,89],"tags":[],"class_list":["post-1693","post","type-post","status-publish","format-standard","hentry","category-linux","category-mysqlyouhua"],"_links":{"self":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/1693"}],"collection":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/comments?post=1693"}],"version-history":[{"count":1,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/1693\/revisions"}],"predecessor-version":[{"id":1694,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/1693\/revisions\/1694"}],"wp:attachment":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/media?parent=1693"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/categories?post=1693"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/tags?post=1693"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}