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

Bash script sharing for backing up MySQL database

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

Share

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

This article mainly explains the "backup MySQL database Bash script sharing", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "backup MySQL database Bash script sharing" bar!

#! / bin/bashNOW= `date + "% Ymuri% m" `; BACKUPDIR= "location/of/your/backup/dir/$NOW"; # Server Setup # * MySQL login user name * # MUSER= "user"; # * MySQL login PASSWORD name * # MPASS= "pass"; # * MySQL login HOST name * # MHOST= "your--ip"; MPORT= "your-mysql-port"; # DO NOT BACKUP these databasesIGNOREDB= "information_schemamysqltest" # * MySQL binaries * # MYSQL= `which mysql`; MYSQLDUMP= `which mysqldump`; GZIP= `which gzip` # assuming that / nas is mounted via / etc/fstabif [!-d $BACKUPDIR]; then mkdir-p $BACKUPDIRelse: fi# get all database listingDBS= "$(mysql-u $MUSER-p$MPASS-h $MHOST-P $MPORT-Bse show databases)" # SET DATE AND TIME FOR THE FILENOW= `date + "d%dh%Hm%Ms%S" `; # day-hour-minute-sec format# start to dump database one by onefor db in $DBSdo DUMP= "yes"; if ["$IGNOREDB"! = ""] Then for i in $IGNOREDB # Store all value of $IGNOREDB ON i do if ["$db" = "$I"]; then # If result of $DBS (db) is equal to $IGNOREDB (I) then DUMP= "NO"; # SET value of DUMP to "no" # echo "$i database is being ignored!"; fi done fi if ["$DUMP" = "yes"]; then # If value of DUMP is "yes" then backup database FILE= "$BACKUPDIR/$NOW-$db.gz"; echo "BACKING UP $db" MYSQLDUMP-- add-drop-database-- opt-- lock-all-tables-u $MUSER-p$MPASS-h $MHOST-P $MPORT $db | gzip > $FILE fidone The best part is that you only need to specify a handful of parameters to make the script work. This includes BACKUPDIR (the destination for storing backups), MUSER (MySQL user), MPASS (MySQL user password), MHOST (the IP address of the MySQL server, e.g. Localhost), and MPORT (the port the MySQL database is running on, default is 3306). Thank you for reading, the above is the content of "Bash script sharing for backing up MySQL database". After the study of this article, I believe you have a deeper understanding of the problem of Bash script sharing for backing up MySQL database, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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