In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly tells you about using shell programming to achieve mysql backup under linux. You can check the relevant professional terms on the Internet or find some related books to supplement them. We will not dabble here, so let's go straight to the topic. I hope this article of using shell programming to achieve mysql backup under linux can bring you some practical help.
1Parse the common variables of the shell:
$0 name of the current script
N the nth parameter of the current script
$* all parameters of the current script (excluding the program itself)
$# number of parameters in the current script (excluding the program itself)
$? The status after the completion of the execution of a command or program. Generally, a return of 0 indicates success.
$UID ID of the current user
The directory where $PWD is currently located
-ne is not equal to
-eq equals
2. Automatic backup of mysql scripts
①, the command to back up DB
Mysqldump-h227.0.0.1-uroot-p123456 du > du_ `date +% y% m% d`.sql
②, backup mechanism
③, the target and library of backup
④, how many days old data are deleted regularly?
#! / bin/bash#auto backup mysql datebases.#by 2017#define DB info PATHSQL_CMD= "/ usr/bin/mysqldump" SQL_HOST= "127.0.0.1" SQL_USR= "root" SQL_PWD= "123456" SQL_DB= "du" SQL_DIR= "/ data/backup/ `date +% y% m% d`" # determine whether it is a root user if [$UID-ne 0]; then echo "only use root to exec." Exit fi# determines whether the path exists, and creates an if [!-d $SQL_DIR] if it does not exist; then mkdir-paired SQL _ DIRfi# backup database $SQL_CMD-h$SQL_HOST-u$SQL_USR-p$SQL_PWD $SQL_DB > $SQL_DIR/$SQL_DB.sql# determines whether the backup is successful, and successfully prints out the path if [$?-eq 0]; then echo "Backup mysql already successful." Echo "Backup path:$SQL_DIR" else echo "Backup mysql failed." fi# deletes the backup file cd $SQL_DIR/../; find. -mtime + 30-exec rm-rf {}\; echo "Done" # add script to crontab task plan grep "mysql" / var/spool/cron/root > > / dev/nullif [$?-ne 0]; then echo "0 * / bin/bash / root/shell/mysql.sh > / tmp/mysql.log 2 > & 1" > > / var/spool/cron/root / etc/init.d/crond restartfi
Linux using shell programming to achieve mysql backup will first tell you here, for other related issues you want to know can continue to pay attention to our industry information. Our section will capture some industry news and professional knowledge to share with you every day.
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.