In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the handout of the MySQL local database backup script, hoping to supplement and update some knowledge, if you have any other questions you need to know, you can continue to follow my updated article in the industry information.
This script is used for scheduled backups of local databases and scheduling tasks based on crontab
#! / bin/bash # Shell Command For Backup MySQL Database Everyday Automatically By Crontab USER=root # Database login user name PASSWORD= "1qaz2wsx" # Database login password DATABASE= "mysql" # Library to be backed up HOSTNAME= "192.168.18.5" # backup host IPWEBMASTER=test@qq.comBACKUP_DIR=/data/mysql _ back/ # backup file storage path LOGFILE=/data/data_backup.log # journal file path DATE= `date'+% Y% m% dhorse% H% M`` # date format (as file name) DUMPFILE=$DATE.sql # backup file name ARCHIVE=$DATE.sql.tgz # compressed file name OPTIONS= "- h$HOSTNAME-u$USER-p$PASSWORD $DATABASE" # mysqldump-help # determine whether the backup file storage directory exists Otherwise, create the directory if [!-d $BACKUP_DIR] Then mkdir-p "$BACKUP_DIR" fi# before starting backup Write the backup header to the diary file echo "> > $LOGFILEecho" > > $LOGFILEecho "- > > $LOGFILEecho" BACKUP DATE: "$(date +"% y-%m-%d% H:%M:%S ") > > $LOGFILEecho"-"> > $LOGFILE# to the backup directory cd $BACKUP_DIR# use the mysqldump command to back up the development database And use the formatted timestamp to name the backup file mysqldump $OPTIONS > $DUMPFILE# to determine whether the database backup is successful or not if [[$? = = 0]] Then # create an archive of backup files tar czvf $ARCHIVE $DUMPFILE > > $LOGFILE 2 > & 1 # enter the message of successful backup to the diary file echo "[$ARCHIVE] Backup Successful!" > > $LOGFILE # delete the original backup file and simply keep the compressed package of the database backup file rm-f $DUMPFILEelse echo "Database Backup Fail!" > > $LOGFILEfi# outputs a reminder that the backup process is over
Echo "Backup Process Done"
Read the above handouts on the MySQL local database backup script, hoping to give you some help in practical application. Due to the limited space in this article, it is inevitable that there will be deficiencies and need to be supplemented. If you need more professional answers, you can contact us on the official website for 24-hour pre-sales and after-sales to help you answer questions at any time.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.