Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mysql sub-library backup script

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

#! / bin/bash#Author:heyic.m@gmail.com# backup by database You can exclude the specified library # 2016-06-08 create.#2017-02-21 add expire_days.#2017-02-27 redifine backupPath's name style.# backup user and password mysql_user= "root" mysql_pwd= "pass" mysql_host= "localhost" cmd_mysql= "/ data/apps/mysql/bin/mysql" cmd_mysqldump= "/ data/apps/mysql/bin/mysqldump" # backup directory # backuppath= "/ data/backup/mysql/ `date +% F` /" backup_basedir= "/ Data/backup/mysql "day= `date +% F` # backup save time backuppath=" ${backup_basedir} / ${day} "expire_days=30if [!-d $backuppath] Then mkdir $backuppath-pfibk_time= `date +% y% m% d% H% M% S` # excluding databases that are not backed up, multiple libraries use'| 'separate exclude_db= "mysql | test | information_schema | performance_schema" # backup function if [- z $mysql_pwd]; then if [- z $exclude_db]; then backup_db= `$ cmd_mysql-u$mysql_user-h$mysql_host-e "show databases | | grep-vi database`else backup_db= `$cmd_mysql-u$mysql_user-h$mysql_host-e "show databases;" | grep-vi database | grep-Ev $exclude_ db`fielse if [- z $exclude_db]; then backup_db= `$ cmd_mysql-u$mysql_user-p$mysql_pwd-h$mysql_host-e "show databases | | grep-vi database`else backup_db= `$cmd_mysql-u$mysql_user-p$mysql_pwd-h$mysql_host-e "show databases;" | grep-vi database | grep-Ev $exclude_ db` fififor db in $backup_db;do if [- z $mysql_pwd] Then echo "`date` Is backuping $db Please wait... "$cmd_mysqldump-u$mysql_user-h$mysql_host\-single-transaction\-hex-blob\-events\ -routines\-- triggers\-- master-data=2\-- set-gtid-purged=off\-- databases\ $db | gzip-9 > $backuppath/$db.$bk_time.sql.gz else echo "`date` Is backuping $db Please wait... "$cmd_mysqldump-u$mysql_user-p$mysql_pwd-h$mysql_host\-- single-transaction\ -hex-blob\-events\-routines\ -- triggers\-- master-data=2\ -- set-gtid-purged=off\-- databases\ $db | gzip-9 > $backuppath/$db.$bk_time.sql.gz fidoneecho "`date` The backup is completed." # clear expired backup # get backup directory path # intercept length (res_len) = total length ( Total_len)-12 (/ 2017-02-21 /) # ${backuppath:0:$res_len} # total_len=$ {# backuppath} # res_len=$ [$total_len-12] # clean_path=$ {backuppath:0:$res_len} clean_path=$ {backup_basedir} # echo $clean_path# clear echo "start to remove backupfiles of more than $expire_days days." find $clean_path-mtime + $expire_days | xargs rm-rfvecho "done."

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report