Jenkins calls the shell to perform database upgrades and backups

Source: Internet
Author: User
Tags svn svn update

# # #this is deploysql.sh###

#!/bin/bash
Lang= "en_US. UTF-8 "
Date= ' date + '%y%m%d_%h%m%s '
User=root
Password=yourpassword
cd/root/sqltest/
SVN up
If [$? = 0];then
get_env= ' cat/root/sqltest/upgrade.sql |grep ^ #ENV =|sed ' s/#ENV =//g;s/.$//'
Get_host= ' cat/root/sqltest/upgrade.sql |grep ^ #HOST =|sed ' s/#HOST =//g;s/.$//'
Host=${get_host}
If [-N "${get_env"}] && [-N "${get_host}"];then
Echo-e "Getting ${get_env} Ip:${get_host} The table that needs to be backed up ... \ n"
Backup_tables= ' cat/root/sqltest/upgrade.sql |grep ^ #backup_tables =|sed ' s/#backup_tables =//g;s/.$//'
Old_ifs= "$IFS"
Ifs= ","
tables= ($backup _tables)
ifs= "$OLD _ifs"
If [-N "$tables"];then
ECHO-E "The tables you need to back up are: ${tables[*]}\n"
For table in ${tables[@]}
Do
Echo-e "mysqldump-uroot-pdbpasswd ${table%.*} ${table#*.} > ${table%.*}_${table#*.} _${date}.sql\n "
Done
If [$?-eq 0]
Then
ECHO-E "Backup succeeded! \ n "
ECHO-E "Performing upgrade sql...\n"
Mysql-u$user-p$password-h $host <<eof
Source/root/sqltest/upgrade.sql;
Eof
Else
ECHO-E "Backup failed! \ n "
Fi
Else
ECHO-E "WARNING: You did not enter any tables that need to be backed up!" but the upgrade SQL still executes ... \ n "
ECHO-E "Performing upgrade sql...\n"
Mysql-u$user-p$password-h $host <<eof
Source/root/sqltest/upgrade.sql;
Eof
Fi
Else
Echo-e "ENV or HOST not found!\n"
Fi
Else
ECHO-E "SVN update failed!\n"
Fi


#this is testenv.sql#

############################### #声明主机 (Operation maintenance) ##############################################

#ENV = quasi-production environment
#HOST =192.168.1.1.

############################### #END ###################################################




################################ #声明需要备份的表, it is recommended to make a backup of the table that has the operation upgraded, can be empty, that is, do not back up the direct upgrade (development maintenance) ################################## ####

#请在下一行 "backup_tables=" after entering the table to be backed up, format: db.table multiple with "," delimited

#backup_tables =mysql.user,mysql.host

################################# #END ##################################################





############################### #提供升级操作SQL (development and maintenance) ############################################
Use MySQL;
Show tables;
############################### #END #####################################################

Jenkins calls the shell to perform database upgrades and backups

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.