Security Code: Indifferent Childe
A few days ago, the leader arranged a task to write a script back up some of the tables in a MySQL database, and to upload the backed up files to an FTP server, so the following script
#!/bin/bash#filename:mysqldump.sh#function:backup a part of tables from mysql databases then package it and put it to ftp server#author: forgotten love#date:2016-12-15basedir=/root/backupcurdate=$ (/bin/date +%y%m%d) FTPIP= 192.168.7.500fullname=${basedir}/mysqldump_${curdate}.tar.gzdestdir=/ops/backuplocal_filename=$ (/bin/basename $FULLNAME) destfile=${destdir}/$local _filenameftpput () {ftp -i -n <<eofopen $ ftpipuser username passwordbinpassivecd $DESTDIRput $FULLNAME $DESTFILEquitEOF} #put $FULLNAME $DESTFILE #backup all tablesecho "################################## backuping tables##################################### "for tablename in bond institution;domysqldump -uroot -pgamma23$ ss_product $tablename > ${basedir}/ ${tablename}_$curdatedone#backup a part of tablesmysqldump -uroot -pgamma23$ ss_product qb_bond_deal -w "Create_ Time " > ${basedir}/qb_bond_deal_$curdateecho " ################################# #packaging file####################################### "cd $basedir/bin/tar zcf mysqldump_${curdate}. tar.gz [biq]*_$curdateecho "################################# #putting file##################### #################### "if [ -f mysqldump_${curdate}.tar.gz ];thenftpput &>/dev/ nullfiecho "################################## finished ########################### ##############"
This script is intended for the Redhat family of operating systems, with the need to change the appropriate FTP server address, FTP user name, FTP user password, and the appropriate backup directory and files to upload to the FTP directory for medium information. In addition, you need to ensure that the script FTP, mysqldump and other commands in the system already exist in order to execute this script, otherwise it will be an error.
This article from "Indifferent Bo" blog, reproduced please contact the author!
Back up some MySQL tables and upload them to the specified FTP server directory