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

Example Analysis of mysqldump usage of mysql backup script

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail the example analysis on the use of mysqldump in mysql backup scripts. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

The details are as follows

#! / bin/bash# complete mode, usually executed on slave computer Suitable for small and medium-sized mysql databases # backup 15 days before deletion # author: fafu_li# time: 2015.08.10source / etc/profile # load system environment variable source ~ / .bash_profile # load user environment variable set-o nounset # exit when referencing uninitialized variables # set-o errexit # exit user= "root" password= "123456" host= "localhost" port= "3306" # databases to be backed up Array db= ("test") # is locked during backup. # MyISAM is a lock table-- lock-all-tables,#InnoDB is a lock row-- single-transaction "mysql_path=" / usr/local/mysql "backup_path=" ${mysql_path} / backup "date=$ (date +% Y-%m-%d_%H-%M-%S) day=15backup_log=" ${mysql_path} / backup.log "# create a backup directory if [!-e $backup_path] Then mkdir-p $backup_pathfi# delete previous backup find $backup_path-type f-mtime + $day-exec rm-rf {}\ > / dev/null 2 > & 1echo "start backing up database: ${db [*]}" # backup and compress backup_sql () {dbname=$1 backup_name= "${dbname} _ ${date} .sql" #-R backup stored procedure, function, trigger mysqldump-h $host-P $port-u $user-p$password $lock-- default-character-set=utf8-- flush-logs-R $dbname > $backup_path/$backup_name if [$? = 0] Then cd $backup_path tar zcpvf $backup_name.tar.gz $backup_name size=$ (du $backup_name.tar.gz-sh | awk'{print $1}') rm-rf $backup_name echo "$date backup $dbname ($size) successful" else cd $backup_path rm-rf $backup_name echo "$date backup $dbname failed" fi} # Loop backup length=$ {# db [@]} for ((I = 0; I)

< $length; i++ )); do backup_sql ${db[$i]} >

> $backup_log 2 > & 1doneecho "backup ends, the results view $backup_log" du $backup_path/*$date*-sh | awk'{print "file:" $2 ", size:" $1} 'this article ends here. I hope the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good. Please share it for more people to see.

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